ia64/xen-unstable

changeset 6380:522bc50588ed

merge?
author cl349@firebug.cl.cam.ac.uk
date Tue Aug 23 18:27:22 2005 +0000 (2005-08-23)
parents 6783e59e1c45 df11e0709383
children 03370bdbc6f1 cc5f88b719d0
files .hgignore Config.mk Makefile buildconfigs/Rules.mk docs/src/user.tex extras/mini-os/include/time.h extras/mini-os/kernel.c extras/mini-os/time.c linux-2.6-xen-sparse/arch/xen/Kconfig linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32 linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_64 linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_32 linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_64 linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_32 linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_64 linux-2.6-xen-sparse/arch/xen/i386/Kconfig linux-2.6-xen-sparse/arch/xen/i386/kernel/Makefile linux-2.6-xen-sparse/arch/xen/i386/kernel/cpu/common.c linux-2.6-xen-sparse/arch/xen/i386/kernel/head.S linux-2.6-xen-sparse/arch/xen/i386/kernel/i386_ksyms.c linux-2.6-xen-sparse/arch/xen/i386/kernel/ioport.c linux-2.6-xen-sparse/arch/xen/i386/kernel/ldt.c linux-2.6-xen-sparse/arch/xen/i386/kernel/mpparse.c linux-2.6-xen-sparse/arch/xen/i386/kernel/pci-dma.c linux-2.6-xen-sparse/arch/xen/i386/kernel/process.c linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c linux-2.6-xen-sparse/arch/xen/i386/kernel/smp.c linux-2.6-xen-sparse/arch/xen/i386/kernel/smpboot.c linux-2.6-xen-sparse/arch/xen/i386/kernel/time.c linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c linux-2.6-xen-sparse/arch/xen/i386/mm/highmem.c linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c linux-2.6-xen-sparse/arch/xen/i386/mm/init.c linux-2.6-xen-sparse/arch/xen/i386/mm/ioremap.c linux-2.6-xen-sparse/arch/xen/i386/mm/pgtable.c linux-2.6-xen-sparse/arch/xen/i386/pci/Makefile linux-2.6-xen-sparse/arch/xen/kernel/evtchn.c linux-2.6-xen-sparse/arch/xen/kernel/gnttab.c linux-2.6-xen-sparse/arch/xen/kernel/reboot.c linux-2.6-xen-sparse/arch/xen/kernel/skbuff.c linux-2.6-xen-sparse/arch/xen/x86_64/Kconfig linux-2.6-xen-sparse/arch/xen/x86_64/Makefile linux-2.6-xen-sparse/arch/xen/x86_64/ia32/Makefile linux-2.6-xen-sparse/arch/xen/x86_64/kernel/Makefile linux-2.6-xen-sparse/arch/xen/x86_64/kernel/apic.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/e820.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/entry.S linux-2.6-xen-sparse/arch/xen/x86_64/kernel/pci-nommu.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/process.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup64.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/smpboot.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/vsyscall.c linux-2.6-xen-sparse/arch/xen/x86_64/mm/Makefile linux-2.6-xen-sparse/arch/xen/x86_64/mm/fault.c linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c linux-2.6-xen-sparse/arch/xen/x86_64/pci/Makefile linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c linux-2.6-xen-sparse/drivers/xen/blkback/Makefile linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c linux-2.6-xen-sparse/drivers/xen/blkback/common.h linux-2.6-xen-sparse/drivers/xen/blkback/interface.c linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c linux-2.6-xen-sparse/drivers/xen/blkfront/block.h linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c linux-2.6-xen-sparse/drivers/xen/blktap/blktap.h linux-2.6-xen-sparse/drivers/xen/blktap/blktap_controlmsg.c linux-2.6-xen-sparse/drivers/xen/blktap/blktap_userdev.c linux-2.6-xen-sparse/drivers/xen/console/console.c linux-2.6-xen-sparse/drivers/xen/netback/common.h linux-2.6-xen-sparse/drivers/xen/netback/interface.c linux-2.6-xen-sparse/drivers/xen/netback/netback.c linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c linux-2.6-xen-sparse/drivers/xen/usbback/usbback.c linux-2.6-xen-sparse/drivers/xen/usbfront/usbfront.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.h linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c linux-2.6-xen-sparse/include/asm-xen/asm-i386/desc.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/dma-mapping.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/fixmap.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/hypercall.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/io.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/mmu_context.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/pci.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgalloc.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable-2level.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable-3level.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/desc.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/dma-mapping.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/hypercall.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/page.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/pci.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/pgtable.h linux-2.6-xen-sparse/include/asm-xen/balloon.h linux-2.6-xen-sparse/include/asm-xen/gnttab.h linux-2.6-xen-sparse/include/asm-xen/hypervisor.h linux-2.6-xen-sparse/include/asm-xen/xenbus.h linux-2.6-xen-sparse/include/linux/highmem.h linux-2.6-xen-sparse/include/linux/mm.h linux-2.6-xen-sparse/mm/highmem.c linux-2.6-xen-sparse/mm/memory.c tools/Makefile tools/Rules.mk tools/console/daemon/io.c tools/debugger/libxendebug/xendebug.c tools/debugger/libxendebug/xendebug.h tools/debugger/pdb/Domain.ml tools/debugger/pdb/Domain.mli tools/debugger/pdb/Makefile tools/debugger/pdb/PDB.ml tools/debugger/pdb/Process.ml tools/debugger/pdb/Process.mli tools/debugger/pdb/debugger.ml tools/debugger/pdb/linux-2.6-module/debug.c tools/debugger/pdb/linux-2.6-module/module.c tools/debugger/pdb/linux-2.6-module/pdb_debug.h tools/debugger/pdb/linux-2.6-module/pdb_module.h tools/debugger/pdb/linux-2.6-patches/i386_ksyms.patch tools/debugger/pdb/pdb_caml_domain.c tools/debugger/pdb/pdb_caml_process.c tools/debugger/pdb/pdb_caml_xcs.c tools/debugger/pdb/readme tools/examples/Makefile tools/examples/xend-config.sxp tools/examples/xmexample.vmx tools/ioemu/hw/ide.c tools/libxc/Makefile tools/libxc/xc.h tools/libxc/xc_core.c tools/libxc/xc_gnttab.c tools/libxc/xc_linux_build.c tools/libxc/xc_linux_restore.c tools/libxc/xc_linux_save.c tools/libxc/xc_load_elf.c tools/libxc/xc_ptrace.c tools/libxc/xc_vmx_build.c tools/misc/xend tools/python/setup.py tools/python/xen/lowlevel/xu/xu.c tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/XendRoot.py tools/python/xen/xend/image.py tools/python/xen/xend/server/blkif.py tools/python/xen/xend/server/controller.py tools/python/xen/xend/server/event.py tools/python/xen/xend/server/netif.py tools/python/xen/xend/server/relocate.py tools/python/xen/xm/create.py tools/python/xen/xm/main.py tools/security/Makefile tools/security/secpol_tool.c tools/xenstat/Makefile tools/xenstat/libxenstat/COPYING tools/xenstat/libxenstat/Makefile tools/xenstat/libxenstat/bindings/swig/perl/.empty tools/xenstat/libxenstat/bindings/swig/python/.empty tools/xenstat/libxenstat/bindings/swig/xenstat.i tools/xenstat/libxenstat/src/xen-interface.c tools/xenstat/libxenstat/src/xen-interface.h tools/xenstat/libxenstat/src/xenstat.c tools/xenstat/libxenstat/src/xenstat.h tools/xenstat/xentop/Makefile tools/xenstat/xentop/TODO tools/xenstat/xentop/xentop.1 tools/xenstat/xentop/xentop.c tools/xenstore/xenstored.h tools/xenstore/xenstored_core.c tools/xentrace/xentrace.c xen/Rules.mk xen/arch/ia64/grant_table.c xen/arch/ia64/xenmisc.c xen/arch/ia64/xentime.c xen/arch/x86/domain.c xen/arch/x86/domain_build.c xen/arch/x86/io_apic.c xen/arch/x86/mm.c xen/arch/x86/physdev.c xen/arch/x86/setup.c xen/arch/x86/shadow.c xen/arch/x86/shadow32.c xen/arch/x86/time.c xen/arch/x86/traps.c xen/arch/x86/vmx.c xen/arch/x86/vmx_io.c xen/arch/x86/x86_32/entry.S xen/arch/x86/x86_32/traps.c xen/arch/x86/x86_64/entry.S xen/arch/x86/x86_64/traps.c xen/common/domain.c xen/common/event_channel.c xen/common/grant_table.c xen/common/lib.c xen/common/perfc.c xen/common/schedule.c xen/common/trace.c xen/drivers/char/console.c xen/include/asm-x86/e820.h xen/include/asm-x86/mm.h xen/include/asm-x86/page.h xen/include/asm-x86/shadow.h xen/include/asm-x86/uaccess.h xen/include/asm-x86/vmx.h xen/include/asm-x86/vmx_vmcs.h xen/include/asm-x86/x86_32/page-3level.h xen/include/asm-x86/x86_32/uaccess.h xen/include/public/arch-ia64.h xen/include/public/arch-x86_32.h xen/include/public/arch-x86_64.h xen/include/public/dom0_ops.h xen/include/public/grant_table.h xen/include/public/io/blkif.h xen/include/public/io/domain_controller.h xen/include/public/io/netif.h xen/include/public/physdev.h xen/include/public/xen.h xen/include/xen/grant_table.h xen/include/xen/sched.h xen/include/xen/time.h
line diff
     1.1 --- a/.hgignore	Tue Aug 23 18:25:51 2005 +0000
     1.2 +++ b/.hgignore	Tue Aug 23 18:27:22 2005 +0000
     1.3 @@ -147,6 +147,7 @@
     1.4  ^tools/xcs/xcsdump$
     1.5  ^tools/xcutils/xc_restore$
     1.6  ^tools/xcutils/xc_save$
     1.7 +^tools/xenstat/xentop/xentop$
     1.8  ^tools/xenstore/testsuite/tmp/.*$
     1.9  ^tools/xenstore/xen$
    1.10  ^tools/xenstore/xenstored$
     2.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_64	Tue Aug 23 18:25:51 2005 +0000
     2.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_64	Tue Aug 23 18:27:22 2005 +0000
     2.3 @@ -807,7 +807,107 @@ CONFIG_DUMMY_CONSOLE=y
     2.4  #
     2.5  CONFIG_USB_ARCH_HAS_HCD=y
     2.6  CONFIG_USB_ARCH_HAS_OHCI=y
     2.7 -# CONFIG_USB is not set
     2.8 +CONFIG_USB=y
     2.9 +# CONFIG_USB_DEBUG is not set
    2.10 +
    2.11 +#
    2.12 +# Miscellaneous USB options
    2.13 +#
    2.14 +# CONFIG_USB_DEVICEFS is not set
    2.15 +# CONFIG_USB_BANDWIDTH is not set
    2.16 +# CONFIG_USB_DYNAMIC_MINORS is not set
    2.17 +# CONFIG_USB_OTG is not set
    2.18 +
    2.19 +#
    2.20 +# USB Host Controller Drivers
    2.21 +#
    2.22 +# CONFIG_USB_EHCI_HCD is not set
    2.23 +CONFIG_USB_OHCI_HCD=y
    2.24 +# CONFIG_USB_OHCI_BIG_ENDIAN is not set
    2.25 +CONFIG_USB_OHCI_LITTLE_ENDIAN=y
    2.26 +CONFIG_USB_UHCI_HCD=y
    2.27 +# CONFIG_USB_SL811_HCD is not set
    2.28 +
    2.29 +#
    2.30 +# USB Device Class drivers
    2.31 +#
    2.32 +# CONFIG_USB_BLUETOOTH_TTY is not set
    2.33 +# CONFIG_USB_ACM is not set
    2.34 +# CONFIG_USB_PRINTER is not set
    2.35 +
    2.36 +#
    2.37 +# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support' may also be needed; see USB_STORAGE Help for more information
    2.38 +#
    2.39 +# CONFIG_USB_STORAGE is not set
    2.40 +
    2.41 +#
    2.42 +# USB Input Devices
    2.43 +#
    2.44 +CONFIG_USB_HID=y
    2.45 +CONFIG_USB_HIDINPUT=y
    2.46 +# CONFIG_HID_FF is not set
    2.47 +# CONFIG_USB_HIDDEV is not set
    2.48 +# CONFIG_USB_AIPTEK is not set
    2.49 +# CONFIG_USB_WACOM is not set
    2.50 +# CONFIG_USB_KBTAB is not set
    2.51 +# CONFIG_USB_POWERMATE is not set
    2.52 +# CONFIG_USB_MTOUCH is not set
    2.53 +# CONFIG_USB_EGALAX is not set
    2.54 +# CONFIG_USB_XPAD is not set
    2.55 +# CONFIG_USB_ATI_REMOTE is not set
    2.56 +
    2.57 +#
    2.58 +# USB Imaging devices
    2.59 +#
    2.60 +# CONFIG_USB_MDC800 is not set
    2.61 +# CONFIG_USB_MICROTEK is not set
    2.62 +
    2.63 +#
    2.64 +# USB Multimedia devices
    2.65 +#
    2.66 +# CONFIG_USB_DABUSB is not set
    2.67 +
    2.68 +#
    2.69 +# Video4Linux support is needed for USB Multimedia device support
    2.70 +#
    2.71 +
    2.72 +#
    2.73 +# USB Network Adapters
    2.74 +#
    2.75 +# CONFIG_USB_CATC is not set
    2.76 +# CONFIG_USB_KAWETH is not set
    2.77 +# CONFIG_USB_PEGASUS is not set
    2.78 +# CONFIG_USB_RTL8150 is not set
    2.79 +# CONFIG_USB_USBNET is not set
    2.80 +CONFIG_USB_MON=y
    2.81 +
    2.82 +#
    2.83 +# USB port drivers
    2.84 +#
    2.85 +
    2.86 +#
    2.87 +# USB Serial Converter support
    2.88 +#
    2.89 +# CONFIG_USB_SERIAL is not set
    2.90 +
    2.91 +#
    2.92 +# USB Miscellaneous drivers
    2.93 +#
    2.94 +# CONFIG_USB_EMI62 is not set
    2.95 +# CONFIG_USB_EMI26 is not set
    2.96 +# CONFIG_USB_AUERSWALD is not set
    2.97 +# CONFIG_USB_RIO500 is not set
    2.98 +# CONFIG_USB_LEGOTOWER is not set
    2.99 +# CONFIG_USB_LCD is not set
   2.100 +# CONFIG_USB_LED is not set
   2.101 +# CONFIG_USB_CYTHERM is not set
   2.102 +# CONFIG_USB_PHIDGETKIT is not set
   2.103 +# CONFIG_USB_PHIDGETSERVO is not set
   2.104 +# CONFIG_USB_IDMOUSE is not set
   2.105 +
   2.106 +#
   2.107 +# USB ATM/DSL drivers
   2.108 +#
   2.109  
   2.110  #
   2.111  # USB Gadget Support
     3.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/process.c	Tue Aug 23 18:25:51 2005 +0000
     3.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/process.c	Tue Aug 23 18:27:22 2005 +0000
     3.3 @@ -149,12 +149,12 @@ void cpu_idle (void)
     3.4  
     3.5  			if (cpu_is_offline(cpu)) {
     3.6  				local_irq_disable();
     3.7 +#if defined(CONFIG_XEN) && defined(CONFIG_HOTPLUG_CPU)
     3.8  				/* Ack it.  From this point on until
     3.9  				   we get woken up, we're not allowed
    3.10  				   to take any locks.  In particular,
    3.11  				   don't printk. */
    3.12  				__get_cpu_var(cpu_state) = CPU_DEAD;
    3.13 -#if defined(CONFIG_XEN) && defined(CONFIG_HOTPLUG_CPU)
    3.14  				/* Tell hypervisor to take vcpu down. */
    3.15  				HYPERVISOR_vcpu_down(cpu);
    3.16  #endif
     4.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c	Tue Aug 23 18:25:51 2005 +0000
     4.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c	Tue Aug 23 18:27:22 2005 +0000
     4.3 @@ -1575,19 +1575,20 @@ void __init setup_arch(char **cmdline_p)
     4.4  	/* Make sure we have a correctly sized P->M table. */
     4.5  	if (max_pfn != xen_start_info.nr_pages) {
     4.6  		phys_to_machine_mapping = alloc_bootmem_low_pages(
     4.7 -			max_pfn * sizeof(unsigned long));
     4.8 +			max_pfn * sizeof(unsigned int));
     4.9  
    4.10  		if (max_pfn > xen_start_info.nr_pages) {
    4.11  			/* set to INVALID_P2M_ENTRY */
    4.12  			memset(phys_to_machine_mapping, ~0,
    4.13 -				max_pfn * sizeof(unsigned long));
    4.14 +				max_pfn * sizeof(unsigned int));
    4.15  			memcpy(phys_to_machine_mapping,
    4.16 -				(unsigned long *)xen_start_info.mfn_list,
    4.17 -				xen_start_info.nr_pages * sizeof(unsigned long));
    4.18 +				(unsigned int *)xen_start_info.mfn_list,
    4.19 +				xen_start_info.nr_pages * sizeof(unsigned int));
    4.20  		} else {
    4.21  			memcpy(phys_to_machine_mapping,
    4.22 -				(unsigned long *)xen_start_info.mfn_list,
    4.23 -				max_pfn * sizeof(unsigned long));
    4.24 +				(unsigned int *)xen_start_info.mfn_list,
    4.25 +				max_pfn * sizeof(unsigned int));
    4.26 +			/* N.B. below relies on sizeof(int) == sizeof(long). */
    4.27  			if (HYPERVISOR_dom_mem_op(
    4.28  				MEMOP_decrease_reservation,
    4.29  				(unsigned long *)xen_start_info.mfn_list + max_pfn,
    4.30 @@ -1597,11 +1598,11 @@ void __init setup_arch(char **cmdline_p)
    4.31  		free_bootmem(
    4.32  			__pa(xen_start_info.mfn_list), 
    4.33  			PFN_PHYS(PFN_UP(xen_start_info.nr_pages *
    4.34 -			sizeof(unsigned long))));
    4.35 +			sizeof(unsigned int))));
    4.36  	}
    4.37  
    4.38  	pfn_to_mfn_frame_list = alloc_bootmem_low_pages(PAGE_SIZE);
    4.39 -	for ( i=0, j=0; i < max_pfn; i+=(PAGE_SIZE/sizeof(unsigned long)), j++ )
    4.40 +	for ( i=0, j=0; i < max_pfn; i+=(PAGE_SIZE/sizeof(unsigned int)), j++ )
    4.41  	{	
    4.42  	     pfn_to_mfn_frame_list[j] = 
    4.43  		  virt_to_mfn(&phys_to_machine_mapping[i]);
     5.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c	Tue Aug 23 18:25:51 2005 +0000
     5.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c	Tue Aug 23 18:27:22 2005 +0000
     5.3 @@ -281,7 +281,7 @@ fastcall void do_page_fault(struct pt_re
     5.4  	siginfo_t info;
     5.5  
     5.6  	/* Set the "privileged fault" bit to something sane. */
     5.7 -	error_code &= 3;
     5.8 +	error_code &= ~4;
     5.9  	error_code |= (regs->xcs & 2) << 1;
    5.10  	if (regs->eflags & X86_EFLAGS_VM)
    5.11  		error_code |= 4;
     6.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/init.c	Tue Aug 23 18:25:51 2005 +0000
     6.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/init.c	Tue Aug 23 18:27:22 2005 +0000
     6.3 @@ -348,9 +348,12 @@ static void __init pagetable_init (void)
     6.4  {
     6.5  	unsigned long vaddr;
     6.6  	pgd_t *pgd_base = (pgd_t *)xen_start_info.pt_base;
     6.7 +	int i;
     6.8  
     6.9  	swapper_pg_dir = pgd_base;
    6.10  	init_mm.pgd    = pgd_base;
    6.11 +	for (i = 0; i < NR_CPUS; i++)
    6.12 +		per_cpu(cur_pgd, i) = pgd_base;
    6.13  
    6.14  	/* Enable PSE if available */
    6.15  	if (cpu_has_pse) {
     7.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/ioremap.c	Tue Aug 23 18:25:51 2005 +0000
     7.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/ioremap.c	Tue Aug 23 18:27:22 2005 +0000
     7.3 @@ -36,6 +36,8 @@ void iounmap(volatile void __iomem *addr
     7.4  {
     7.5  }
     7.6  
     7.7 +#ifdef __i386__
     7.8 +
     7.9  void __init *bt_ioremap(unsigned long phys_addr, unsigned long size)
    7.10  {
    7.11  	return NULL;
    7.12 @@ -45,6 +47,8 @@ void __init bt_iounmap(void *addr, unsig
    7.13  {
    7.14  }
    7.15  
    7.16 +#endif /* __i386__ */
    7.17 +
    7.18  #else
    7.19  
    7.20  /*
    7.21 @@ -58,7 +62,7 @@ static inline int is_local_lowmem(unsign
    7.22  	extern unsigned long max_low_pfn;
    7.23  	unsigned long mfn = address >> PAGE_SHIFT;
    7.24  	unsigned long pfn = mfn_to_pfn(mfn);
    7.25 -	return ((pfn < max_low_pfn) && (pfn_to_mfn(pfn) == mfn));
    7.26 +	return ((pfn < max_low_pfn) && (phys_to_machine_mapping[pfn] == mfn));
    7.27  }
    7.28  
    7.29  /*
    7.30 @@ -126,10 +130,12 @@ void __iomem * __ioremap(unsigned long p
    7.31  		return NULL;
    7.32  	area->phys_addr = phys_addr;
    7.33  	addr = (void __iomem *) area->addr;
    7.34 +	flags |= _PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED;
    7.35 +#ifdef __x86_64__
    7.36 +	flags |= _PAGE_USER;
    7.37 +#endif
    7.38  	if (direct_remap_area_pages(&init_mm, (unsigned long) addr, phys_addr,
    7.39 -				    size, __pgprot(_PAGE_PRESENT | _PAGE_RW |
    7.40 -						   _PAGE_DIRTY | _PAGE_ACCESSED
    7.41 -						   | flags), domid)) {
    7.42 +				    size, __pgprot(flags), domid)) {
    7.43  		vunmap((void __force *) addr);
    7.44  		return NULL;
    7.45  	}
    7.46 @@ -218,6 +224,8 @@ void iounmap(volatile void __iomem *addr
    7.47  	kfree(p); 
    7.48  }
    7.49  
    7.50 +#ifdef __i386__
    7.51 +
    7.52  void __init *bt_ioremap(unsigned long phys_addr, unsigned long size)
    7.53  {
    7.54  	unsigned long offset, last_addr;
    7.55 @@ -289,6 +297,8 @@ void __init bt_iounmap(void *addr, unsig
    7.56  	}
    7.57  }
    7.58  
    7.59 +#endif /* __i386__ */
    7.60 +
    7.61  #endif /* CONFIG_XEN_PHYSDEV_ACCESS */
    7.62  
    7.63  /* These hacky macros avoid phys->machine translations. */
    7.64 @@ -346,7 +356,7 @@ int direct_remap_area_pages(struct mm_st
    7.65  		 * Fill in the machine address: PTE ptr is done later by
    7.66  		 * __direct_remap_area_pages(). 
    7.67  		 */
    7.68 -		v->val = (machine_addr & PAGE_MASK) | pgprot_val(prot);
    7.69 +		v->val = pte_val_ma(pfn_pte_ma(machine_addr >> PAGE_SHIFT, prot));
    7.70  
    7.71  		machine_addr += PAGE_SIZE;
    7.72  		address += PAGE_SIZE; 
     8.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/gnttab.c	Tue Aug 23 18:25:51 2005 +0000
     8.2 +++ b/linux-2.6-xen-sparse/arch/xen/kernel/gnttab.c	Tue Aug 23 18:27:22 2005 +0000
     8.3 @@ -40,38 +40,82 @@ EXPORT_SYMBOL(gnttab_grant_foreign_trans
     8.4  EXPORT_SYMBOL(gnttab_end_foreign_transfer);
     8.5  EXPORT_SYMBOL(gnttab_alloc_grant_references);
     8.6  EXPORT_SYMBOL(gnttab_free_grant_references);
     8.7 +EXPORT_SYMBOL(gnttab_free_grant_reference);
     8.8  EXPORT_SYMBOL(gnttab_claim_grant_reference);
     8.9  EXPORT_SYMBOL(gnttab_release_grant_reference);
    8.10  EXPORT_SYMBOL(gnttab_grant_foreign_access_ref);
    8.11  EXPORT_SYMBOL(gnttab_grant_foreign_transfer_ref);
    8.12  
    8.13 -static grant_ref_t gnttab_free_list[NR_GRANT_ENTRIES];
    8.14 +#define NR_GRANT_ENTRIES (NR_GRANT_FRAMES * PAGE_SIZE / sizeof(grant_entry_t))
    8.15 +#define GNTTAB_LIST_END (NR_GRANT_ENTRIES + 1)
    8.16 +
    8.17 +static grant_ref_t gnttab_list[NR_GRANT_ENTRIES];
    8.18 +static int gnttab_free_count = NR_GRANT_ENTRIES;
    8.19  static grant_ref_t gnttab_free_head;
    8.20 +static spinlock_t gnttab_list_lock = SPIN_LOCK_UNLOCKED;
    8.21  
    8.22  static grant_entry_t *shared;
    8.23  
    8.24 -/*
    8.25 - * Lock-free grant-entry allocator
    8.26 - */
    8.27 +static struct gnttab_free_callback *gnttab_free_callback_list = NULL;
    8.28  
    8.29 -static inline int
    8.30 -get_free_entry(
    8.31 -    void)
    8.32 +static int
    8.33 +get_free_entries(int count)
    8.34  {
    8.35 -    grant_ref_t fh, nfh = gnttab_free_head;
    8.36 -    do { if ( unlikely((fh = nfh) == NR_GRANT_ENTRIES) ) return -1; }
    8.37 -    while ( unlikely((nfh = cmpxchg(&gnttab_free_head, fh,
    8.38 -                                    gnttab_free_list[fh])) != fh) );
    8.39 -    return fh;
    8.40 +    unsigned long flags;
    8.41 +    int ref;
    8.42 +    grant_ref_t head;
    8.43 +    spin_lock_irqsave(&gnttab_list_lock, flags);
    8.44 +    if (gnttab_free_count < count) {
    8.45 +	spin_unlock_irqrestore(&gnttab_list_lock, flags);
    8.46 +	return -1;
    8.47 +    }
    8.48 +    ref = head = gnttab_free_head;
    8.49 +    gnttab_free_count -= count;
    8.50 +    while (count-- > 1)
    8.51 +	head = gnttab_list[head];
    8.52 +    gnttab_free_head = gnttab_list[head];
    8.53 +    gnttab_list[head] = GNTTAB_LIST_END;
    8.54 +    spin_unlock_irqrestore(&gnttab_list_lock, flags);
    8.55 +    return ref;
    8.56 +}
    8.57 +
    8.58 +#define get_free_entry() get_free_entries(1)
    8.59 +
    8.60 +static void
    8.61 +do_free_callbacks(void)
    8.62 +{
    8.63 +    struct gnttab_free_callback *callback = gnttab_free_callback_list, *next;
    8.64 +    gnttab_free_callback_list = NULL;
    8.65 +    while (callback) {
    8.66 +	next = callback->next;
    8.67 +	if (gnttab_free_count >= callback->count) {
    8.68 +	    callback->next = NULL;
    8.69 +	    callback->fn(callback->arg);
    8.70 +	} else {
    8.71 +	    callback->next = gnttab_free_callback_list;
    8.72 +	    gnttab_free_callback_list = callback;
    8.73 +	}
    8.74 +	callback = next;
    8.75 +    }
    8.76  }
    8.77  
    8.78  static inline void
    8.79 -put_free_entry(
    8.80 -    grant_ref_t ref)
    8.81 +check_free_callbacks(void)
    8.82  {
    8.83 -    grant_ref_t fh, nfh = gnttab_free_head;
    8.84 -    do { gnttab_free_list[ref] = fh = nfh; wmb(); }
    8.85 -    while ( unlikely((nfh = cmpxchg(&gnttab_free_head, fh, ref)) != fh) );
    8.86 +    if (unlikely(gnttab_free_callback_list))
    8.87 +	do_free_callbacks();
    8.88 +}
    8.89 +
    8.90 +static void
    8.91 +put_free_entry(grant_ref_t ref)
    8.92 +{
    8.93 +    unsigned long flags;
    8.94 +    spin_lock_irqsave(&gnttab_list_lock, flags);
    8.95 +    gnttab_list[ref] = gnttab_free_head;
    8.96 +    gnttab_free_head = ref;
    8.97 +    gnttab_free_count++;
    8.98 +    check_free_callbacks();
    8.99 +    spin_unlock_irqrestore(&gnttab_list_lock, flags);
   8.100  }
   8.101  
   8.102  /*
   8.103 @@ -79,8 +123,7 @@ put_free_entry(
   8.104   */
   8.105  
   8.106  int
   8.107 -gnttab_grant_foreign_access(
   8.108 -    domid_t domid, unsigned long frame, int readonly)
   8.109 +gnttab_grant_foreign_access(domid_t domid, unsigned long frame, int readonly)
   8.110  {
   8.111      int ref;
   8.112      
   8.113 @@ -96,8 +139,8 @@ gnttab_grant_foreign_access(
   8.114  }
   8.115  
   8.116  void
   8.117 -gnttab_grant_foreign_access_ref(
   8.118 -    grant_ref_t ref, domid_t domid, unsigned long frame, int readonly)
   8.119 +gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid,
   8.120 +				unsigned long frame, int readonly)
   8.121  {
   8.122      shared[ref].frame = frame;
   8.123      shared[ref].domid = domid;
   8.124 @@ -107,7 +150,7 @@ gnttab_grant_foreign_access_ref(
   8.125  
   8.126  
   8.127  int
   8.128 -gnttab_query_foreign_access( grant_ref_t ref )
   8.129 +gnttab_query_foreign_access(grant_ref_t ref)
   8.130  {
   8.131      u16 nflags;
   8.132  
   8.133 @@ -117,7 +160,7 @@ gnttab_query_foreign_access( grant_ref_t
   8.134  }
   8.135  
   8.136  void
   8.137 -gnttab_end_foreign_access( grant_ref_t ref, int readonly )
   8.138 +gnttab_end_foreign_access(grant_ref_t ref, int readonly)
   8.139  {
   8.140      u16 flags, nflags;
   8.141  
   8.142 @@ -132,8 +175,7 @@ gnttab_end_foreign_access( grant_ref_t r
   8.143  }
   8.144  
   8.145  int
   8.146 -gnttab_grant_foreign_transfer(
   8.147 -    domid_t domid, unsigned long pfn )
   8.148 +gnttab_grant_foreign_transfer(domid_t domid, unsigned long pfn)
   8.149  {
   8.150      int ref;
   8.151  
   8.152 @@ -149,8 +191,8 @@ gnttab_grant_foreign_transfer(
   8.153  }
   8.154  
   8.155  void
   8.156 -gnttab_grant_foreign_transfer_ref(
   8.157 -    grant_ref_t ref, domid_t domid, unsigned long pfn )
   8.158 +gnttab_grant_foreign_transfer_ref(grant_ref_t ref, domid_t domid,
   8.159 +				  unsigned long pfn)
   8.160  {
   8.161      shared[ref].frame = pfn;
   8.162      shared[ref].domid = domid;
   8.163 @@ -159,8 +201,7 @@ gnttab_grant_foreign_transfer_ref(
   8.164  }
   8.165  
   8.166  unsigned long
   8.167 -gnttab_end_foreign_transfer(
   8.168 -    grant_ref_t ref)
   8.169 +gnttab_end_foreign_transfer(grant_ref_t ref)
   8.170  {
   8.171      unsigned long frame = 0;
   8.172      u16           flags;
   8.173 @@ -189,61 +230,81 @@ gnttab_end_foreign_transfer(
   8.174  }
   8.175  
   8.176  void
   8.177 -gnttab_free_grant_references( u16 count, grant_ref_t head )
   8.178 +gnttab_free_grant_reference(grant_ref_t ref)
   8.179  {
   8.180 -    /* TODO: O(N)...? */
   8.181 -    grant_ref_t to_die = 0, next = head;
   8.182 -    int i;
   8.183  
   8.184 -    for ( i = 0; i < count; i++ )
   8.185 -    {
   8.186 -        to_die = next;
   8.187 -        next = gnttab_free_list[next];
   8.188 -        put_free_entry( to_die );
   8.189 +    put_free_entry(ref);
   8.190 +}
   8.191 +
   8.192 +void
   8.193 +gnttab_free_grant_references(grant_ref_t head)
   8.194 +{
   8.195 +    grant_ref_t ref;
   8.196 +    unsigned long flags;
   8.197 +    int count = 1;
   8.198 +    if (head == GNTTAB_LIST_END)
   8.199 +	return;
   8.200 +    spin_lock_irqsave(&gnttab_list_lock, flags);
   8.201 +    ref = head;
   8.202 +    while (gnttab_list[ref] != GNTTAB_LIST_END) {
   8.203 +	ref = gnttab_list[ref];
   8.204 +	count++;
   8.205      }
   8.206 +    gnttab_list[ref] = gnttab_free_head;
   8.207 +    gnttab_free_head = head;
   8.208 +    gnttab_free_count += count;
   8.209 +    check_free_callbacks();
   8.210 +    spin_unlock_irqrestore(&gnttab_list_lock, flags);
   8.211  }
   8.212  
   8.213  int
   8.214 -gnttab_alloc_grant_references( u16 count,
   8.215 -                               grant_ref_t *head,
   8.216 -                               grant_ref_t *terminal )
   8.217 +gnttab_alloc_grant_references(u16 count, grant_ref_t *head)
   8.218  {
   8.219 -    int i;
   8.220 -    grant_ref_t h = gnttab_free_head;
   8.221 +    int h = get_free_entries(count);
   8.222  
   8.223 -    for ( i = 0; i < count; i++ )
   8.224 -        if ( unlikely(get_free_entry() == -1) )
   8.225 -            goto not_enough_refs;
   8.226 +    if (h == -1)
   8.227 +	return -ENOSPC;
   8.228  
   8.229      *head = h;
   8.230 -    *terminal = gnttab_free_head;
   8.231  
   8.232      return 0;
   8.233 -
   8.234 -not_enough_refs:
   8.235 -    gnttab_free_head = h;
   8.236 -    return -ENOSPC;
   8.237  }
   8.238  
   8.239  int
   8.240 -gnttab_claim_grant_reference( grant_ref_t *private_head,
   8.241 -                              grant_ref_t  terminal )
   8.242 +gnttab_claim_grant_reference(grant_ref_t *private_head)
   8.243  {
   8.244 -    grant_ref_t g;
   8.245 -    if ( unlikely((g = *private_head) == terminal) )
   8.246 +    grant_ref_t g = *private_head;
   8.247 +    if (unlikely(g == GNTTAB_LIST_END))
   8.248          return -ENOSPC;
   8.249 -    *private_head = gnttab_free_list[g];
   8.250 +    *private_head = gnttab_list[g];
   8.251      return g;
   8.252  }
   8.253  
   8.254  void
   8.255 -gnttab_release_grant_reference( grant_ref_t *private_head,
   8.256 -                                grant_ref_t  release )
   8.257 +gnttab_release_grant_reference(grant_ref_t *private_head, grant_ref_t  release)
   8.258  {
   8.259 -    gnttab_free_list[release] = *private_head;
   8.260 +    gnttab_list[release] = *private_head;
   8.261      *private_head = release;
   8.262  }
   8.263  
   8.264 +void
   8.265 +gnttab_request_free_callback(struct gnttab_free_callback *callback,
   8.266 +			     void (*fn)(void *), void *arg, u16 count)
   8.267 +{
   8.268 +    unsigned long flags;
   8.269 +    spin_lock_irqsave(&gnttab_list_lock, flags);
   8.270 +    if (callback->next)
   8.271 +	goto out;
   8.272 +    callback->fn = fn;
   8.273 +    callback->arg = arg;
   8.274 +    callback->count = count;
   8.275 +    callback->next = gnttab_free_callback_list;
   8.276 +    gnttab_free_callback_list = callback;
   8.277 +    check_free_callbacks();
   8.278 + out:
   8.279 +    spin_unlock_irqrestore(&gnttab_list_lock, flags);
   8.280 +}
   8.281 +
   8.282  /*
   8.283   * ProcFS operations
   8.284   */
   8.285 @@ -252,8 +313,9 @@ gnttab_release_grant_reference( grant_re
   8.286  
   8.287  static struct proc_dir_entry *grant_pde;
   8.288  
   8.289 -static int grant_ioctl(struct inode *inode, struct file *file,
   8.290 -                       unsigned int cmd, unsigned long data)
   8.291 +static int
   8.292 +grant_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
   8.293 +	    unsigned long data)
   8.294  {
   8.295      int                     ret;
   8.296      privcmd_hypercall_t     hypercall;
   8.297 @@ -291,8 +353,9 @@ static struct file_operations grant_file
   8.298      ioctl:  grant_ioctl,
   8.299  };
   8.300  
   8.301 -static int grant_read(char *page, char **start, off_t off,
   8.302 -                      int count, int *eof, void *data)
   8.303 +static int
   8.304 +grant_read(char *page, char **start, off_t off, int count, int *eof,
   8.305 +	   void *data)
   8.306  {
   8.307      int             len;
   8.308      unsigned int    i;
   8.309 @@ -321,8 +384,9 @@ static int grant_read(char *page, char *
   8.310      return len;
   8.311  }
   8.312  
   8.313 -static int grant_write(struct file *file, const char __user *buffer,
   8.314 -                       unsigned long count, void *data)
   8.315 +static int
   8.316 +grant_write(struct file *file, const char __user *buffer, unsigned long count,
   8.317 +	    void *data)
   8.318  {
   8.319      /* TODO: implement this */
   8.320      return -ENOSYS;
   8.321 @@ -330,7 +394,8 @@ static int grant_write(struct file *file
   8.322  
   8.323  #endif /* CONFIG_PROC_FS */
   8.324  
   8.325 -int gnttab_resume(void)
   8.326 +int
   8.327 +gnttab_resume(void)
   8.328  {
   8.329      gnttab_setup_table_t setup;
   8.330      unsigned long        frames[NR_GRANT_FRAMES];
   8.331 @@ -349,7 +414,8 @@ int gnttab_resume(void)
   8.332      return 0;
   8.333  }
   8.334  
   8.335 -int gnttab_suspend(void)
   8.336 +int
   8.337 +gnttab_suspend(void)
   8.338  {
   8.339      int i;
   8.340  
   8.341 @@ -359,7 +425,8 @@ int gnttab_suspend(void)
   8.342      return 0;
   8.343  }
   8.344  
   8.345 -static int __init gnttab_init(void)
   8.346 +static int __init
   8.347 +gnttab_init(void)
   8.348  {
   8.349      int i;
   8.350  
   8.351 @@ -368,7 +435,7 @@ static int __init gnttab_init(void)
   8.352      shared = (grant_entry_t *)fix_to_virt(FIX_GNTTAB_END);
   8.353  
   8.354      for ( i = 0; i < NR_GRANT_ENTRIES; i++ )
   8.355 -        gnttab_free_list[i] = i + 1;
   8.356 +        gnttab_list[i] = i + 1;
   8.357      
   8.358  #ifdef CONFIG_PROC_FS
   8.359      /*
     9.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/Makefile	Tue Aug 23 18:25:51 2005 +0000
     9.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/Makefile	Tue Aug 23 18:27:22 2005 +0000
     9.3 @@ -44,7 +44,7 @@ obj-$(CONFIG_X86_PM_TIMER)	+= pmtimer.o
     9.4  
     9.5  c-obj-$(CONFIG_MODULES)		+= module.o
     9.6  
     9.7 -#obj-y				+= topology.o
     9.8 +obj-y				+= topology.o
     9.9  c-obj-y				+= intel_cacheinfo.o
    9.10  
    9.11  bootflag-y			+= ../../../i386/kernel/bootflag.o
    10.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c	Tue Aug 23 18:25:51 2005 +0000
    10.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c	Tue Aug 23 18:27:22 2005 +0000
    10.3 @@ -778,21 +778,21 @@ void __init setup_arch(char **cmdline_p)
    10.4  		/* Make sure we have a large enough P->M table. */
    10.5  		if (end_pfn > xen_start_info.nr_pages) {
    10.6  			phys_to_machine_mapping = alloc_bootmem(
    10.7 -				max_pfn * sizeof(unsigned long));
    10.8 +				max_pfn * sizeof(u32));
    10.9  			memset(phys_to_machine_mapping, ~0,
   10.10 -			       max_pfn * sizeof(unsigned long));
   10.11 +			       max_pfn * sizeof(u32));
   10.12  			memcpy(phys_to_machine_mapping,
   10.13 -			       (unsigned long *)xen_start_info.mfn_list,
   10.14 -			       xen_start_info.nr_pages * sizeof(unsigned long));
   10.15 +			       (u32 *)xen_start_info.mfn_list,
   10.16 +			       xen_start_info.nr_pages * sizeof(u32));
   10.17  			free_bootmem(
   10.18  				__pa(xen_start_info.mfn_list), 
   10.19  				PFN_PHYS(PFN_UP(xen_start_info.nr_pages *
   10.20 -						sizeof(unsigned long))));
   10.21 +						sizeof(u32))));
   10.22  		}
   10.23  
   10.24  		pfn_to_mfn_frame_list = alloc_bootmem(PAGE_SIZE);
   10.25  
   10.26 -		for ( i=0, j=0; i < end_pfn; i+=(PAGE_SIZE/sizeof(unsigned long)), j++ )
   10.27 +		for ( i=0, j=0; i < end_pfn; i+=(PAGE_SIZE/sizeof(u32)), j++ )
   10.28  		{	
   10.29  			pfn_to_mfn_frame_list[j] = 
   10.30  				virt_to_mfn(&phys_to_machine_mapping[i]);
    11.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/mm/Makefile	Tue Aug 23 18:25:51 2005 +0000
    11.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/mm/Makefile	Tue Aug 23 18:27:22 2005 +0000
    11.3 @@ -6,10 +6,10 @@ XENARCH	:= $(subst ",,$(CONFIG_XENARCH))
    11.4  
    11.5  CFLAGS	+= -Iarch/$(XENARCH)/mm
    11.6  
    11.7 -obj-y	:= init.o fault.o ioremap.o pageattr.o
    11.8 +obj-y	:= init.o fault.o pageattr.o
    11.9  c-obj-y	:= extable.o
   11.10  
   11.11 -i386-obj-y := hypervisor.o
   11.12 +i386-obj-y := hypervisor.o ioremap.o
   11.13  
   11.14  #obj-y	 := init.o fault.o ioremap.o extable.o pageattr.o
   11.15  #c-obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
    12.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c	Tue Aug 23 18:25:51 2005 +0000
    12.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c	Tue Aug 23 18:27:22 2005 +0000
    12.3 @@ -559,6 +559,11 @@ static void xen_copy_pt(void)
    12.4  
    12.5  void __init xen_init_pt(void)
    12.6  {
    12.7 +	int i;
    12.8 +
    12.9 +	for (i = 0; i < NR_CPUS; i++)
   12.10 +		per_cpu(cur_pgd, i) = init_mm.pgd;
   12.11 +
   12.12  	memcpy((void *)init_level4_pgt, 
   12.13  	       (void *)xen_start_info.pt_base, PAGE_SIZE);
   12.14  
    13.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/mm/ioremap.c	Tue Aug 23 18:25:51 2005 +0000
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,499 +0,0 @@
    13.4 -/*
    13.5 - * arch/x86_64/mm/ioremap.c
    13.6 - *
    13.7 - * Re-map IO memory to kernel address space so that we can access it.
    13.8 - * This is needed for high PCI addresses that aren't mapped in the
    13.9 - * 640k-1MB IO memory area on PC's
   13.10 - *
   13.11 - * (C) Copyright 1995 1996 Linus Torvalds
   13.12 - */
   13.13 -
   13.14 -#include <linux/vmalloc.h>
   13.15 -#include <linux/init.h>
   13.16 -#include <linux/slab.h>
   13.17 -#include <linux/module.h>
   13.18 -#include <asm/io.h>
   13.19 -#include <asm/fixmap.h>
   13.20 -#include <asm/cacheflush.h>
   13.21 -#include <asm/tlbflush.h>
   13.22 -#include <asm/pgtable.h>
   13.23 -#include <asm/pgalloc.h>
   13.24 -
   13.25 -/*
   13.26 - * Reuse arch/xen/i396/mm/ioremap.c. Need to merge later
   13.27 - */
   13.28 -#ifndef CONFIG_XEN_PHYSDEV_ACCESS
   13.29 -
   13.30 -void * __ioremap(unsigned long phys_addr, unsigned long size,
   13.31 -		 unsigned long flags)
   13.32 -{
   13.33 -	return NULL;
   13.34 -}
   13.35 -
   13.36 -void *ioremap_nocache (unsigned long phys_addr, unsigned long size)
   13.37 -{
   13.38 -	return NULL;
   13.39 -}
   13.40 -
   13.41 -void iounmap(volatile void __iomem *addr)
   13.42 -{
   13.43 -}
   13.44 -
   13.45 -void __init *bt_ioremap(unsigned long phys_addr, unsigned long size)
   13.46 -{
   13.47 -	return NULL;
   13.48 -}
   13.49 -
   13.50 -void __init bt_iounmap(void *addr, unsigned long size)
   13.51 -{
   13.52 -}
   13.53 -
   13.54 -#else
   13.55 -
   13.56 -#if defined(__i386__)
   13.57 -/*
   13.58 - * Does @address reside within a non-highmem page that is local to this virtual
   13.59 - * machine (i.e., not an I/O page, nor a memory page belonging to another VM).
   13.60 - * See the comment that accompanies pte_pfn() in pgtable-2level.h to understand
   13.61 - * why this works.
   13.62 - */
   13.63 -static inline int is_local_lowmem(unsigned long address)
   13.64 -{
   13.65 -	extern unsigned long max_low_pfn;
   13.66 -	unsigned long mfn = address >> PAGE_SHIFT;
   13.67 -	unsigned long pfn = mfn_to_pfn(mfn);
   13.68 -	return ((pfn < max_low_pfn) && (pfn_to_mfn(pfn) == mfn));
   13.69 -}
   13.70 -#elif defined(__x86_64__)
   13.71 -/*
   13.72 - * 
   13.73 - */
   13.74 -static inline int is_local_lowmem(unsigned long address)
   13.75 -{
   13.76 -        return 0;
   13.77 -}
   13.78 -#endif
   13.79 -
   13.80 -/*
   13.81 - * Generic mapping function (not visible outside):
   13.82 - */
   13.83 -
   13.84 -/*
   13.85 - * Remap an arbitrary physical address space into the kernel virtual
   13.86 - * address space. Needed when the kernel wants to access high addresses
   13.87 - * directly.
   13.88 - *
   13.89 - * NOTE! We need to allow non-page-aligned mappings too: we will obviously
   13.90 - * have to convert them into an offset in a page-aligned mapping, but the
   13.91 - * caller shouldn't need to know that small detail.
   13.92 - */
   13.93 -void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned long flags)
   13.94 -{
   13.95 -	void __iomem * addr;
   13.96 -	struct vm_struct * area;
   13.97 -	unsigned long offset, last_addr;
   13.98 -	domid_t domid = DOMID_IO;
   13.99 -
  13.100 -	/* Don't allow wraparound or zero size */
  13.101 -	last_addr = phys_addr + size - 1;
  13.102 -	if (!size || last_addr < phys_addr)
  13.103 -		return NULL;
  13.104 -
  13.105 -#ifdef CONFIG_XEN_PRIVILEGED_GUEST
  13.106 -	/*
  13.107 -	 * Don't remap the low PCI/ISA area, it's always mapped..
  13.108 -	 */
  13.109 -	if (phys_addr >= 0x0 && last_addr < 0x100000)
  13.110 -		return isa_bus_to_virt(phys_addr);
  13.111 -#endif
  13.112 -
  13.113 -	/*
  13.114 -	 * Don't allow anybody to remap normal RAM that we're using..
  13.115 -	 */
  13.116 -	if (is_local_lowmem(phys_addr)) {
  13.117 -		char *t_addr, *t_end;
  13.118 - 		struct page *page;
  13.119 -
  13.120 -		t_addr = bus_to_virt(phys_addr);
  13.121 -		t_end = t_addr + (size - 1);
  13.122 -	   
  13.123 -		for(page = virt_to_page(t_addr); page <= virt_to_page(t_end); page++)
  13.124 -			if(!PageReserved(page))
  13.125 -				return NULL;
  13.126 -
  13.127 -		domid = DOMID_LOCAL;
  13.128 -	}
  13.129 -
  13.130 -	/*
  13.131 -	 * Mappings have to be page-aligned
  13.132 -	 */
  13.133 -	offset = phys_addr & ~PAGE_MASK;
  13.134 -	phys_addr &= PAGE_MASK;
  13.135 -	size = PAGE_ALIGN(last_addr+1) - phys_addr;
  13.136 -
  13.137 -	/*
  13.138 -	 * Ok, go for it..
  13.139 -	 */
  13.140 -	area = get_vm_area(size, VM_IOREMAP | (flags << 20));
  13.141 -	if (!area)
  13.142 -		return NULL;
  13.143 -	area->phys_addr = phys_addr;
  13.144 -	addr = (void __iomem *) area->addr;
  13.145 -	if (direct_remap_area_pages(&init_mm, (unsigned long) addr, phys_addr,
  13.146 -				    size, __pgprot(_PAGE_PRESENT | _PAGE_RW |
  13.147 -						   _PAGE_DIRTY | _PAGE_ACCESSED
  13.148 -#if defined(__x86_64__)
  13.149 -                                                   | _PAGE_USER
  13.150 -#endif
  13.151 -						   | flags), domid)) {
  13.152 -		vunmap((void __force *) addr);
  13.153 -		return NULL;
  13.154 -	}
  13.155 -	return (void __iomem *) (offset + (char __iomem *)addr);
  13.156 -}
  13.157 -
  13.158 -
  13.159 -/**
  13.160 - * ioremap_nocache     -   map bus memory into CPU space
  13.161 - * @offset:    bus address of the memory
  13.162 - * @size:      size of the resource to map
  13.163 - *
  13.164 - * ioremap_nocache performs a platform specific sequence of operations to
  13.165 - * make bus memory CPU accessible via the readb/readw/readl/writeb/
  13.166 - * writew/writel functions and the other mmio helpers. The returned
  13.167 - * address is not guaranteed to be usable directly as a virtual
  13.168 - * address. 
  13.169 - *
  13.170 - * This version of ioremap ensures that the memory is marked uncachable
  13.171 - * on the CPU as well as honouring existing caching rules from things like
  13.172 - * the PCI bus. Note that there are other caches and buffers on many 
  13.173 - * busses. In particular driver authors should read up on PCI writes
  13.174 - *
  13.175 - * It's useful if some control registers are in such an area and
  13.176 - * write combining or read caching is not desirable:
  13.177 - * 
  13.178 - * Must be freed with iounmap.
  13.179 - */
  13.180 -
  13.181 -void __iomem *ioremap_nocache (unsigned long phys_addr, unsigned long size)
  13.182 -{
  13.183 -	unsigned long last_addr;
  13.184 -	void __iomem *p = __ioremap(phys_addr, size, _PAGE_PCD);
  13.185 -	if (!p) 
  13.186 -		return p; 
  13.187 -
  13.188 -	/* Guaranteed to be > phys_addr, as per __ioremap() */
  13.189 -	last_addr = phys_addr + size - 1;
  13.190 -
  13.191 -	if (is_local_lowmem(last_addr)) { 
  13.192 -		struct page *ppage = virt_to_page(bus_to_virt(phys_addr));
  13.193 -		unsigned long npages;
  13.194 -
  13.195 -		phys_addr &= PAGE_MASK;
  13.196 -
  13.197 -		/* This might overflow and become zero.. */
  13.198 -		last_addr = PAGE_ALIGN(last_addr);
  13.199 -
  13.200 -		/* .. but that's ok, because modulo-2**n arithmetic will make
  13.201 -	 	* the page-aligned "last - first" come out right.
  13.202 -	 	*/
  13.203 -		npages = (last_addr - phys_addr) >> PAGE_SHIFT;
  13.204 -
  13.205 -		if (change_page_attr(ppage, npages, PAGE_KERNEL_NOCACHE) < 0) { 
  13.206 -			iounmap(p); 
  13.207 -			p = NULL;
  13.208 -		}
  13.209 -		global_flush_tlb();
  13.210 -	}
  13.211 -
  13.212 -	return p;					
  13.213 -}
  13.214 -
  13.215 -void iounmap(volatile void __iomem *addr)
  13.216 -{
  13.217 -	struct vm_struct *p;
  13.218 -	if ((void __force *) addr <= high_memory) 
  13.219 -		return; 
  13.220 -#ifdef CONFIG_XEN_PRIVILEGED_GUEST
  13.221 -	if ((unsigned long) addr >= fix_to_virt(FIX_ISAMAP_BEGIN))
  13.222 -		return;
  13.223 -#endif
  13.224 -	p = remove_vm_area((void *) (PAGE_MASK & (unsigned long __force) addr));
  13.225 -	if (!p) { 
  13.226 -		printk("__iounmap: bad address %p\n", addr);
  13.227 -		return;
  13.228 -	}
  13.229 -
  13.230 -	if ((p->flags >> 20) && is_local_lowmem(p->phys_addr)) {
  13.231 -		/* p->size includes the guard page, but cpa doesn't like that */
  13.232 -		change_page_attr(virt_to_page(bus_to_virt(p->phys_addr)),
  13.233 -				 (p->size - PAGE_SIZE) >> PAGE_SHIFT,
  13.234 -				 PAGE_KERNEL); 				 
  13.235 -		global_flush_tlb();
  13.236 -	} 
  13.237 -	kfree(p); 
  13.238 -}
  13.239 -
  13.240 -#if defined(__i386__)
  13.241 -void __init *bt_ioremap(unsigned long phys_addr, unsigned long size)
  13.242 -{
  13.243 -	unsigned long offset, last_addr;
  13.244 -	unsigned int nrpages;
  13.245 -	enum fixed_addresses idx;
  13.246 -
  13.247 -	/* Don't allow wraparound or zero size */
  13.248 -	last_addr = phys_addr + size - 1;
  13.249 -	if (!size || last_addr < phys_addr)
  13.250 -		return NULL;
  13.251 -
  13.252 -#ifdef CONFIG_XEN_PRIVILEGED_GUEST
  13.253 -	/*
  13.254 -	 * Don't remap the low PCI/ISA area, it's always mapped..
  13.255 -	 */
  13.256 -	if (phys_addr >= 0x0 && last_addr < 0x100000)
  13.257 -		return isa_bus_to_virt(phys_addr);
  13.258 -#endif
  13.259 -
  13.260 -	/*
  13.261 -	 * Mappings have to be page-aligned
  13.262 -	 */
  13.263 -	offset = phys_addr & ~PAGE_MASK;
  13.264 -	phys_addr &= PAGE_MASK;
  13.265 -	size = PAGE_ALIGN(last_addr) - phys_addr;
  13.266 -
  13.267 -	/*
  13.268 -	 * Mappings have to fit in the FIX_BTMAP area.
  13.269 -	 */
  13.270 -	nrpages = size >> PAGE_SHIFT;
  13.271 -	if (nrpages > NR_FIX_BTMAPS)
  13.272 -		return NULL;
  13.273 -
  13.274 -	/*
  13.275 -	 * Ok, go for it..
  13.276 -	 */
  13.277 -	idx = FIX_BTMAP_BEGIN;
  13.278 -	while (nrpages > 0) {
  13.279 -		set_fixmap(idx, phys_addr);
  13.280 -		phys_addr += PAGE_SIZE;
  13.281 -		--idx;
  13.282 -		--nrpages;
  13.283 -	}
  13.284 -	return (void*) (offset + fix_to_virt(FIX_BTMAP_BEGIN));
  13.285 -}
  13.286 -
  13.287 -void __init bt_iounmap(void *addr, unsigned long size)
  13.288 -{
  13.289 -	unsigned long virt_addr;
  13.290 -	unsigned long offset;
  13.291 -	unsigned int nrpages;
  13.292 -	enum fixed_addresses idx;
  13.293 -
  13.294 -	virt_addr = (unsigned long)addr;
  13.295 -	if (virt_addr < fix_to_virt(FIX_BTMAP_BEGIN))
  13.296 -		return;
  13.297 -#ifdef CONFIG_XEN_PRIVILEGED_GUEST
  13.298 -	if (virt_addr >= fix_to_virt(FIX_ISAMAP_BEGIN))
  13.299 -		return;
  13.300 -#endif
  13.301 -	offset = virt_addr & ~PAGE_MASK;
  13.302 -	nrpages = PAGE_ALIGN(offset + size - 1) >> PAGE_SHIFT;
  13.303 -
  13.304 -	idx = FIX_BTMAP_BEGIN;
  13.305 -	while (nrpages > 0) {
  13.306 -		clear_fixmap(idx);
  13.307 -		--idx;
  13.308 -		--nrpages;
  13.309 -	}
  13.310 -}
  13.311 -#endif /* defined(__i386__) */
  13.312 -
  13.313 -#endif /* CONFIG_XEN_PHYSDEV_ACCESS */
  13.314 -
  13.315 -/* These hacky macros avoid phys->machine translations. */
  13.316 -#define __direct_pte(x) ((pte_t) { (x) } )
  13.317 -#define __direct_mk_pte(page_nr,pgprot) \
  13.318 -  __direct_pte(((page_nr) << PAGE_SHIFT) | pgprot_val(pgprot))
  13.319 -#define direct_mk_pte_phys(physpage, pgprot) \
  13.320 -  __direct_mk_pte((physpage) >> PAGE_SHIFT, pgprot)
  13.321 -
  13.322 -static inline void direct_remap_area_pte(pte_t *pte, 
  13.323 -					 unsigned long address, 
  13.324 -					 unsigned long size,
  13.325 -					 mmu_update_t **v)
  13.326 -{
  13.327 -	unsigned long end;
  13.328 -
  13.329 -	address &= ~PMD_MASK;
  13.330 -	end = address + size;
  13.331 -	if (end > PMD_SIZE)
  13.332 -		end = PMD_SIZE;
  13.333 -	if (address >= end)
  13.334 -		BUG();
  13.335 -
  13.336 -	do {
  13.337 -		(*v)->ptr = virt_to_machine(pte);
  13.338 -		(*v)++;
  13.339 -		address += PAGE_SIZE;
  13.340 -		pte++;
  13.341 -	} while (address && (address < end));
  13.342 -}
  13.343 -
  13.344 -static inline int direct_remap_area_pmd(struct mm_struct *mm,
  13.345 -					pmd_t *pmd, 
  13.346 -					unsigned long address, 
  13.347 -					unsigned long size,
  13.348 -					mmu_update_t **v)
  13.349 -{
  13.350 -	unsigned long end;
  13.351 -
  13.352 -	address &= ~PGDIR_MASK;
  13.353 -	end = address + size;
  13.354 -	if (end > PGDIR_SIZE)
  13.355 -		end = PGDIR_SIZE;
  13.356 -	if (address >= end)
  13.357 -		BUG();
  13.358 -	do {
  13.359 -		pte_t *pte = (mm == &init_mm) ? 
  13.360 -			pte_alloc_kernel(mm, pmd, address) :
  13.361 -			pte_alloc_map(mm, pmd, address);
  13.362 -		if (!pte)
  13.363 -			return -ENOMEM;
  13.364 -		direct_remap_area_pte(pte, address, end - address, v);
  13.365 -		pte_unmap(pte);
  13.366 -		address = (address + PMD_SIZE) & PMD_MASK;
  13.367 -		pmd++;
  13.368 -	} while (address && (address < end));
  13.369 -	return 0;
  13.370 -}
  13.371 - 
  13.372 -int __direct_remap_area_pages(struct mm_struct *mm,
  13.373 -			      unsigned long address, 
  13.374 -			      unsigned long size, 
  13.375 -			      mmu_update_t *v)
  13.376 -{
  13.377 -	pgd_t * dir;
  13.378 -	unsigned long end = address + size;
  13.379 -	int error;
  13.380 -
  13.381 -#if defined(__i386__)
  13.382 -	dir = pgd_offset(mm, address);
  13.383 -#elif defined (__x86_64)
  13.384 -        dir = (mm == &init_mm) ?
  13.385 -		pgd_offset_k(address):
  13.386 -		pgd_offset(mm, address);
  13.387 -#endif
  13.388 -	if (address >= end)
  13.389 -		BUG();
  13.390 -	spin_lock(&mm->page_table_lock);
  13.391 -	do {
  13.392 -		pud_t *pud;
  13.393 -		pmd_t *pmd;
  13.394 -
  13.395 -		error = -ENOMEM;
  13.396 -		pud = pud_alloc(mm, dir, address);
  13.397 -		if (!pud)
  13.398 -			break;
  13.399 -		pmd = pmd_alloc(mm, pud, address);
  13.400 -		if (!pmd)
  13.401 -			break;
  13.402 -		error = 0;
  13.403 -		direct_remap_area_pmd(mm, pmd, address, end - address, &v);
  13.404 -		address = (address + PGDIR_SIZE) & PGDIR_MASK;
  13.405 -		dir++;
  13.406 -
  13.407 -	} while (address && (address < end));
  13.408 -	spin_unlock(&mm->page_table_lock);
  13.409 -	return error;
  13.410 -}
  13.411 -
  13.412 -
  13.413 -int direct_remap_area_pages(struct mm_struct *mm,
  13.414 -			    unsigned long address, 
  13.415 -			    unsigned long machine_addr,
  13.416 -			    unsigned long size, 
  13.417 -			    pgprot_t prot,
  13.418 -			    domid_t  domid)
  13.419 -{
  13.420 -	int i;
  13.421 -	unsigned long start_address;
  13.422 -#define MAX_DIRECTMAP_MMU_QUEUE 130
  13.423 -	mmu_update_t u[MAX_DIRECTMAP_MMU_QUEUE], *v = u;
  13.424 -
  13.425 -	start_address = address;
  13.426 -
  13.427 -	flush_cache_all();
  13.428 -
  13.429 -	for (i = 0; i < size; i += PAGE_SIZE) {
  13.430 -		if ((v - u) == MAX_DIRECTMAP_MMU_QUEUE) {
  13.431 -			/* Fill in the PTE pointers. */
  13.432 -			__direct_remap_area_pages(mm,
  13.433 -						  start_address, 
  13.434 -						  address-start_address, 
  13.435 -						  u);
  13.436 - 
  13.437 -			if (HYPERVISOR_mmu_update(u, v - u, NULL, domid) < 0)
  13.438 -				return -EFAULT;
  13.439 -			v = u;
  13.440 -			start_address = address;
  13.441 -		}
  13.442 -
  13.443 -		/*
  13.444 -		 * Fill in the machine address: PTE ptr is done later by
  13.445 -		 * __direct_remap_area_pages(). 
  13.446 -		 */
  13.447 -		v->val = (machine_addr & PAGE_MASK) | pgprot_val(prot);
  13.448 -
  13.449 -		machine_addr += PAGE_SIZE;
  13.450 -		address += PAGE_SIZE; 
  13.451 -		v++;
  13.452 -	}
  13.453 -
  13.454 -	if (v != u) {
  13.455 -		/* get the ptep's filled in */
  13.456 -		__direct_remap_area_pages(mm,
  13.457 -					  start_address, 
  13.458 -					  address-start_address, 
  13.459 -					  u);
  13.460 -		if (unlikely(HYPERVISOR_mmu_update(u, v - u, NULL, domid) < 0))
  13.461 -			return -EFAULT;
  13.462 -	}
  13.463 -
  13.464 -	flush_tlb_all();
  13.465 -
  13.466 -	return 0;
  13.467 -}
  13.468 -
  13.469 -EXPORT_SYMBOL(direct_remap_area_pages);
  13.470 -
  13.471 -static int lookup_pte_fn(
  13.472 -    pte_t *pte, struct page *pte_page, unsigned long addr, void *data) 
  13.473 -{
  13.474 -    unsigned long *ptep = (unsigned long *)data;
  13.475 -    if (ptep) *ptep = (pfn_to_mfn(page_to_pfn(pte_page)) << PAGE_SHIFT)
  13.476 -                  | ((unsigned long)pte & ~PAGE_MASK);
  13.477 -    return 0;
  13.478 -}
  13.479 -
  13.480 -int create_lookup_pte_addr(struct mm_struct *mm, 
  13.481 -                           unsigned long address,
  13.482 -                           unsigned long *ptep)
  13.483 -{
  13.484 -    return generic_page_range(mm, address, PAGE_SIZE, lookup_pte_fn, ptep);
  13.485 -}
  13.486 -
  13.487 -EXPORT_SYMBOL(create_lookup_pte_addr);
  13.488 -
  13.489 -static int noop_fn(
  13.490 -    pte_t *pte, struct page *pte_page, unsigned long addr, void *data) 
  13.491 -{
  13.492 -    return 0;
  13.493 -}
  13.494 -
  13.495 -int touch_pte_range(struct mm_struct *mm,
  13.496 -                    unsigned long address,
  13.497 -                    unsigned long size)
  13.498 -{
  13.499 -    return generic_page_range(mm, address, size, noop_fn, NULL);
  13.500 -}
  13.501 -
  13.502 -EXPORT_SYMBOL(touch_pte_range);
    14.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Tue Aug 23 18:25:51 2005 +0000
    14.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Tue Aug 23 18:27:22 2005 +0000
    14.3 @@ -65,9 +65,6 @@ typedef unsigned int PEND_RING_IDX;
    14.4  static PEND_RING_IDX pending_prod, pending_cons;
    14.5  #define NR_PENDING_REQS (MAX_PENDING_REQS - pending_prod + pending_cons)
    14.6  
    14.7 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
    14.8 -static kmem_cache_t *buffer_head_cachep;
    14.9 -#else
   14.10  static request_queue_t *plugged_queue;
   14.11  static inline void flush_plugged_queue(void)
   14.12  {
   14.13 @@ -80,7 +77,6 @@ static inline void flush_plugged_queue(v
   14.14          plugged_queue = NULL;
   14.15      }
   14.16  }
   14.17 -#endif
   14.18  
   14.19  /* When using grant tables to map a frame for device access then the
   14.20   * handle returned must be used to unmap the frame. This is needed to
   14.21 @@ -184,11 +180,7 @@ static int blkio_schedule(void *arg)
   14.22      blkif_t          *blkif;
   14.23      struct list_head *ent;
   14.24  
   14.25 -    daemonize(
   14.26 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
   14.27 -        "xenblkd"
   14.28 -#endif
   14.29 -        );
   14.30 +    daemonize("xenblkd");
   14.31  
   14.32      for ( ; ; )
   14.33      {
   14.34 @@ -215,11 +207,7 @@ static int blkio_schedule(void *arg)
   14.35          }
   14.36  
   14.37          /* Push the batch through to disc. */
   14.38 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
   14.39 -        run_task_queue(&tq_disk);
   14.40 -#else
   14.41          flush_plugged_queue();
   14.42 -#endif
   14.43      }
   14.44  }
   14.45  
   14.46 @@ -268,13 +256,6 @@ static void __end_block_io_op(pending_re
   14.47      }
   14.48  }
   14.49  
   14.50 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
   14.51 -static void end_block_io_op(struct buffer_head *bh, int uptodate)
   14.52 -{
   14.53 -    __end_block_io_op(bh->b_private, uptodate);
   14.54 -    kmem_cache_free(buffer_head_cachep, bh);
   14.55 -}
   14.56 -#else
   14.57  static int end_block_io_op(struct bio *bio, unsigned int done, int error)
   14.58  {
   14.59      if ( bio->bi_size != 0 )
   14.60 @@ -283,7 +264,6 @@ static int end_block_io_op(struct bio *b
   14.61      bio_put(bio);
   14.62      return error;
   14.63  }
   14.64 -#endif
   14.65  
   14.66  
   14.67  /******************************************************************************
   14.68 @@ -357,13 +337,9 @@ static void dispatch_rw_block_io(blkif_t
   14.69          unsigned long buf; unsigned int nsec;
   14.70      } seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
   14.71      unsigned int nseg;
   14.72 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
   14.73 -    struct buffer_head *bh;
   14.74 -#else
   14.75      struct bio *bio = NULL, *biolist[BLKIF_MAX_SEGMENTS_PER_REQUEST];
   14.76      int nbio = 0;
   14.77      request_queue_t *q;
   14.78 -#endif
   14.79  
   14.80      /* Check that number of segments is sane. */
   14.81      nseg = req->nr_segments;
   14.82 @@ -435,49 +411,6 @@ static void dispatch_rw_block_io(blkif_t
   14.83      pending_req->status    = BLKIF_RSP_OKAY;
   14.84      pending_req->nr_pages  = nseg;
   14.85  
   14.86 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
   14.87 -
   14.88 -    atomic_set(&pending_req->pendcnt, nseg);
   14.89 -    pending_cons++;
   14.90 -    blkif_get(blkif);
   14.91 -
   14.92 -    for ( i = 0; i < nseg; i++ )
   14.93 -    {
   14.94 -        bh = kmem_cache_alloc(buffer_head_cachep, GFP_KERNEL);
   14.95 -        if ( unlikely(bh == NULL) )
   14.96 -        {
   14.97 -            __end_block_io_op(pending_req, 0);
   14.98 -            continue;
   14.99 -        }
  14.100 -
  14.101 -        memset(bh, 0, sizeof (struct buffer_head));
  14.102 -
  14.103 -        init_waitqueue_head(&bh->b_wait);
  14.104 -        bh->b_size          = seg[i].nsec << 9;
  14.105 -        bh->b_dev           = preq.dev;
  14.106 -        bh->b_rdev          = preq.dev;
  14.107 -        bh->b_rsector       = (unsigned long)preq.sector_number;
  14.108 -        bh->b_data          = (char *)MMAP_VADDR(pending_idx, i) +
  14.109 -            (seg[i].buf & ~PAGE_MASK);
  14.110 -        bh->b_page          = virt_to_page(MMAP_VADDR(pending_idx, i));
  14.111 -        bh->b_end_io        = end_block_io_op;
  14.112 -        bh->b_private       = pending_req;
  14.113 -
  14.114 -        bh->b_state = (1 << BH_Mapped) | (1 << BH_Lock) | 
  14.115 -            (1 << BH_Req) | (1 << BH_Launder);
  14.116 -        if ( operation == WRITE )
  14.117 -            bh->b_state |= (1 << BH_JBD) | (1 << BH_Req) | (1 << BH_Uptodate);
  14.118 -
  14.119 -        atomic_set(&bh->b_count, 1);
  14.120 -
  14.121 -        /* Dispatch a single request. We'll flush it to disc later. */
  14.122 -        generic_make_request(operation, bh);
  14.123 -
  14.124 -        preq.sector_number += seg[i].nsec;
  14.125 -    }
  14.126 -
  14.127 -#else
  14.128 -
  14.129      for ( i = 0; i < nseg; i++ )
  14.130      {
  14.131          if ( ((int)preq.sector_number|(int)seg[i].nsec) &
  14.132 @@ -526,8 +459,6 @@ static void dispatch_rw_block_io(blkif_t
  14.133      for ( i = 0; i < nbio; i++ )
  14.134          submit_bio(operation, biolist[i]);
  14.135  
  14.136 -#endif
  14.137 -
  14.138      return;
  14.139  
  14.140   bad_descriptor:
  14.141 @@ -595,12 +526,6 @@ static int __init blkif_init(void)
  14.142      if ( kernel_thread(blkio_schedule, 0, CLONE_FS | CLONE_FILES) < 0 )
  14.143          BUG();
  14.144  
  14.145 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
  14.146 -    buffer_head_cachep = kmem_cache_create(
  14.147 -        "buffer_head_cache", sizeof(struct buffer_head),
  14.148 -        0, SLAB_HWCACHE_ALIGN, NULL, NULL);
  14.149 -#endif
  14.150 -
  14.151      blkif_xenbus_init();
  14.152  
  14.153      memset( pending_grant_handles,  BLKBACK_INVALID_HANDLE, MMAP_PAGES );
    15.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h	Tue Aug 23 18:25:51 2005 +0000
    15.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h	Tue Aug 23 18:27:22 2005 +0000
    15.3 @@ -5,7 +5,6 @@
    15.4  #include <linux/config.h>
    15.5  #include <linux/version.h>
    15.6  #include <linux/module.h>
    15.7 -#include <linux/rbtree.h>
    15.8  #include <linux/interrupt.h>
    15.9  #include <linux/slab.h>
   15.10  #include <linux/blkdev.h>
   15.11 @@ -30,12 +29,13 @@
   15.12  #define DPRINTK(_f, _a...) ((void)0)
   15.13  #endif
   15.14  
   15.15 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
   15.16 -typedef struct rb_root rb_root_t;
   15.17 -typedef struct rb_node rb_node_t;
   15.18 -#else
   15.19 -struct block_device;
   15.20 -#endif
   15.21 +struct vbd {
   15.22 +    blkif_vdev_t   handle;      /* what the domain refers to this vbd as */
   15.23 +    unsigned char  readonly;    /* Non-zero -> read-only */
   15.24 +    unsigned char  type;        /* VDISK_xxx */
   15.25 +    blkif_pdev_t   pdevice;     /* phys device that this vbd maps to */
   15.26 +    struct block_device *bdev;
   15.27 +}; 
   15.28  
   15.29  typedef struct blkif_st {
   15.30      /* Unique identifier for this interface. */
   15.31 @@ -48,25 +48,18 @@ typedef struct blkif_st {
   15.32      /* Comms information. */
   15.33      blkif_back_ring_t blk_ring;
   15.34      /* VBDs attached to this interface. */
   15.35 -    rb_root_t         vbd_rb;        /* Mapping from 16-bit vdevices to VBDs.*/
   15.36 -    spinlock_t        vbd_lock;      /* Protects VBD mapping. */
   15.37 +    struct vbd        vbd;
   15.38      /* Private fields. */
   15.39      enum { DISCONNECTED, CONNECTED } status;
   15.40 -    /*
   15.41 -     * DISCONNECT response is deferred until pending requests are ack'ed.
   15.42 -     * We therefore need to store the id from the original request.
   15.43 -     */
   15.44 -    u8               disconnect_rspid;
   15.45  #ifdef CONFIG_XEN_BLKDEV_TAP_BE
   15.46      /* Is this a blktap frontend */
   15.47      unsigned int     is_blktap;
   15.48  #endif
   15.49 -    struct blkif_st *hash_next;
   15.50      struct list_head blkdev_list;
   15.51      spinlock_t       blk_ring_lock;
   15.52      atomic_t         refcnt;
   15.53  
   15.54 -    struct work_struct work;
   15.55 +    struct work_struct free_work;
   15.56      u16 shmem_handle;
   15.57      unsigned long shmem_vaddr;
   15.58      grant_ref_t shmem_ref;
   15.59 @@ -77,30 +70,25 @@ void blkif_destroy(blkif_be_destroy_t *d
   15.60  void blkif_connect(blkif_be_connect_t *connect);
   15.61  int  blkif_disconnect(blkif_be_disconnect_t *disconnect, u8 rsp_id);
   15.62  void blkif_disconnect_complete(blkif_t *blkif);
   15.63 -blkif_t *blkif_find(domid_t domid);
   15.64 -void free_blkif(blkif_t *blkif);
   15.65 +blkif_t *alloc_blkif(domid_t domid);
   15.66 +void free_blkif_callback(blkif_t *blkif);
   15.67  int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn);
   15.68  
   15.69  #define blkif_get(_b) (atomic_inc(&(_b)->refcnt))
   15.70  #define blkif_put(_b)                             \
   15.71      do {                                          \
   15.72          if ( atomic_dec_and_test(&(_b)->refcnt) ) \
   15.73 -            free_blkif(_b);			  \
   15.74 +            free_blkif_callback(_b);		  \
   15.75      } while (0)
   15.76  
   15.77 -struct vbd;
   15.78 -void vbd_free(blkif_t *blkif, struct vbd *vbd);
   15.79 -
   15.80 -/* Creates inactive vbd. */
   15.81 -struct vbd *vbd_create(blkif_t *blkif, blkif_vdev_t vdevice, blkif_pdev_t pdevice, int readonly);
   15.82 -int vbd_is_active(struct vbd *vbd);
   15.83 -void vbd_activate(blkif_t *blkif, struct vbd *vbd);
   15.84 +/* Create a vbd. */
   15.85 +int vbd_create(blkif_t *blkif, blkif_vdev_t vdevice, blkif_pdev_t pdevice,
   15.86 +	       int readonly);
   15.87 +void vbd_free(struct vbd *vbd);
   15.88  
   15.89  unsigned long vbd_size(struct vbd *vbd);
   15.90  unsigned int vbd_info(struct vbd *vbd);
   15.91  unsigned long vbd_secsize(struct vbd *vbd);
   15.92 -void vbd_destroy(blkif_be_vbd_destroy_t *delete); 
   15.93 -void destroy_all_vbds(blkif_t *blkif);
   15.94  
   15.95  struct phys_req {
   15.96      unsigned short       dev;
    16.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Tue Aug 23 18:25:51 2005 +0000
    16.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Tue Aug 23 18:27:22 2005 +0000
    16.3 @@ -9,27 +9,11 @@
    16.4  #include "common.h"
    16.5  #include <asm-xen/evtchn.h>
    16.6  
    16.7 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    16.8 -#define VMALLOC_VMADDR(x) ((unsigned long)(x))
    16.9 -#endif
   16.10 -
   16.11 -#define BLKIF_HASHSZ 1024
   16.12 -#define BLKIF_HASH(_d) (((int)(_d))&(BLKIF_HASHSZ-1))
   16.13 -
   16.14  static kmem_cache_t *blkif_cachep;
   16.15 -static blkif_t      *blkif_hash[BLKIF_HASHSZ];
   16.16  
   16.17 -blkif_t *blkif_find(domid_t domid)
   16.18 +blkif_t *alloc_blkif(domid_t domid)
   16.19  {
   16.20 -    blkif_t *blkif = blkif_hash[BLKIF_HASH(domid)];
   16.21 -
   16.22 -    while (blkif) {
   16.23 -	if (blkif->domid == domid) {
   16.24 -	    blkif_get(blkif);
   16.25 -	    return blkif;
   16.26 -	}
   16.27 -        blkif = blkif->hash_next;
   16.28 -    }
   16.29 +    blkif_t *blkif;
   16.30  
   16.31      blkif = kmem_cache_alloc(blkif_cachep, GFP_KERNEL);
   16.32      if (!blkif)
   16.33 @@ -38,12 +22,9 @@ blkif_t *blkif_find(domid_t domid)
   16.34      memset(blkif, 0, sizeof(*blkif));
   16.35      blkif->domid = domid;
   16.36      blkif->status = DISCONNECTED;
   16.37 -    spin_lock_init(&blkif->vbd_lock);
   16.38      spin_lock_init(&blkif->blk_ring_lock);
   16.39      atomic_set(&blkif->refcnt, 1);
   16.40  
   16.41 -    blkif->hash_next = blkif_hash[BLKIF_HASH(domid)];
   16.42 -    blkif_hash[BLKIF_HASH(domid)] = blkif;
   16.43      return blkif;
   16.44  }
   16.45  
   16.46 @@ -55,7 +36,7 @@ static int map_frontend_page(blkif_t *bl
   16.47      op.flags = GNTMAP_host_map;
   16.48      op.ref = shared_page;
   16.49      op.dom = blkif->domid;
   16.50 -       
   16.51 +
   16.52      BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
   16.53  
   16.54      if (op.handle < 0) {
   16.55 @@ -91,7 +72,7 @@ int blkif_map(blkif_t *blkif, unsigned l
   16.56      if ( (vma = get_vm_area(PAGE_SIZE, VM_IOREMAP)) == NULL )
   16.57  	return -ENOMEM;
   16.58  
   16.59 -    err = map_frontend_page(blkif, VMALLOC_VMADDR(vma->addr), shared_page);
   16.60 +    err = map_frontend_page(blkif, (unsigned long)vma->addr, shared_page);
   16.61      if (err) {
   16.62          vfree(vma->addr);
   16.63  	return err;
   16.64 @@ -123,10 +104,10 @@ int blkif_map(blkif_t *blkif, unsigned l
   16.65      return 0;
   16.66  }
   16.67  
   16.68 -void free_blkif(blkif_t *blkif)
   16.69 +static void free_blkif(void *arg)
   16.70  {
   16.71 -    blkif_t     **pblkif;
   16.72      evtchn_op_t op = { .cmd = EVTCHNOP_close };
   16.73 +    blkif_t *blkif = (blkif_t *)arg;
   16.74  
   16.75      op.u.close.port = blkif->evtchn;
   16.76      op.u.close.dom = DOMID_SELF;
   16.77 @@ -135,6 +116,8 @@ void free_blkif(blkif_t *blkif)
   16.78      op.u.close.dom = blkif->domid;
   16.79      HYPERVISOR_event_channel_op(&op);
   16.80  
   16.81 +    vbd_free(&blkif->vbd);
   16.82 +
   16.83      if (blkif->evtchn)
   16.84          unbind_evtchn_from_irqhandler(blkif->evtchn, blkif);
   16.85  
   16.86 @@ -143,20 +126,17 @@ void free_blkif(blkif_t *blkif)
   16.87  	vfree(blkif->blk_ring.sring);
   16.88      }
   16.89  
   16.90 -    pblkif = &blkif_hash[BLKIF_HASH(blkif->domid)];
   16.91 -    while ( *pblkif != blkif )
   16.92 -    {
   16.93 -	BUG_ON(!*pblkif);
   16.94 -        pblkif = &(*pblkif)->hash_next;
   16.95 -    }
   16.96 -    *pblkif = blkif->hash_next;
   16.97 -    destroy_all_vbds(blkif);
   16.98      kmem_cache_free(blkif_cachep, blkif);
   16.99  }
  16.100  
  16.101 +void free_blkif_callback(blkif_t *blkif)
  16.102 +{
  16.103 +    INIT_WORK(&blkif->free_work, free_blkif, (void *)blkif);
  16.104 +    schedule_work(&blkif->free_work);
  16.105 +}
  16.106 +
  16.107  void __init blkif_interface_init(void)
  16.108  {
  16.109      blkif_cachep = kmem_cache_create("blkif_cache", sizeof(blkif_t), 
  16.110                                       0, 0, NULL, NULL);
  16.111 -    memset(blkif_hash, 0, sizeof(blkif_hash));
  16.112  }
    17.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c	Tue Aug 23 18:25:51 2005 +0000
    17.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c	Tue Aug 23 18:27:22 2005 +0000
    17.3 @@ -3,38 +3,19 @@
    17.4   * 
    17.5   * Routines for managing virtual block devices (VBDs).
    17.6   * 
    17.7 - * NOTE: vbd_lock protects updates to the rb_tree against concurrent lookups 
    17.8 - * in vbd_translate.  All other lookups are implicitly protected because the 
    17.9 - * only caller (the control message dispatch routine) serializes the calls.
   17.10 - * 
   17.11   * Copyright (c) 2003-2005, Keir Fraser & Steve Hand
   17.12   */
   17.13  
   17.14  #include "common.h"
   17.15  #include <asm-xen/xenbus.h>
   17.16  
   17.17 -struct vbd { 
   17.18 -    blkif_vdev_t   handle;     /* what the domain refers to this vbd as */
   17.19 -    unsigned char  readonly;    /* Non-zero -> read-only */
   17.20 -    unsigned char  type;        /* VDISK_xxx */
   17.21 -    blkif_pdev_t   pdevice;     /* phys device that this vbd maps to */
   17.22 -    struct block_device *bdev;
   17.23 -
   17.24 -    int active;
   17.25 -    rb_node_t      rb;          /* for linking into R-B tree lookup struct */
   17.26 -}; 
   17.27 -
   17.28 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
   17.29  static inline dev_t vbd_map_devnum(blkif_pdev_t cookie)
   17.30 -{ return MKDEV(cookie>>8, cookie&0xff); }
   17.31 +{
   17.32 +    return MKDEV(BLKIF_MAJOR(cookie), BLKIF_MINOR(cookie));
   17.33 +}
   17.34  #define vbd_sz(_v)   ((_v)->bdev->bd_part ? \
   17.35      (_v)->bdev->bd_part->nr_sects : (_v)->bdev->bd_disk->capacity)
   17.36  #define bdev_put(_b) blkdev_put(_b)
   17.37 -#else
   17.38 -#define vbd_sz(_v)   (blk_size[MAJOR((_v)->pdevice)][MINOR((_v)->pdevice)]*2)
   17.39 -#define bdev_put(_b) ((void)0)
   17.40 -#define bdev_hardsect_size(_b) 512
   17.41 -#endif
   17.42  
   17.43  unsigned long vbd_size(struct vbd *vbd)
   17.44  {
   17.45 @@ -51,45 +32,32 @@ unsigned long vbd_secsize(struct vbd *vb
   17.46  	return bdev_hardsect_size(vbd->bdev);
   17.47  }
   17.48  
   17.49 -int vbd_is_active(struct vbd *vbd)
   17.50 -{
   17.51 -	return vbd->active;
   17.52 -}
   17.53 -
   17.54 -struct vbd *vbd_create(blkif_t *blkif, blkif_vdev_t handle,
   17.55 -		       blkif_pdev_t pdevice, int readonly)
   17.56 +int vbd_create(blkif_t *blkif, blkif_vdev_t handle,
   17.57 +	       blkif_pdev_t pdevice, int readonly)
   17.58  {
   17.59 -    struct vbd  *vbd; 
   17.60 +    struct vbd *vbd;
   17.61  
   17.62 -    if ( unlikely((vbd = kmalloc(sizeof(struct vbd), GFP_KERNEL)) == NULL) )
   17.63 -    {
   17.64 -        DPRINTK("vbd_create: out of memory\n");
   17.65 -	return ERR_PTR(-ENOMEM);
   17.66 -    }
   17.67 -
   17.68 +    vbd = &blkif->vbd;
   17.69      vbd->handle   = handle; 
   17.70      vbd->readonly = readonly;
   17.71      vbd->type     = 0;
   17.72 -    vbd->active   = 0;
   17.73  
   17.74      vbd->pdevice  = pdevice;
   17.75  
   17.76 -    /* FIXME: Who frees vbd on failure? --RR */
   17.77 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
   17.78      vbd->bdev = open_by_devnum(
   17.79          vbd_map_devnum(vbd->pdevice),
   17.80          vbd->readonly ? FMODE_READ : FMODE_WRITE);
   17.81      if ( IS_ERR(vbd->bdev) )
   17.82      {
   17.83          DPRINTK("vbd_creat: device %08x doesn't exist.\n", vbd->pdevice);
   17.84 -        return ERR_PTR(-ENOENT);
   17.85 +        return -ENOENT;
   17.86      }
   17.87  
   17.88      if ( (vbd->bdev->bd_disk == NULL) )
   17.89      {
   17.90          DPRINTK("vbd_creat: device %08x doesn't exist.\n", vbd->pdevice);
   17.91 -        bdev_put(vbd->bdev);
   17.92 -        return ERR_PTR(-ENOENT);
   17.93 +	vbd_free(vbd);
   17.94 +        return -ENOENT;
   17.95      }
   17.96  
   17.97      if ( vbd->bdev->bd_disk->flags & GENHD_FL_CD )
   17.98 @@ -97,121 +65,27 @@ struct vbd *vbd_create(blkif_t *blkif, b
   17.99      if ( vbd->bdev->bd_disk->flags & GENHD_FL_REMOVABLE )
  17.100          vbd->type |= VDISK_REMOVABLE;
  17.101  
  17.102 -#else
  17.103 -    if ( (blk_size[MAJOR(vbd->pdevice)] == NULL) || (vbd_sz(vbd) == 0) )
  17.104 -    {
  17.105 -        DPRINTK("vbd_creat: device %08x doesn't exist.\n", vbd->pdevice);
  17.106 -        return ERR_PTR(-ENOENT);
  17.107 -    }
  17.108 -#endif
  17.109 -
  17.110      DPRINTK("Successful creation of handle=%04x (dom=%u)\n",
  17.111              handle, blkif->domid);
  17.112 -    return vbd;
  17.113 +    return 0;
  17.114  }
  17.115  
  17.116 -void vbd_activate(blkif_t *blkif, struct vbd *vbd)
  17.117 +void vbd_free(struct vbd *vbd)
  17.118  {
  17.119 -    rb_node_t  **rb_p, *rb_parent = NULL;
  17.120 -    struct vbd *i;
  17.121 -    BUG_ON(vbd_is_active(vbd));
  17.122 -
  17.123 -    /* Find where to put it. */
  17.124 -    rb_p = &blkif->vbd_rb.rb_node;
  17.125 -    while ( *rb_p != NULL )
  17.126 -    {
  17.127 -        rb_parent = *rb_p;
  17.128 -        i = rb_entry(rb_parent, struct vbd, rb);
  17.129 -        if ( vbd->handle < i->handle )
  17.130 -        {
  17.131 -            rb_p = &rb_parent->rb_left;
  17.132 -        }
  17.133 -        else if ( vbd->handle > i->handle )
  17.134 -        {
  17.135 -            rb_p = &rb_parent->rb_right;
  17.136 -        }
  17.137 -        else
  17.138 -        {
  17.139 -	    /* We never create two of same vbd, so not possible. */
  17.140 -	    BUG();
  17.141 -        }
  17.142 -    }
  17.143 -
  17.144 -    /* Now we're active. */
  17.145 -    vbd->active = 1;
  17.146 -    blkif_get(blkif);
  17.147 -
  17.148 -    spin_lock(&blkif->vbd_lock);
  17.149 -    rb_link_node(&vbd->rb, rb_parent, rb_p);
  17.150 -    rb_insert_color(&vbd->rb, &blkif->vbd_rb);
  17.151 -    spin_unlock(&blkif->vbd_lock);
  17.152 -}
  17.153 -
  17.154 -void vbd_free(blkif_t *blkif, struct vbd *vbd)
  17.155 -{
  17.156 -    if (vbd_is_active(vbd)) {
  17.157 -	spin_lock(&blkif->vbd_lock);
  17.158 -	rb_erase(&vbd->rb, &blkif->vbd_rb);
  17.159 -	spin_unlock(&blkif->vbd_lock);
  17.160 -	blkif_put(blkif);
  17.161 -    }
  17.162 -    bdev_put(vbd->bdev);
  17.163 -    kfree(vbd);
  17.164 -}
  17.165 -
  17.166 -void destroy_all_vbds(blkif_t *blkif)
  17.167 -{
  17.168 -    struct vbd *vbd;
  17.169 -    rb_node_t  *rb;
  17.170 -
  17.171 -    spin_lock(&blkif->vbd_lock);
  17.172 -
  17.173 -    while ( (rb = blkif->vbd_rb.rb_node) != NULL )
  17.174 -    {
  17.175 -        vbd = rb_entry(rb, struct vbd, rb);
  17.176 -        rb_erase(rb, &blkif->vbd_rb);
  17.177 -        spin_unlock(&blkif->vbd_lock);
  17.178 -        bdev_put(vbd->bdev);
  17.179 -        kfree(vbd);
  17.180 -        spin_lock(&blkif->vbd_lock);
  17.181 -        blkif_put(blkif);
  17.182 -    }
  17.183 -
  17.184 -    spin_unlock(&blkif->vbd_lock);
  17.185 +    if (vbd->bdev)
  17.186 +	bdev_put(vbd->bdev);
  17.187 +    vbd->bdev = NULL;
  17.188  }
  17.189  
  17.190  int vbd_translate(struct phys_req *req, blkif_t *blkif, int operation)
  17.191  {
  17.192 -    struct vbd *vbd;
  17.193 -    rb_node_t  *rb;
  17.194 -    int         rc = -EACCES;
  17.195 -
  17.196 -    /* Take the vbd_lock because another thread could be updating the tree. */
  17.197 -    spin_lock(&blkif->vbd_lock);
  17.198 +    struct vbd *vbd = &blkif->vbd;
  17.199 +    int rc = -EACCES;
  17.200  
  17.201 -    rb = blkif->vbd_rb.rb_node;
  17.202 -    while ( rb != NULL )
  17.203 -    {
  17.204 -        vbd = rb_entry(rb, struct vbd, rb);
  17.205 -        if ( req->dev < vbd->handle )
  17.206 -            rb = rb->rb_left;
  17.207 -        else if ( req->dev > vbd->handle )
  17.208 -            rb = rb->rb_right;
  17.209 -        else
  17.210 -            goto found;
  17.211 -    }
  17.212 -
  17.213 -    DPRINTK("vbd_translate; domain %u attempted to access "
  17.214 -            "non-existent VBD.\n", blkif->domid);
  17.215 -    rc = -ENODEV;
  17.216 -    goto out;
  17.217 -
  17.218 - found:
  17.219 -
  17.220 -    if ( (operation == WRITE) && vbd->readonly )
  17.221 +    if ((operation == WRITE) && vbd->readonly)
  17.222          goto out;
  17.223  
  17.224 -    if ( unlikely((req->sector_number + req->nr_sects) > vbd_sz(vbd)) )
  17.225 +    if (unlikely((req->sector_number + req->nr_sects) > vbd_sz(vbd)))
  17.226          goto out;
  17.227  
  17.228      req->dev  = vbd->pdevice;
  17.229 @@ -219,6 +93,5 @@ int vbd_translate(struct phys_req *req, 
  17.230      rc = 0;
  17.231  
  17.232   out:
  17.233 -    spin_unlock(&blkif->vbd_lock);
  17.234      return rc;
  17.235  }
    18.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Tue Aug 23 18:25:51 2005 +0000
    18.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Tue Aug 23 18:27:22 2005 +0000
    18.3 @@ -26,7 +26,6 @@ struct backend_info
    18.4  
    18.5  	/* our communications channel */
    18.6  	blkif_t *blkif;
    18.7 -	struct vbd *vbd;
    18.8  
    18.9  	long int frontend_id;
   18.10  	long int pdev;
   18.11 @@ -47,8 +46,6 @@ static int blkback_remove(struct xenbus_
   18.12  	if (be->watch.node)
   18.13  		unregister_xenbus_watch(&be->watch);
   18.14  	unregister_xenbus_watch(&be->backend_watch);
   18.15 -	if (be->vbd)
   18.16 -		vbd_free(be->blkif, be->vbd);
   18.17  	if (be->blkif)
   18.18  		blkif_put(be->blkif);
   18.19  	if (be->frontpath)
   18.20 @@ -72,7 +69,7 @@ static void frontend_changed(struct xenb
   18.21  		device_unregister(&be->dev->dev);
   18.22  		return;
   18.23  	}
   18.24 -	if (vbd_is_active(be->vbd))
   18.25 +	if (be->blkif->status == CONNECTED)
   18.26  		return;
   18.27  
   18.28  	err = xenbus_gather(be->frontpath, "grant-id", "%lu", &sharedmfn,
   18.29 @@ -85,9 +82,8 @@ static void frontend_changed(struct xenb
   18.30  	}
   18.31  
   18.32  	/* Domains must use same shared frame for all vbds. */
   18.33 -	if (be->blkif->status == CONNECTED &&
   18.34 -	    (evtchn != be->blkif->remote_evtchn ||
   18.35 -	     sharedmfn != be->blkif->shmem_frame)) {
   18.36 +	if (evtchn != be->blkif->remote_evtchn ||
   18.37 +	    sharedmfn != be->blkif->shmem_frame) {
   18.38  		xenbus_dev_error(be->dev, err,
   18.39  				 "Shared frame/evtchn %li/%u not same as"
   18.40  				 " old %li/%u",
   18.41 @@ -105,7 +101,7 @@ static void frontend_changed(struct xenb
   18.42  	}
   18.43  
   18.44  	err = xenbus_printf(be->dev->nodename, "sectors", "%lu",
   18.45 -			    vbd_size(be->vbd));
   18.46 +			    vbd_size(&be->blkif->vbd));
   18.47  	if (err) {
   18.48  		xenbus_dev_error(be->dev, err, "writing %s/sectors",
   18.49  				 be->dev->nodename);
   18.50 @@ -114,34 +110,29 @@ static void frontend_changed(struct xenb
   18.51  
   18.52  	/* FIXME: use a typename instead */
   18.53  	err = xenbus_printf(be->dev->nodename, "info", "%u",
   18.54 -			    vbd_info(be->vbd));
   18.55 +			    vbd_info(&be->blkif->vbd));
   18.56  	if (err) {
   18.57  		xenbus_dev_error(be->dev, err, "writing %s/info",
   18.58  				 be->dev->nodename);
   18.59  		goto abort;
   18.60  	}
   18.61  	err = xenbus_printf(be->dev->nodename, "sector-size", "%lu",
   18.62 -			    vbd_secsize(be->vbd));
   18.63 +			    vbd_secsize(&be->blkif->vbd));
   18.64  	if (err) {
   18.65  		xenbus_dev_error(be->dev, err, "writing %s/sector-size",
   18.66  				 be->dev->nodename);
   18.67  		goto abort;
   18.68  	}
   18.69  
   18.70 -	/* First vbd?  We need to map the shared frame, irq etc. */
   18.71 -	if (be->blkif->status != CONNECTED) {
   18.72 -		err = blkif_map(be->blkif, sharedmfn, evtchn);
   18.73 -		if (err) {
   18.74 -			xenbus_dev_error(be->dev, err,
   18.75 -					 "mapping shared-frame %lu port %u",
   18.76 -					 sharedmfn, evtchn);
   18.77 -			goto abort;
   18.78 -		}
   18.79 +	/* Map the shared frame, irq etc. */
   18.80 +	err = blkif_map(be->blkif, sharedmfn, evtchn);
   18.81 +	if (err) {
   18.82 +		xenbus_dev_error(be->dev, err,
   18.83 +				 "mapping shared-frame %lu port %u",
   18.84 +				 sharedmfn, evtchn);
   18.85 +		goto abort;
   18.86  	}
   18.87  
   18.88 -	/* We're ready, activate. */
   18.89 -	vbd_activate(be->blkif, be->vbd);
   18.90 -
   18.91  	xenbus_transaction_end(0);
   18.92  	xenbus_dev_ok(be->dev);
   18.93  
   18.94 @@ -228,20 +219,16 @@ static void backend_changed(struct xenbu
   18.95  		p = strrchr(be->frontpath, '/') + 1;
   18.96  		handle = simple_strtoul(p, NULL, 0);
   18.97  
   18.98 -		be->blkif = blkif_find(be->frontend_id);
   18.99 +		be->blkif = alloc_blkif(be->frontend_id);
  18.100  		if (IS_ERR(be->blkif)) {
  18.101  			err = PTR_ERR(be->blkif);
  18.102  			be->blkif = NULL;
  18.103  			goto device_fail;
  18.104  		}
  18.105  
  18.106 -		be->vbd = vbd_create(be->blkif, handle, be->pdev,
  18.107 -				     be->readonly);
  18.108 -		if (IS_ERR(be->vbd)) {
  18.109 -			err = PTR_ERR(be->vbd);
  18.110 -			be->vbd = NULL;
  18.111 +		err = vbd_create(be->blkif, handle, be->pdev, be->readonly);
  18.112 +		if (err)
  18.113  			goto device_fail;
  18.114 -		}
  18.115  
  18.116  		frontend_changed(&be->watch, be->frontpath);
  18.117  	}
    19.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Tue Aug 23 18:25:51 2005 +0000
    19.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Tue Aug 23 18:27:22 2005 +0000
    19.3 @@ -63,25 +63,16 @@ typedef unsigned char byte; /* from linu
    19.4  /* Control whether runtime update of vbds is enabled. */
    19.5  #define ENABLE_VBD_UPDATE 1
    19.6  
    19.7 -#define BLKIF_STATE_CLOSED       0
    19.8 -#define BLKIF_STATE_DISCONNECTED 1
    19.9 -#define BLKIF_STATE_CONNECTED    2
   19.10 +#define BLKIF_STATE_DISCONNECTED 0
   19.11 +#define BLKIF_STATE_CONNECTED    1
   19.12  
   19.13 -static unsigned int blkif_state = BLKIF_STATE_CLOSED;
   19.14 -static unsigned int blkif_evtchn = 0;
   19.15 -static unsigned int blkif_vbds = 0;
   19.16 -static unsigned int blkif_vbds_connected = 0;
   19.17 -
   19.18 -static blkif_front_ring_t blk_ring;
   19.19 +static unsigned int blkif_state = BLKIF_STATE_DISCONNECTED;
   19.20  
   19.21  #define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, PAGE_SIZE)
   19.22  
   19.23 -static domid_t rdomid = 0;
   19.24 -static grant_ref_t gref_head, gref_terminal;
   19.25  #define MAXIMUM_OUTSTANDING_BLOCK_REQS \
   19.26      (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLKIF_RING_SIZE)
   19.27  #define GRANTREF_INVALID (1<<15)
   19.28 -static int shmem_ref;
   19.29  
   19.30  static struct blk_shadow {
   19.31      blkif_request_t req;
   19.32 @@ -92,7 +83,7 @@ unsigned long blk_shadow_free;
   19.33  
   19.34  static int recovery = 0; /* Recovery in progress: protected by blkif_io_lock */
   19.35  
   19.36 -static void kick_pending_request_queues(void);
   19.37 +static void kick_pending_request_queues(struct blkfront_info *info);
   19.38  
   19.39  static int __init xlblk_init(void);
   19.40  
   19.41 @@ -119,7 +110,7 @@ static inline void ADD_ID_TO_FREELIST(un
   19.42  
   19.43  /* Kernel-specific definitions used in the common code */
   19.44  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
   19.45 -#define DISABLE_SCATTERGATHER() 
   19.46 +#define DISABLE_SCATTERGATHER()
   19.47  #else
   19.48  static int sg_operation = -1;
   19.49  #define DISABLE_SCATTERGATHER() (sg_operation = -1)
   19.50 @@ -138,11 +129,11 @@ static inline void unpickle_request(blki
   19.51  }
   19.52  
   19.53  
   19.54 -static inline void flush_requests(void)
   19.55 +static inline void flush_requests(struct blkfront_info *info)
   19.56  {
   19.57      DISABLE_SCATTERGATHER();
   19.58 -    RING_PUSH_REQUESTS(&blk_ring);
   19.59 -    notify_via_evtchn(blkif_evtchn);
   19.60 +    RING_PUSH_REQUESTS(&info->ring);
   19.61 +    notify_via_evtchn(info->evtchn);
   19.62  }
   19.63  
   19.64  
   19.65 @@ -152,30 +143,39 @@ static inline void flush_requests(void)
   19.66  
   19.67  module_init(xlblk_init);
   19.68  
   19.69 -static struct xlbd_disk_info *head_waiting = NULL;
   19.70 -static void kick_pending_request_queues(void)
   19.71 +static void kick_pending_request_queues(struct blkfront_info *info)
   19.72  {
   19.73 -    struct xlbd_disk_info *di;
   19.74 -    while ( ((di = head_waiting) != NULL) && !RING_FULL(&blk_ring) )
   19.75 -    {
   19.76 -        head_waiting = di->next_waiting;
   19.77 -        di->next_waiting = NULL;
   19.78 -        /* Re-enable calldowns. */
   19.79 -        blk_start_queue(di->rq);
   19.80 -        /* Kick things off immediately. */
   19.81 -        do_blkif_request(di->rq);
   19.82 -    }
   19.83 +	if (!RING_FULL(&info->ring)) {
   19.84 +		/* Re-enable calldowns. */
   19.85 +		blk_start_queue(info->rq);
   19.86 +		/* Kick things off immediately. */
   19.87 +		do_blkif_request(info->rq);
   19.88 +	}
   19.89 +}
   19.90 +
   19.91 +static void blkif_restart_queue(void *arg)
   19.92 +{
   19.93 +	struct blkfront_info *info = (struct blkfront_info *)arg;
   19.94 +	spin_lock_irq(&blkif_io_lock);
   19.95 +	kick_pending_request_queues(info);
   19.96 +	spin_unlock_irq(&blkif_io_lock);
   19.97 +}
   19.98 +
   19.99 +static void blkif_restart_queue_callback(void *arg)
  19.100 +{
  19.101 +	struct blkfront_info *info = (struct blkfront_info *)arg;
  19.102 +	schedule_work(&info->work);
  19.103  }
  19.104  
  19.105  int blkif_open(struct inode *inode, struct file *filep)
  19.106  {
  19.107 -    struct gendisk *gd = inode->i_bdev->bd_disk;
  19.108 -    struct xlbd_disk_info *di = (struct xlbd_disk_info *)gd->private_data;
  19.109 +	// struct gendisk *gd = inode->i_bdev->bd_disk;
  19.110 +	// struct xlbd_disk_info *di = (struct xlbd_disk_info *)gd->private_data;
  19.111  
  19.112 -    /* Update of usage count is protected by per-device semaphore. */
  19.113 -    di->mi->usage++;
  19.114 -    
  19.115 -    return 0;
  19.116 +	/* Update of usage count is protected by per-device semaphore. */
  19.117 +	// di->mi->usage++;
  19.118 +
  19.119 +	return 0;
  19.120  }
  19.121  
  19.122  
  19.123 @@ -192,8 +192,8 @@ int blkif_ioctl(struct inode *inode, str
  19.124      int i;
  19.125  
  19.126      DPRINTK_IOCTL("command: 0x%x, argument: 0x%lx, dev: 0x%04x\n",
  19.127 -                  command, (long)argument, inode->i_rdev); 
  19.128 -  
  19.129 +                  command, (long)argument, inode->i_rdev);
  19.130 +
  19.131      switch ( command )
  19.132      {
  19.133      case HDIO_GETGEO:
  19.134 @@ -219,7 +219,7 @@ int blkif_ioctl(struct inode *inode, str
  19.135  /*
  19.136   * blkif_queue_request
  19.137   *
  19.138 - * request block io 
  19.139 + * request block io
  19.140   * 
  19.141   * id: for guest use only.
  19.142   * operation: BLKIF_OP_{READ,WRITE,PROBE}
  19.143 @@ -228,7 +228,7 @@ int blkif_ioctl(struct inode *inode, str
  19.144   */
  19.145  static int blkif_queue_request(struct request *req)
  19.146  {
  19.147 -    struct xlbd_disk_info *di = req->rq_disk->private_data;
  19.148 +    struct blkfront_info *info = req->rq_disk->private_data;
  19.149      unsigned long buffer_ma;
  19.150      blkif_request_t *ring_req;
  19.151      struct bio *bio;
  19.152 @@ -237,20 +237,28 @@ static int blkif_queue_request(struct re
  19.153      unsigned long id;
  19.154      unsigned int fsect, lsect;
  19.155      int ref;
  19.156 +    grant_ref_t gref_head;
  19.157  
  19.158 -    if ( unlikely(blkif_state != BLKIF_STATE_CONNECTED) )
  19.159 +    if (unlikely(info->connected != BLKIF_STATE_CONNECTED))
  19.160          return 1;
  19.161  
  19.162 +    if (gnttab_alloc_grant_references(BLKIF_MAX_SEGMENTS_PER_REQUEST,
  19.163 +				      &gref_head) < 0) {
  19.164 +	    gnttab_request_free_callback(&info->callback,
  19.165 +					 blkif_restart_queue_callback, info,
  19.166 +					 BLKIF_MAX_SEGMENTS_PER_REQUEST);
  19.167 +	    return 1;
  19.168 +    }
  19.169 +
  19.170      /* Fill out a communications ring structure. */
  19.171 -    ring_req = RING_GET_REQUEST(&blk_ring, blk_ring.req_prod_pvt);
  19.172 +    ring_req = RING_GET_REQUEST(&info->ring, info->ring.req_prod_pvt);
  19.173      id = GET_ID_FROM_FREELIST();
  19.174      blk_shadow[id].request = (unsigned long)req;
  19.175  
  19.176      ring_req->id = id;
  19.177 -    ring_req->operation = rq_data_dir(req) ? BLKIF_OP_WRITE :
  19.178 -        BLKIF_OP_READ;
  19.179 +    ring_req->operation = rq_data_dir(req) ? BLKIF_OP_WRITE : BLKIF_OP_READ;
  19.180      ring_req->sector_number = (blkif_sector_t)req->sector;
  19.181 -    ring_req->handle = di->handle;
  19.182 +    ring_req->handle = info->handle;
  19.183  
  19.184      ring_req->nr_segments = 0;
  19.185      rq_for_each_bio(bio, req)
  19.186 @@ -263,56 +271,61 @@ static int blkif_queue_request(struct re
  19.187              fsect = bvec->bv_offset >> 9;
  19.188              lsect = fsect + (bvec->bv_len >> 9) - 1;
  19.189              /* install a grant reference. */
  19.190 -            ref = gnttab_claim_grant_reference(&gref_head, gref_terminal);
  19.191 +            ref = gnttab_claim_grant_reference(&gref_head);
  19.192              ASSERT( ref != -ENOSPC );
  19.193  
  19.194              gnttab_grant_foreign_access_ref(
  19.195                          ref,
  19.196 -                        rdomid,
  19.197 +                        info->backend_id,
  19.198                          buffer_ma >> PAGE_SHIFT,
  19.199                          rq_data_dir(req) );
  19.200  
  19.201              blk_shadow[id].frame[ring_req->nr_segments] =
  19.202                  buffer_ma >> PAGE_SHIFT;
  19.203  
  19.204 -            ring_req->frame_and_sects[ring_req->nr_segments++] =
  19.205 +            ring_req->frame_and_sects[ring_req->nr_segments] =
  19.206                  blkif_fas_from_gref(ref, fsect, lsect);
  19.207 +
  19.208 +	    ring_req->nr_segments++;
  19.209          }
  19.210      }
  19.211  
  19.212 -    blk_ring.req_prod_pvt++;
  19.213 -    
  19.214 +    info->ring.req_prod_pvt++;
  19.215 +
  19.216      /* Keep a private copy so we can reissue requests when recovering. */
  19.217      pickle_request(&blk_shadow[id], ring_req);
  19.218  
  19.219 +    gnttab_free_grant_references(gref_head);
  19.220 +
  19.221      return 0;
  19.222  }
  19.223  
  19.224 -
  19.225  /*
  19.226   * do_blkif_request
  19.227   *  read a block; request is in a request queue
  19.228   */
  19.229  void do_blkif_request(request_queue_t *rq)
  19.230  {
  19.231 -    struct xlbd_disk_info *di;
  19.232 +    struct blkfront_info *info = NULL;
  19.233      struct request *req;
  19.234      int queued;
  19.235  
  19.236 -    DPRINTK("Entered do_blkif_request\n"); 
  19.237 +    DPRINTK("Entered do_blkif_request\n");
  19.238  
  19.239      queued = 0;
  19.240  
  19.241      while ( (req = elv_next_request(rq)) != NULL )
  19.242      {
  19.243 +	info = req->rq_disk->private_data;
  19.244 +
  19.245          if ( !blk_fs_request(req) )
  19.246          {
  19.247              end_request(req, 0);
  19.248              continue;
  19.249          }
  19.250  
  19.251 -        if ( RING_FULL(&blk_ring) )
  19.252 -            goto wait;
  19.253 +	if (RING_FULL(&info->ring))
  19.254 +		goto wait;
  19.255  
  19.256          DPRINTK("do_blk_req %p: cmd %p, sec %lx, (%u/%li) buffer:%p [%s]\n",
  19.257                  req, req->cmd, req->sector, req->current_nr_sectors,
  19.258 @@ -320,25 +333,19 @@ void do_blkif_request(request_queue_t *r
  19.259                  rq_data_dir(req) ? "write" : "read");
  19.260  
  19.261          blkdev_dequeue_request(req);
  19.262 -        if ( blkif_queue_request(req) )
  19.263 -        {
  19.264 +        if (blkif_queue_request(req)) {
  19.265 +		blk_requeue_request(rq, req);
  19.266          wait:
  19.267 -            di = req->rq_disk->private_data;
  19.268 -            if ( di->next_waiting == NULL )
  19.269 -            {
  19.270 -                di->next_waiting = head_waiting;
  19.271 -                head_waiting = di;
  19.272 -                /* Avoid pointless unplugs. */
  19.273 -                blk_stop_queue(rq);
  19.274 -            }
  19.275 -            break;
  19.276 +		/* Avoid pointless unplugs. */
  19.277 +		blk_stop_queue(rq);
  19.278 +		break;
  19.279          }
  19.280  
  19.281          queued++;
  19.282      }
  19.283  
  19.284      if ( queued != 0 )
  19.285 -        flush_requests();
  19.286 +        flush_requests(info);
  19.287  }
  19.288  
  19.289  
  19.290 @@ -347,25 +354,24 @@ static irqreturn_t blkif_int(int irq, vo
  19.291      struct request *req;
  19.292      blkif_response_t *bret;
  19.293      RING_IDX i, rp;
  19.294 -    unsigned long flags; 
  19.295 -    
  19.296 -    spin_lock_irqsave(&blkif_io_lock, flags);     
  19.297 +    unsigned long flags;
  19.298 +    struct blkfront_info *info = (struct blkfront_info *)dev_id;
  19.299  
  19.300 -    if ( unlikely(blkif_state == BLKIF_STATE_CLOSED) || 
  19.301 -         unlikely(recovery) )
  19.302 -    {
  19.303 +    spin_lock_irqsave(&blkif_io_lock, flags);
  19.304 +
  19.305 +    if (unlikely(info->connected != BLKIF_STATE_CONNECTED || recovery)) {
  19.306          spin_unlock_irqrestore(&blkif_io_lock, flags);
  19.307          return IRQ_HANDLED;
  19.308      }
  19.309 -    
  19.310 -    rp = blk_ring.sring->rsp_prod;
  19.311 +
  19.312 +    rp = info->ring.sring->rsp_prod;
  19.313      rmb(); /* Ensure we see queued responses up to 'rp'. */
  19.314  
  19.315 -    for ( i = blk_ring.rsp_cons; i != rp; i++ )
  19.316 +    for ( i = info->ring.rsp_cons; i != rp; i++ )
  19.317      {
  19.318          unsigned long id;
  19.319  
  19.320 -        bret = RING_GET_RESPONSE(&blk_ring, i);
  19.321 +        bret = RING_GET_RESPONSE(&info->ring, i);
  19.322          id   = bret->id;
  19.323          req  = (struct request *)blk_shadow[id].request;
  19.324  
  19.325 @@ -382,7 +388,7 @@ static irqreturn_t blkif_int(int irq, vo
  19.326                          bret->status);
  19.327  
  19.328              if ( unlikely(end_that_request_first
  19.329 -                          (req, 
  19.330 +                          (req,
  19.331                             (bret->status == BLKIF_RSP_OKAY),
  19.332                             req->hard_nr_sectors)) )
  19.333                  BUG();
  19.334 @@ -394,9 +400,9 @@ static irqreturn_t blkif_int(int irq, vo
  19.335          }
  19.336      }
  19.337  
  19.338 -    blk_ring.rsp_cons = i;
  19.339 +    info->ring.rsp_cons = i;
  19.340  
  19.341 -    kick_pending_request_queues();
  19.342 +    kick_pending_request_queues(info);
  19.343  
  19.344      spin_unlock_irqrestore(&blkif_io_lock, flags);
  19.345  
  19.346 @@ -425,31 +431,31 @@ static int nr_pending;
  19.347  static void kick_pending_request_queues(void)
  19.348  {
  19.349      /* We kick pending request queues if the ring is reasonably empty. */
  19.350 -    if ( (nr_pending != 0) && 
  19.351 -         (RING_PENDING_REQUESTS(&blk_ring) < (BLK_RING_SIZE >> 1)) )
  19.352 +    if ( (nr_pending != 0) &&
  19.353 +         (RING_PENDING_REQUESTS(&info->ring) < (BLK_RING_SIZE >> 1)) )
  19.354      {
  19.355          /* Attempt to drain the queue, but bail if the ring becomes full. */
  19.356 -        while ( (nr_pending != 0) && !RING_FULL(&blk_ring) )
  19.357 +        while ( (nr_pending != 0) && !RING_FULL(&info->ring) )
  19.358              do_blkif_request(pending_queues[--nr_pending]);
  19.359      }
  19.360  }
  19.361  
  19.362  int blkif_open(struct inode *inode, struct file *filep)
  19.363  {
  19.364 -    short xldev = inode->i_rdev; 
  19.365 +    short xldev = inode->i_rdev;
  19.366      struct gendisk *gd = get_gendisk(xldev);
  19.367      xl_disk_t *disk = xldev_to_xldisk(inode->i_rdev);
  19.368 -    short minor = MINOR(xldev); 
  19.369 +    short minor = MINOR(xldev);
  19.370  
  19.371      if ( gd->part[minor].nr_sects == 0 )
  19.372 -    { 
  19.373 +    {
  19.374          /*
  19.375           * Device either doesn't exist, or has zero capacity; we use a few
  19.376           * cheesy heuristics to return the relevant error code
  19.377           */
  19.378          if ( (gd->sizes[minor >> gd->minor_shift] != 0) ||
  19.379               ((minor & (gd->max_p - 1)) != 0) )
  19.380 -        { 
  19.381 +        {
  19.382              /*
  19.383               * We have a real device, but no such partition, or we just have a
  19.384               * partition number so guess this is the problem.
  19.385 @@ -458,16 +464,16 @@ int blkif_open(struct inode *inode, stru
  19.386          }
  19.387          else if ( gd->flags[minor >> gd->minor_shift] & GENHD_FL_REMOVABLE )
  19.388          {
  19.389 -            /* This is a removable device => assume that media is missing. */ 
  19.390 +            /* This is a removable device => assume that media is missing. */
  19.391              return -ENOMEDIUM; /* media not present (this is a guess) */
  19.392 -        } 
  19.393 +        }
  19.394          else
  19.395 -        { 
  19.396 +        {
  19.397              /* Just go for the general 'no such device' error. */
  19.398              return -ENODEV;    /* no such device */
  19.399          }
  19.400      }
  19.401 -    
  19.402 +
  19.403      /* Update of usage count is protected by per-device semaphore. */
  19.404      disk->usage++;
  19.405  
  19.406 @@ -496,24 +502,24 @@ int blkif_ioctl(struct inode *inode, str
  19.407  {
  19.408      kdev_t dev = inode->i_rdev;
  19.409      struct hd_geometry *geo = (struct hd_geometry *)argument;
  19.410 -    struct gendisk *gd;     
  19.411 -    struct hd_struct *part; 
  19.412 +    struct gendisk *gd;
  19.413 +    struct hd_struct *part;
  19.414      int i;
  19.415      unsigned short cylinders;
  19.416      byte heads, sectors;
  19.417  
  19.418      /* NB. No need to check permissions. That is done for us. */
  19.419 -    
  19.420 +
  19.421      DPRINTK_IOCTL("command: 0x%x, argument: 0x%lx, dev: 0x%04x\n",
  19.422 -                  command, (long) argument, dev); 
  19.423 -  
  19.424 +                  command, (long) argument, dev);
  19.425 +
  19.426      gd = get_gendisk(dev);
  19.427 -    part = &gd->part[MINOR(dev)]; 
  19.428 +    part = &gd->part[MINOR(dev)];
  19.429  
  19.430      switch ( command )
  19.431      {
  19.432      case BLKGETSIZE:
  19.433 -        DPRINTK_IOCTL("   BLKGETSIZE: %x %lx\n", BLKGETSIZE, part->nr_sects); 
  19.434 +        DPRINTK_IOCTL("   BLKGETSIZE: %x %lx\n", BLKGETSIZE, part->nr_sects);
  19.435          return put_user(part->nr_sects, (unsigned long *) argument);
  19.436  
  19.437      case BLKGETSIZE64:
  19.438 @@ -526,7 +532,7 @@ int blkif_ioctl(struct inode *inode, str
  19.439          return blkif_revalidate(dev);
  19.440  
  19.441      case BLKSSZGET:
  19.442 -        return hardsect_size[MAJOR(dev)][MINOR(dev)]; 
  19.443 +        return hardsect_size[MAJOR(dev)][MINOR(dev)];
  19.444  
  19.445      case BLKBSZGET:                                        /* get block size */
  19.446          DPRINTK_IOCTL("   BLKBSZGET: %x\n", BLKBSZGET);
  19.447 @@ -552,7 +558,7 @@ int blkif_ioctl(struct inode *inode, str
  19.448             values consistent with the size of the device */
  19.449  
  19.450          heads = 0xff;
  19.451 -        sectors = 0x3f; 
  19.452 +        sectors = 0x3f;
  19.453          cylinders = part->nr_sects / (heads * sectors);
  19.454  
  19.455          if (put_user(0x00,  (unsigned long *) &geo->start)) return -EFAULT;
  19.456 @@ -562,7 +568,7 @@ int blkif_ioctl(struct inode *inode, str
  19.457  
  19.458          return 0;
  19.459  
  19.460 -    case HDIO_GETGEO_BIG: 
  19.461 +    case HDIO_GETGEO_BIG:
  19.462          DPRINTK_IOCTL("   HDIO_GETGEO_BIG: %x\n", HDIO_GETGEO_BIG);
  19.463          if (!argument) return -EINVAL;
  19.464  
  19.465 @@ -570,7 +576,7 @@ int blkif_ioctl(struct inode *inode, str
  19.466             values consistent with the size of the device */
  19.467  
  19.468          heads = 0xff;
  19.469 -        sectors = 0x3f; 
  19.470 +        sectors = 0x3f;
  19.471          cylinders = part->nr_sects / (heads * sectors);
  19.472  
  19.473          if (put_user(0x00,  (unsigned long *) &geo->start))  return -EFAULT;
  19.474 @@ -594,7 +600,7 @@ int blkif_ioctl(struct inode *inode, str
  19.475          WPRINTK("ioctl %08x not supported by XL blkif\n", command);
  19.476          return -ENOSYS;
  19.477      }
  19.478 -    
  19.479 +
  19.480      return 0;
  19.481  }
  19.482  
  19.483 @@ -614,7 +620,7 @@ int blkif_revalidate(kdev_t dev)
  19.484      xl_disk_t *disk;
  19.485      unsigned long capacity;
  19.486      int i, rc = 0;
  19.487 -    
  19.488 +
  19.489      if ( (bd = bdget(dev)) == NULL )
  19.490          return -EINVAL;
  19.491  
  19.492 @@ -662,7 +668,7 @@ int blkif_revalidate(kdev_t dev)
  19.493  /*
  19.494   * blkif_queue_request
  19.495   *
  19.496 - * request block io 
  19.497 + * request block io
  19.498   * 
  19.499   * id: for guest use only.
  19.500   * operation: BLKIF_OP_{READ,WRITE,PROBE}
  19.501 @@ -696,7 +702,7 @@ static int blkif_queue_request(unsigned 
  19.502  
  19.503      buffer_ma &= PAGE_MASK;
  19.504  
  19.505 -    if ( unlikely(blkif_state != BLKIF_STATE_CONNECTED) )
  19.506 +    if (unlikely(info->connected != BLKIF_STATE_CONNECTED))
  19.507          return 1;
  19.508  
  19.509      switch ( operation )
  19.510 @@ -704,7 +710,7 @@ static int blkif_queue_request(unsigned 
  19.511  
  19.512      case BLKIF_OP_READ:
  19.513      case BLKIF_OP_WRITE:
  19.514 -        gd = get_gendisk(device); 
  19.515 +        gd = get_gendisk(device);
  19.516  
  19.517          /*
  19.518           * Update the sector_number we'll pass down as appropriate; note that
  19.519 @@ -714,10 +720,10 @@ static int blkif_queue_request(unsigned 
  19.520          sector_number += gd->part[MINOR(device)].start_sect;
  19.521  
  19.522          /*
  19.523 -         * If this unit doesn't consist of virtual partitions then we clear 
  19.524 +         * If this unit doesn't consist of virtual partitions then we clear
  19.525           * the partn bits from the device number.
  19.526           */
  19.527 -        if ( !(gd->flags[MINOR(device)>>gd->minor_shift] & 
  19.528 +        if ( !(gd->flags[MINOR(device)>>gd->minor_shift] &
  19.529                 GENHD_FL_VIRT_PARTNS) )
  19.530              device &= ~(gd->max_p - 1);
  19.531  
  19.532 @@ -725,20 +731,20 @@ static int blkif_queue_request(unsigned 
  19.533               (sg_dev == device) &&
  19.534               (sg_next_sect == sector_number) )
  19.535          {
  19.536 -            req = RING_GET_REQUEST(&blk_ring, 
  19.537 -                                   blk_ring.req_prod_pvt - 1);
  19.538 +            req = RING_GET_REQUEST(&info->ring,
  19.539 +                                   info->ring.req_prod_pvt - 1);
  19.540              bh = (struct buffer_head *)id;
  19.541 -     
  19.542 +
  19.543              bh->b_reqnext = (struct buffer_head *)blk_shadow[req->id].request;
  19.544              blk_shadow[req->id].request = (unsigned long)id;
  19.545  
  19.546              /* install a grant reference. */
  19.547 -            ref = gnttab_claim_grant_reference(&gref_head, gref_terminal);
  19.548 +            ref = gnttab_claim_grant_reference(&gref_head);
  19.549              ASSERT( ref != -ENOSPC );
  19.550  
  19.551              gnttab_grant_foreign_access_ref(
  19.552                          ref,
  19.553 -                        rdomid,
  19.554 +                        info->backend_id,
  19.555                          buffer_ma >> PAGE_SHIFT,
  19.556                          ( operation == BLKIF_OP_WRITE ? 1 : 0 ) );
  19.557  
  19.558 @@ -757,7 +763,7 @@ static int blkif_queue_request(unsigned 
  19.559  
  19.560              return 0;
  19.561          }
  19.562 -        else if ( RING_FULL(&blk_ring) )
  19.563 +        else if ( RING_FULL(&info->ring) )
  19.564          {
  19.565              return 1;
  19.566          }
  19.567 @@ -774,7 +780,7 @@ static int blkif_queue_request(unsigned 
  19.568      }
  19.569  
  19.570      /* Fill out a communications ring structure. */
  19.571 -    req = RING_GET_REQUEST(&blk_ring, blk_ring.req_prod_pvt);
  19.572 +    req = RING_GET_REQUEST(&info->ring, info->ring.req_prod_pvt);
  19.573  
  19.574      xid = GET_ID_FROM_FREELIST();
  19.575      blk_shadow[xid].request = (unsigned long)id;
  19.576 @@ -782,15 +788,15 @@ static int blkif_queue_request(unsigned 
  19.577      req->id            = xid;
  19.578      req->operation     = operation;
  19.579      req->sector_number = (blkif_sector_t)sector_number;
  19.580 -    req->handle        = handle; 
  19.581 +    req->handle        = handle;
  19.582      req->nr_segments   = 1;
  19.583      /* install a grant reference. */
  19.584 -    ref = gnttab_claim_grant_reference(&gref_head, gref_terminal);
  19.585 +    ref = gnttab_claim_grant_reference(&gref_head);
  19.586      ASSERT( ref != -ENOSPC );
  19.587  
  19.588      gnttab_grant_foreign_access_ref(
  19.589                  ref,
  19.590 -                rdomid,
  19.591 +                info->backend_id,
  19.592                  buffer_ma >> PAGE_SHIFT,
  19.593                  ( operation == BLKIF_OP_WRITE ? 1 : 0 ) );
  19.594  
  19.595 @@ -798,11 +804,11 @@ static int blkif_queue_request(unsigned 
  19.596  
  19.597      req->frame_and_sects[0] = blkif_fas_from_gref(ref, fsect, lsect);
  19.598  
  19.599 -    /* Keep a private copy so we can reissue requests when recovering. */    
  19.600 +    /* Keep a private copy so we can reissue requests when recovering. */
  19.601      pickle_request(&blk_shadow[xid], req);
  19.602  
  19.603 -    blk_ring.req_prod_pvt++;
  19.604 -    
  19.605 +    info->ring.req_prod_pvt++;
  19.606 +
  19.607      return 0;
  19.608  }
  19.609  
  19.610 @@ -817,13 +823,13 @@ void do_blkif_request(request_queue_t *r
  19.611      struct buffer_head *bh, *next_bh;
  19.612      int rw, nsect, full, queued = 0;
  19.613  
  19.614 -    DPRINTK("Entered do_blkif_request\n"); 
  19.615 +    DPRINTK("Entered do_blkif_request\n");
  19.616  
  19.617      while ( !rq->plugged && !list_empty(&rq->queue_head))
  19.618      {
  19.619 -        if ( (req = blkdev_entry_next_request(&rq->queue_head)) == NULL ) 
  19.620 +        if ( (req = blkdev_entry_next_request(&rq->queue_head)) == NULL )
  19.621              goto out;
  19.622 -  
  19.623 +
  19.624          DPRINTK("do_blkif_request %p: cmd %i, sec %lx, (%li/%li) bh:%p\n",
  19.625                  req, req->cmd, req->sector,
  19.626                  req->current_nr_sectors, req->nr_sectors, req->bh);
  19.627 @@ -844,16 +850,16 @@ void do_blkif_request(request_queue_t *r
  19.628  
  19.629              full = blkif_queue_request(
  19.630                  (unsigned long)bh,
  19.631 -                (rw == READ) ? BLKIF_OP_READ : BLKIF_OP_WRITE, 
  19.632 +                (rw == READ) ? BLKIF_OP_READ : BLKIF_OP_WRITE,
  19.633                  bh->b_data, bh->b_rsector, bh->b_size>>9, bh->b_rdev);
  19.634  
  19.635              if ( full )
  19.636 -            { 
  19.637 +            {
  19.638                  bh->b_reqnext = next_bh;
  19.639                  pending_queues[nr_pending++] = rq;
  19.640                  if ( unlikely(nr_pending >= MAX_PENDING) )
  19.641                      BUG();
  19.642 -                goto out; 
  19.643 +                goto out;
  19.644              }
  19.645  
  19.646              queued++;
  19.647 @@ -861,7 +867,7 @@ void do_blkif_request(request_queue_t *r
  19.648              /* Dequeue the buffer head from the request. */
  19.649              nsect = bh->b_size >> 9;
  19.650              bh = req->bh = next_bh;
  19.651 -            
  19.652 +
  19.653              if ( bh != NULL )
  19.654              {
  19.655                  /* There's another buffer head to do. Update the request. */
  19.656 @@ -891,27 +897,27 @@ void do_blkif_request(request_queue_t *r
  19.657  
  19.658  static void blkif_int(int irq, void *dev_id, struct pt_regs *ptregs)
  19.659  {
  19.660 -    RING_IDX i, rp; 
  19.661 -    unsigned long flags; 
  19.662 +    RING_IDX i, rp;
  19.663 +    unsigned long flags;
  19.664      struct buffer_head *bh, *next_bh;
  19.665 -    
  19.666 -    spin_lock_irqsave(&io_request_lock, flags);     
  19.667  
  19.668 -    if ( unlikely(blkif_state == BLKIF_STATE_CLOSED || recovery) )
  19.669 +    spin_lock_irqsave(&io_request_lock, flags);
  19.670 +
  19.671 +    if ( unlikely(info->connected != BLKIF_STATE_CONNECTED || recovery) )
  19.672      {
  19.673          spin_unlock_irqrestore(&io_request_lock, flags);
  19.674          return;
  19.675      }
  19.676  
  19.677 -    rp = blk_ring.sring->rsp_prod;
  19.678 +    rp = info->ring.sring->rsp_prod;
  19.679      rmb(); /* Ensure we see queued responses up to 'rp'. */
  19.680  
  19.681 -    for ( i = blk_ring.rsp_cons; i != rp; i++ )
  19.682 +    for ( i = info->ring.rsp_cons; i != rp; i++ )
  19.683      {
  19.684          unsigned long id;
  19.685          blkif_response_t *bret;
  19.686 -        
  19.687 -        bret = RING_GET_RESPONSE(&blk_ring, i);
  19.688 +
  19.689 +        bret = RING_GET_RESPONSE(&info->ring, i);
  19.690          id = bret->id;
  19.691          bh = (struct buffer_head *)blk_shadow[id].request;
  19.692  
  19.693 @@ -943,8 +949,8 @@ static void blkif_int(int irq, void *dev
  19.694          }
  19.695  
  19.696      }
  19.697 -    blk_ring.rsp_cons = i;
  19.698 -    
  19.699 +    info->ring.rsp_cons = i;
  19.700 +
  19.701      kick_pending_request_queues();
  19.702  
  19.703      spin_unlock_irqrestore(&io_request_lock, flags);
  19.704 @@ -954,24 +960,24 @@ static void blkif_int(int irq, void *dev
  19.705  
  19.706  /*****************************  COMMON CODE  *******************************/
  19.707  
  19.708 -static void blkif_free(void)
  19.709 +static void blkif_free(struct blkfront_info *info)
  19.710  {
  19.711      /* Prevent new requests being issued until we fix things up. */
  19.712      spin_lock_irq(&blkif_io_lock);
  19.713 -    blkif_state = BLKIF_STATE_DISCONNECTED;
  19.714 +    info->connected = BLKIF_STATE_DISCONNECTED;
  19.715      spin_unlock_irq(&blkif_io_lock);
  19.716  
  19.717      /* Free resources associated with old device channel. */
  19.718 -    if ( blk_ring.sring != NULL )
  19.719 +    if ( info->ring.sring != NULL )
  19.720      {
  19.721 -        free_page((unsigned long)blk_ring.sring);
  19.722 -        blk_ring.sring = NULL;
  19.723 +        free_page((unsigned long)info->ring.sring);
  19.724 +        info->ring.sring = NULL;
  19.725      }
  19.726 -    unbind_evtchn_from_irqhandler(blkif_evtchn, NULL);
  19.727 -    blkif_evtchn = 0;
  19.728 +    unbind_evtchn_from_irqhandler(info->evtchn, NULL);
  19.729 +    info->evtchn = 0;
  19.730  }
  19.731  
  19.732 -static void blkif_recover(void)
  19.733 +static void blkif_recover(struct blkfront_info *info)
  19.734  {
  19.735      int i;
  19.736      blkif_request_t *req;
  19.737 @@ -987,7 +993,7 @@ static void blkif_recover(void)
  19.738      memset(&blk_shadow, 0, sizeof(blk_shadow));
  19.739      for ( i = 0; i < BLK_RING_SIZE; i++ )
  19.740          blk_shadow[i].req.id = i+1;
  19.741 -    blk_shadow_free = blk_ring.req_prod_pvt;
  19.742 +    blk_shadow_free = info->ring.req_prod_pvt;
  19.743      blk_shadow[BLK_RING_SIZE-1].req.id = 0x0fffffff;
  19.744  
  19.745      /* Stage 3: Find pending requests and requeue them. */
  19.746 @@ -999,7 +1005,7 @@ static void blkif_recover(void)
  19.747  
  19.748          /* Grab a request slot and unpickle shadow state into it. */
  19.749          req = RING_GET_REQUEST(
  19.750 -            &blk_ring, blk_ring.req_prod_pvt);
  19.751 +            &info->ring, info->ring.req_prod_pvt);
  19.752          unpickle_request(req, &copy[i]);
  19.753  
  19.754          /* We get a new request id, and must reset the shadow state. */
  19.755 @@ -1012,7 +1018,7 @@ static void blkif_recover(void)
  19.756              if ( req->frame_and_sects[j] & GRANTREF_INVALID )
  19.757                  gnttab_grant_foreign_access_ref(
  19.758                      blkif_gref_from_fas(req->frame_and_sects[j]),
  19.759 -                    rdomid,
  19.760 +                    info->backend_id,
  19.761                      blk_shadow[req->id].frame[j],
  19.762                      rq_data_dir((struct request *)
  19.763                                  blk_shadow[req->id].request));
  19.764 @@ -1020,32 +1026,31 @@ static void blkif_recover(void)
  19.765          }
  19.766          blk_shadow[req->id].req = *req;
  19.767  
  19.768 -        blk_ring.req_prod_pvt++;
  19.769 +        info->ring.req_prod_pvt++;
  19.770      }
  19.771  
  19.772      kfree(copy);
  19.773  
  19.774      recovery = 0;
  19.775  
  19.776 -    /* blk_ring->req_prod will be set when we flush_requests().*/
  19.777 +    /* info->ring->req_prod will be set when we flush_requests().*/
  19.778      wmb();
  19.779  
  19.780      /* Kicks things back into life. */
  19.781 -    flush_requests();
  19.782 +    flush_requests(info);
  19.783  
  19.784      /* Now safe to left other people use the interface. */
  19.785 -    blkif_state = BLKIF_STATE_CONNECTED;
  19.786 +    info->connected = BLKIF_STATE_CONNECTED;
  19.787  }
  19.788  
  19.789 -static void blkif_connect(u16 evtchn, domid_t domid)
  19.790 +static void blkif_connect(struct blkfront_info *info, u16 evtchn)
  19.791  {
  19.792      int err = 0;
  19.793  
  19.794 -    blkif_evtchn = evtchn;
  19.795 -    rdomid       = domid;
  19.796 +    info->evtchn = evtchn;
  19.797  
  19.798      err = bind_evtchn_to_irqhandler(
  19.799 -        blkif_evtchn, blkif_int, SA_SAMPLE_RANDOM, "blkif", NULL);
  19.800 +        info->evtchn, blkif_int, SA_SAMPLE_RANDOM, "blkif", info);
  19.801      if ( err != 0 )
  19.802      {
  19.803          WPRINTK("bind_evtchn_to_irqhandler failed (err=%d)\n", err);
  19.804 @@ -1059,17 +1064,6 @@ static struct xenbus_device_id blkfront_
  19.805  	{ "" }
  19.806  };
  19.807  
  19.808 -struct blkfront_info
  19.809 -{
  19.810 -	/* We watch the backend */
  19.811 -	struct xenbus_watch watch;
  19.812 -	int vdevice;
  19.813 -	u16 handle;
  19.814 -	int connected;
  19.815 -	struct xenbus_device *dev;
  19.816 -	char *backend;
  19.817 -};
  19.818 -
  19.819  static void watch_for_status(struct xenbus_watch *watch, const char *node)
  19.820  {
  19.821  	struct blkfront_info *info;
  19.822 @@ -1081,35 +1075,33 @@ static void watch_for_status(struct xenb
  19.823  	node += strlen(watch->node);
  19.824  
  19.825  	/* FIXME: clean up when error on the other end. */
  19.826 -	if (info->connected)
  19.827 +	if (info->connected == BLKIF_STATE_CONNECTED)
  19.828  		return;
  19.829  
  19.830 -	err = xenbus_gather(watch->node, 
  19.831 +	err = xenbus_gather(watch->node,
  19.832  			    "sectors", "%lu", &sectors,
  19.833  			    "info", "%u", &binfo,
  19.834  			    "sector-size", "%lu", &sector_size,
  19.835  			    NULL);
  19.836  	if (err) {
  19.837 -		xenbus_dev_error(info->dev, err, "reading backend fields");
  19.838 +		xenbus_dev_error(info->xbdev, err, "reading backend fields");
  19.839  		return;
  19.840  	}
  19.841  
  19.842 -	xlvbd_add(sectors, info->vdevice, info->handle, binfo, sector_size);
  19.843 -	info->connected = 1;
  19.844 +	xlvbd_add(sectors, info->vdevice, binfo, sector_size, info);
  19.845 +	info->connected = BLKIF_STATE_CONNECTED;
  19.846  
  19.847 -	/* First to connect?  blkif is now connected. */
  19.848 -	if (blkif_vbds_connected++ == 0)
  19.849 -		blkif_state = BLKIF_STATE_CONNECTED;
  19.850 +	blkif_state = BLKIF_STATE_CONNECTED;
  19.851  
  19.852 -	xenbus_dev_ok(info->dev);
  19.853 +	xenbus_dev_ok(info->xbdev);
  19.854  
  19.855  	/* Kick pending requests. */
  19.856  	spin_lock_irq(&blkif_io_lock);
  19.857 -	kick_pending_request_queues();
  19.858 +	kick_pending_request_queues(info);
  19.859  	spin_unlock_irq(&blkif_io_lock);
  19.860  }
  19.861  
  19.862 -static int setup_blkring(struct xenbus_device *dev, unsigned int backend_id)
  19.863 +static int setup_blkring(struct xenbus_device *dev, struct blkfront_info *info)
  19.864  {
  19.865  	blkif_sring_t *sring;
  19.866  	evtchn_op_t op = { .cmd = EVTCHNOP_alloc_unbound };
  19.867 @@ -1121,25 +1113,28 @@ static int setup_blkring(struct xenbus_d
  19.868  		return -ENOMEM;
  19.869  	}
  19.870  	SHARED_RING_INIT(sring);
  19.871 -	FRONT_RING_INIT(&blk_ring, sring, PAGE_SIZE);
  19.872 +	FRONT_RING_INIT(&info->ring, sring, PAGE_SIZE);
  19.873  
  19.874 -	shmem_ref = gnttab_claim_grant_reference(&gref_head,
  19.875 -						 gref_terminal);
  19.876 -	ASSERT(shmem_ref != -ENOSPC);
  19.877 -	gnttab_grant_foreign_access_ref(shmem_ref,
  19.878 -					backend_id,
  19.879 -					virt_to_mfn(blk_ring.sring),
  19.880 -					0);
  19.881 +	err = gnttab_grant_foreign_access(info->backend_id,
  19.882 +					  virt_to_mfn(info->ring.sring), 0);
  19.883 +	if (err == -ENOSPC) {
  19.884 +		free_page((unsigned long)info->ring.sring);
  19.885 +		info->ring.sring = 0;
  19.886 +		xenbus_dev_error(dev, err, "granting access to ring page");
  19.887 +		return err;
  19.888 +	}
  19.889 +	info->grant_id = err;
  19.890  
  19.891 -	op.u.alloc_unbound.dom = backend_id;
  19.892 +	op.u.alloc_unbound.dom = info->backend_id;
  19.893  	err = HYPERVISOR_event_channel_op(&op);
  19.894  	if (err) {
  19.895 -		free_page((unsigned long)blk_ring.sring);
  19.896 -		blk_ring.sring = 0;
  19.897 +		gnttab_end_foreign_access(info->grant_id, 0);
  19.898 +		free_page((unsigned long)info->ring.sring);
  19.899 +		info->ring.sring = 0;
  19.900  		xenbus_dev_error(dev, err, "allocating event channel");
  19.901  		return err;
  19.902  	}
  19.903 -	blkif_connect(op.u.alloc_unbound.port, backend_id);
  19.904 +	blkif_connect(info, op.u.alloc_unbound.port);
  19.905  	return 0;
  19.906  }
  19.907  
  19.908 @@ -1149,11 +1144,11 @@ static int talk_to_backend(struct xenbus
  19.909  {
  19.910  	char *backend;
  19.911  	const char *message;
  19.912 -	int err, backend_id;
  19.913 +	int err;
  19.914  
  19.915  	backend = NULL;
  19.916  	err = xenbus_gather(dev->nodename,
  19.917 -			    "backend-id", "%i", &backend_id,
  19.918 +			    "backend-id", "%i", &info->backend_id,
  19.919  			    "backend", NULL, &backend,
  19.920  			    NULL);
  19.921  	if (XENBUS_EXIST_ERR(err))
  19.922 @@ -1168,12 +1163,10 @@ static int talk_to_backend(struct xenbus
  19.923  		goto out;
  19.924  	}
  19.925  
  19.926 -	/* First device?  We create shared ring, alloc event channel. */
  19.927 -	if (blkif_vbds == 0) {
  19.928 -		err = setup_blkring(dev, backend_id);
  19.929 -		if (err)
  19.930 -			goto out;
  19.931 -	}
  19.932 +	/* Create shared ring, alloc event channel. */
  19.933 +	err = setup_blkring(dev, info);
  19.934 +	if (err)
  19.935 +		goto out;
  19.936  
  19.937  	err = xenbus_transaction_start(dev->nodename);
  19.938  	if (err) {
  19.939 @@ -1181,13 +1174,13 @@ static int talk_to_backend(struct xenbus
  19.940  		goto destroy_blkring;
  19.941  	}
  19.942  
  19.943 -	err = xenbus_printf(dev->nodename, "grant-id","%u", shmem_ref);
  19.944 +	err = xenbus_printf(dev->nodename, "grant-id","%u", info->grant_id);
  19.945  	if (err) {
  19.946  		message = "writing grant-id";
  19.947  		goto abort_transaction;
  19.948  	}
  19.949  	err = xenbus_printf(dev->nodename,
  19.950 -			    "event-channel", "%u", blkif_evtchn);
  19.951 +			    "event-channel", "%u", info->evtchn);
  19.952  	if (err) {
  19.953  		message = "writing event-channel";
  19.954  		goto abort_transaction;
  19.955 @@ -1220,8 +1213,7 @@ static int talk_to_backend(struct xenbus
  19.956  	/* Have to do this *outside* transaction.  */
  19.957  	xenbus_dev_error(dev, err, "%s", message);
  19.958   destroy_blkring:
  19.959 -	if (blkif_vbds == 0)
  19.960 -		blkif_free();
  19.961 +	blkif_free(info);
  19.962  	goto out;
  19.963  }
  19.964  
  19.965 @@ -1250,9 +1242,11 @@ static int blkfront_probe(struct xenbus_
  19.966  		xenbus_dev_error(dev, err, "allocating info structure");
  19.967  		return err;
  19.968  	}
  19.969 -	info->dev = dev;
  19.970 +	info->xbdev = dev;
  19.971  	info->vdevice = vdevice;
  19.972 -	info->connected = 0;
  19.973 +	info->connected = BLKIF_STATE_DISCONNECTED;
  19.974 +	info->mi = NULL;
  19.975 +	INIT_WORK(&info->work, blkif_restart_queue, (void *)info);
  19.976  
  19.977  	/* Front end dir is a number, which is used as the id. */
  19.978  	info->handle = simple_strtoul(strrchr(dev->nodename,'/')+1, NULL, 0);
  19.979 @@ -1266,7 +1260,6 @@ static int blkfront_probe(struct xenbus_
  19.980  
  19.981  	/* Call once in case entries already there. */
  19.982  	watch_for_status(&info->watch, info->watch.node);
  19.983 -	blkif_vbds++;
  19.984  	return 0;
  19.985  }
  19.986  
  19.987 @@ -1277,16 +1270,14 @@ static int blkfront_remove(struct xenbus
  19.988  	if (info->backend)
  19.989  		unregister_xenbus_watch(&info->watch);
  19.990  
  19.991 -	if (info->connected) {
  19.992 -		xlvbd_del(info->handle);
  19.993 -		blkif_vbds_connected--;
  19.994 -	}
  19.995 +	if (info->mi)
  19.996 +		xlvbd_del(info);
  19.997 +
  19.998 +	blkif_free(info);
  19.999 +
 19.1000  	kfree(info->backend);
 19.1001  	kfree(info);
 19.1002  
 19.1003 -	if (--blkif_vbds == 0)
 19.1004 -		blkif_free();
 19.1005 -
 19.1006  	return 0;
 19.1007  }
 19.1008  
 19.1009 @@ -1298,10 +1289,8 @@ static int blkfront_suspend(struct xenbu
 19.1010  	kfree(info->backend);
 19.1011  	info->backend = NULL;
 19.1012  
 19.1013 -	if (--blkif_vbds == 0) {
 19.1014 -		recovery = 1;
 19.1015 -		blkif_free();
 19.1016 -	}
 19.1017 +	recovery = 1;
 19.1018 +	blkif_free(info);
 19.1019  
 19.1020  	return 0;
 19.1021  }
 19.1022 @@ -1314,8 +1303,7 @@ static int blkfront_resume(struct xenbus
 19.1023  	/* FIXME: Check geometry hasn't changed here... */
 19.1024  	err = talk_to_backend(dev, info);
 19.1025  	if (!err) {
 19.1026 -		if (blkif_vbds++ == 0)
 19.1027 -			blkif_recover();
 19.1028 +		blkif_recover(info);
 19.1029  	}
 19.1030  	return err;
 19.1031  }
 19.1032 @@ -1363,11 +1351,6 @@ static int __init xlblk_init(void)
 19.1033  {
 19.1034      int i;
 19.1035  
 19.1036 -    /* A grant for every ring slot, plus one for the ring itself. */
 19.1037 -    if (gnttab_alloc_grant_references(MAXIMUM_OUTSTANDING_BLOCK_REQS + 1,
 19.1038 -				      &gref_head, &gref_terminal) < 0)
 19.1039 -        return 1;
 19.1040 -
 19.1041      if ( (xen_start_info.flags & SIF_INITDOMAIN) ||
 19.1042           (xen_start_info.flags & SIF_BLK_BE_DOMAIN) )
 19.1043          return 0;
 19.1044 @@ -1391,6 +1374,6 @@ static void blkif_completion(struct blk_
 19.1045  {
 19.1046      int i;
 19.1047      for ( i = 0; i < s->req.nr_segments; i++ )
 19.1048 -        gnttab_release_grant_reference(
 19.1049 -            &gref_head, blkif_gref_from_fas(s->req.frame_and_sects[i]));
 19.1050 +        gnttab_free_grant_reference(
 19.1051 +		blkif_gref_from_fas(s->req.frame_and_sects[i]));
 19.1052  }
    20.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/block.h	Tue Aug 23 18:25:51 2005 +0000
    20.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/block.h	Tue Aug 23 18:27:22 2005 +0000
    20.3 @@ -46,6 +46,7 @@
    20.4  #include <linux/major.h>
    20.5  #include <linux/devfs_fs_kernel.h>
    20.6  #include <asm-xen/hypervisor.h>
    20.7 +#include <asm-xen/xenbus.h>
    20.8  #include <asm-xen/xen-public/xen.h>
    20.9  #include <asm-xen/xen-public/io/blkif.h>
   20.10  #include <asm-xen/xen-public/io/ring.h>
   20.11 @@ -79,11 +80,20 @@
   20.12  #define DPRINTK_IOCTL(_f, _a...) ((void)0)
   20.13  #endif
   20.14  
   20.15 -struct xlbd_type_info {
   20.16 -    int partn_shift;
   20.17 -    int disks_per_major;
   20.18 -    char *devname;
   20.19 -    char *diskname;
   20.20 +struct xlbd_type_info
   20.21 +{
   20.22 +	int partn_shift;
   20.23 +	int disks_per_major;
   20.24 +	char *devname;
   20.25 +	char *diskname;
   20.26 +};
   20.27 +
   20.28 +struct xlbd_major_info
   20.29 +{
   20.30 +	int major;
   20.31 +	int index;
   20.32 +	int usage;
   20.33 +	struct xlbd_type_info *type;
   20.34  };
   20.35  
   20.36  /*
   20.37 @@ -91,27 +101,28 @@ struct xlbd_type_info {
   20.38   * hang in private_data off the gendisk structure. We may end up
   20.39   * putting all kinds of interesting stuff here :-)
   20.40   */
   20.41 -struct xlbd_major_info {
   20.42 -    int major;
   20.43 -    int index;
   20.44 -    int usage;
   20.45 -    struct xlbd_type_info *type;
   20.46 +struct blkfront_info
   20.47 +{
   20.48 +	struct xenbus_device *xbdev;
   20.49 +	/* We watch the backend */
   20.50 +	struct xenbus_watch watch;
   20.51 +	dev_t dev;
   20.52 +	int vdevice;
   20.53 +	blkif_vdev_t handle;
   20.54 +	int connected;
   20.55 +	char *backend;
   20.56 +	int backend_id;
   20.57 +	int grant_id;
   20.58 +	blkif_front_ring_t ring;
   20.59 +	unsigned int evtchn;
   20.60 +	struct xlbd_major_info *mi;
   20.61 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
   20.62 +	request_queue_t *rq;
   20.63 +#endif
   20.64 +	struct work_struct work;
   20.65 +	struct gnttab_free_callback callback;
   20.66  };
   20.67  
   20.68 -struct xlbd_disk_info {
   20.69 -    int xd_device;
   20.70 -    blkif_vdev_t handle;
   20.71 -    struct xlbd_major_info *mi;
   20.72 -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
   20.73 -    struct xlbd_disk_info  *next_waiting;
   20.74 -    request_queue_t        *rq;
   20.75 -#endif
   20.76 -};
   20.77 -
   20.78 -typedef struct xen_block {
   20.79 -    int usage;
   20.80 -} xen_block_t;
   20.81 -
   20.82  extern spinlock_t blkif_io_lock;
   20.83  
   20.84  extern int blkif_open(struct inode *inode, struct file *filep);
   20.85 @@ -123,7 +134,7 @@ extern int blkif_revalidate(dev_t dev);
   20.86  extern void do_blkif_request (request_queue_t *rq); 
   20.87  
   20.88  /* Virtual block-device subsystem. */
   20.89 -int xlvbd_add(blkif_sector_t capacity, int device, blkif_vdev_t handle,
   20.90 -	      u16 info, u16 sector_size);
   20.91 -void xlvbd_del(blkif_vdev_t handle);
   20.92 +int xlvbd_add(blkif_sector_t capacity, int device,
   20.93 +	      u16 vdisk_info, u16 sector_size, struct blkfront_info *info);
   20.94 +void xlvbd_del(struct blkfront_info *info);
   20.95  #endif /* __XEN_DRIVERS_BLOCK_H__ */
    21.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c	Tue Aug 23 18:25:51 2005 +0000
    21.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c	Tue Aug 23 18:27:22 2005 +0000
    21.3 @@ -43,325 +43,269 @@
    21.4  #define NUM_SCSI_MAJORS 9
    21.5  #define NUM_VBD_MAJORS 1
    21.6  
    21.7 -struct lvdisk
    21.8 -{
    21.9 -    blkif_sector_t capacity; /*  0: Size in terms of 512-byte sectors.   */
   21.10 -    blkif_vdev_t   handle;   /*  8: Device number (opaque 16 bit value). */
   21.11 -    u16            info;
   21.12 -    dev_t          dev;
   21.13 -    struct list_head list;
   21.14 -};
   21.15 -
   21.16  static struct xlbd_type_info xlbd_ide_type = {
   21.17 -    .partn_shift = 6,
   21.18 -    .disks_per_major = 2,
   21.19 -    .devname = "ide",
   21.20 -    .diskname = "hd",
   21.21 +	.partn_shift = 6,
   21.22 +	.disks_per_major = 2,
   21.23 +	.devname = "ide",
   21.24 +	.diskname = "hd",
   21.25  };
   21.26  
   21.27  static struct xlbd_type_info xlbd_scsi_type = {
   21.28 -    .partn_shift = 4,
   21.29 -    .disks_per_major = 16,
   21.30 -    .devname = "sd",
   21.31 -    .diskname = "sd",
   21.32 +	.partn_shift = 4,
   21.33 +	.disks_per_major = 16,
   21.34 +	.devname = "sd",
   21.35 +	.diskname = "sd",
   21.36  };
   21.37  
   21.38  static struct xlbd_type_info xlbd_vbd_type = {
   21.39 -    .partn_shift = 4,
   21.40 -    .disks_per_major = 16,
   21.41 -    .devname = "xvd",
   21.42 -    .diskname = "xvd",
   21.43 +	.partn_shift = 4,
   21.44 +	.disks_per_major = 16,
   21.45 +	.devname = "xvd",
   21.46 +	.diskname = "xvd",
   21.47  };
   21.48  
   21.49  static struct xlbd_major_info *major_info[NUM_IDE_MAJORS + NUM_SCSI_MAJORS +
   21.50 -                                         NUM_VBD_MAJORS];
   21.51 +					  NUM_VBD_MAJORS];
   21.52  
   21.53 -#define XLBD_MAJOR_IDE_START    0
   21.54 -#define XLBD_MAJOR_SCSI_START   (NUM_IDE_MAJORS)
   21.55 -#define XLBD_MAJOR_VBD_START    (NUM_IDE_MAJORS + NUM_SCSI_MAJORS)
   21.56 +#define XLBD_MAJOR_IDE_START	0
   21.57 +#define XLBD_MAJOR_SCSI_START	(NUM_IDE_MAJORS)
   21.58 +#define XLBD_MAJOR_VBD_START	(NUM_IDE_MAJORS + NUM_SCSI_MAJORS)
   21.59  
   21.60 -#define XLBD_MAJOR_IDE_RANGE    XLBD_MAJOR_IDE_START ... XLBD_MAJOR_SCSI_START - 1
   21.61 -#define XLBD_MAJOR_SCSI_RANGE   XLBD_MAJOR_SCSI_START ... XLBD_MAJOR_VBD_START - 1
   21.62 -#define XLBD_MAJOR_VBD_RANGE    XLBD_MAJOR_VBD_START ... XLBD_MAJOR_VBD_START + NUM_VBD_MAJORS - 1
   21.63 +#define XLBD_MAJOR_IDE_RANGE	XLBD_MAJOR_IDE_START ... XLBD_MAJOR_SCSI_START - 1
   21.64 +#define XLBD_MAJOR_SCSI_RANGE	XLBD_MAJOR_SCSI_START ... XLBD_MAJOR_VBD_START - 1
   21.65 +#define XLBD_MAJOR_VBD_RANGE	XLBD_MAJOR_VBD_START ... XLBD_MAJOR_VBD_START + NUM_VBD_MAJORS - 1
   21.66  
   21.67  /* Information about our VBDs. */
   21.68  #define MAX_VBDS 64
   21.69  static LIST_HEAD(vbds_list);
   21.70  
   21.71 -#define MAJOR_XEN(dev) ((dev)>>8)
   21.72 -#define MINOR_XEN(dev) ((dev) & 0xff)
   21.73 -
   21.74 -static struct block_device_operations xlvbd_block_fops = 
   21.75 +static struct block_device_operations xlvbd_block_fops =
   21.76  {
   21.77 -    .owner  = THIS_MODULE,
   21.78 -    .open  = blkif_open,
   21.79 -    .release = blkif_release,
   21.80 -    .ioctl  = blkif_ioctl,
   21.81 +	.owner = THIS_MODULE,
   21.82 +	.open = blkif_open,
   21.83 +	.release = blkif_release,
   21.84 +	.ioctl  = blkif_ioctl,
   21.85  };
   21.86  
   21.87  spinlock_t blkif_io_lock = SPIN_LOCK_UNLOCKED;
   21.88  
   21.89 -static struct lvdisk *xlvbd_device_alloc(void)
   21.90 -{
   21.91 -    struct lvdisk *disk;
   21.92 -
   21.93 -    disk = kmalloc(sizeof(*disk), GFP_KERNEL);
   21.94 -    if (disk != NULL) {
   21.95 -        memset(disk, 0, sizeof(*disk));
   21.96 -        INIT_LIST_HEAD(&disk->list);
   21.97 -    }
   21.98 -    return disk;
   21.99 -}
  21.100 -
  21.101 -static void xlvbd_device_free(struct lvdisk *disk)
  21.102 -{
  21.103 -    list_del(&disk->list);
  21.104 -    kfree(disk);
  21.105 -}
  21.106 -
  21.107 -static struct xlbd_major_info *xlbd_alloc_major_info(
  21.108 -    int major, int minor, int index)
  21.109 +static struct xlbd_major_info *
  21.110 +xlbd_alloc_major_info(int major, int minor, int index)
  21.111  {
  21.112 -    struct xlbd_major_info *ptr;
  21.113 -
  21.114 -    ptr = kmalloc(sizeof(struct xlbd_major_info), GFP_KERNEL);
  21.115 -    if (ptr == NULL)
  21.116 -        return NULL;
  21.117 -
  21.118 -    memset(ptr, 0, sizeof(struct xlbd_major_info));
  21.119 -
  21.120 -    ptr->major = major;
  21.121 -
  21.122 -    switch (index) {
  21.123 -    case XLBD_MAJOR_IDE_RANGE:
  21.124 -        ptr->type = &xlbd_ide_type;
  21.125 -        ptr->index = index - XLBD_MAJOR_IDE_START;
  21.126 -        break;
  21.127 -    case XLBD_MAJOR_SCSI_RANGE:
  21.128 -        ptr->type = &xlbd_scsi_type;
  21.129 -        ptr->index = index - XLBD_MAJOR_SCSI_START;
  21.130 -        break;
  21.131 -    case XLBD_MAJOR_VBD_RANGE:
  21.132 -        ptr->type = &xlbd_vbd_type;
  21.133 -        ptr->index = index - XLBD_MAJOR_VBD_START;
  21.134 -        break;
  21.135 -    }
  21.136 -    
  21.137 -    printk("Registering block device major %i\n", ptr->major);
  21.138 -    if (register_blkdev(ptr->major, ptr->type->devname)) {
  21.139 -        WPRINTK("can't get major %d with name %s\n",
  21.140 -                ptr->major, ptr->type->devname);
  21.141 -        kfree(ptr);
  21.142 -        return NULL;
  21.143 -    }
  21.144 +	struct xlbd_major_info *ptr;
  21.145  
  21.146 -    devfs_mk_dir(ptr->type->devname);
  21.147 -    major_info[index] = ptr;
  21.148 -    return ptr;
  21.149 -}
  21.150 -
  21.151 -static struct xlbd_major_info *xlbd_get_major_info(int device)
  21.152 -{
  21.153 -    int major, minor, index;
  21.154 -
  21.155 -    major = MAJOR_XEN(device);
  21.156 -    minor = MINOR_XEN(device);
  21.157 -
  21.158 -    switch (major) {
  21.159 -    case IDE0_MAJOR: index = 0; break;
  21.160 -    case IDE1_MAJOR: index = 1; break;
  21.161 -    case IDE2_MAJOR: index = 2; break;
  21.162 -    case IDE3_MAJOR: index = 3; break;
  21.163 -    case IDE4_MAJOR: index = 4; break;
  21.164 -    case IDE5_MAJOR: index = 5; break;
  21.165 -    case IDE6_MAJOR: index = 6; break;
  21.166 -    case IDE7_MAJOR: index = 7; break;
  21.167 -    case IDE8_MAJOR: index = 8; break;
  21.168 -    case IDE9_MAJOR: index = 9; break;
  21.169 -    case SCSI_DISK0_MAJOR: index = 10; break;
  21.170 -    case SCSI_DISK1_MAJOR ... SCSI_DISK7_MAJOR:
  21.171 -        index = 11 + major - SCSI_DISK1_MAJOR;
  21.172 -        break;
  21.173 -    case SCSI_CDROM_MAJOR: index = 18; break;
  21.174 -    default: index = 19; break;
  21.175 -    }
  21.176 +	ptr = kmalloc(sizeof(struct xlbd_major_info), GFP_KERNEL);
  21.177 +	if (ptr == NULL)
  21.178 +		return NULL;
  21.179  
  21.180 -    return ((major_info[index] != NULL) ? major_info[index] :
  21.181 -            xlbd_alloc_major_info(major, minor, index));
  21.182 -}
  21.183 -
  21.184 -static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size)
  21.185 -{
  21.186 -    request_queue_t *rq;
  21.187 -
  21.188 -    rq = blk_init_queue(do_blkif_request, &blkif_io_lock);
  21.189 -    if (rq == NULL)
  21.190 -        return -1;
  21.191 -
  21.192 -    elevator_init(rq, "noop");
  21.193 +	memset(ptr, 0, sizeof(struct xlbd_major_info));
  21.194  
  21.195 -    /* Hard sector size and max sectors impersonate the equiv. hardware. */
  21.196 -    blk_queue_hardsect_size(rq, sector_size);
  21.197 -    blk_queue_max_sectors(rq, 512);
  21.198 -
  21.199 -    /* Each segment in a request is up to an aligned page in size. */
  21.200 -    blk_queue_segment_boundary(rq, PAGE_SIZE - 1);
  21.201 -    blk_queue_max_segment_size(rq, PAGE_SIZE);
  21.202 +	ptr->major = major;
  21.203  
  21.204 -    /* Ensure a merged request will fit in a single I/O ring slot. */
  21.205 -    blk_queue_max_phys_segments(rq, BLKIF_MAX_SEGMENTS_PER_REQUEST);
  21.206 -    blk_queue_max_hw_segments(rq, BLKIF_MAX_SEGMENTS_PER_REQUEST);
  21.207 +	switch (index) {
  21.208 +	case XLBD_MAJOR_IDE_RANGE:
  21.209 +		ptr->type = &xlbd_ide_type;
  21.210 +		ptr->index = index - XLBD_MAJOR_IDE_START;
  21.211 +		break;
  21.212 +	case XLBD_MAJOR_SCSI_RANGE:
  21.213 +		ptr->type = &xlbd_scsi_type;
  21.214 +		ptr->index = index - XLBD_MAJOR_SCSI_START;
  21.215 +		break;
  21.216 +	case XLBD_MAJOR_VBD_RANGE:
  21.217 +		ptr->type = &xlbd_vbd_type;
  21.218 +		ptr->index = index - XLBD_MAJOR_VBD_START;
  21.219 +		break;
  21.220 +	}
  21.221  
  21.222 -    /* Make sure buffer addresses are sector-aligned. */
  21.223 -    blk_queue_dma_alignment(rq, 511);
  21.224 +	printk("Registering block device major %i\n", ptr->major);
  21.225 +	if (register_blkdev(ptr->major, ptr->type->devname)) {
  21.226 +		WPRINTK("can't get major %d with name %s\n",
  21.227 +			ptr->major, ptr->type->devname);
  21.228 +		kfree(ptr);
  21.229 +		return NULL;
  21.230 +	}
  21.231  
  21.232 -    gd->queue = rq;
  21.233 -
  21.234 -    return 0;
  21.235 +	devfs_mk_dir(ptr->type->devname);
  21.236 +	major_info[index] = ptr;
  21.237 +	return ptr;
  21.238  }
  21.239  
  21.240 -static struct gendisk *xlvbd_alloc_gendisk(
  21.241 -    struct xlbd_major_info *mi, int minor, blkif_sector_t capacity,
  21.242 -    int device, blkif_vdev_t handle, u16 info, u16 sector_size)
  21.243 +static struct xlbd_major_info *
  21.244 +xlbd_get_major_info(int vdevice)
  21.245  {
  21.246 -    struct gendisk *gd;
  21.247 -    struct xlbd_disk_info *di;
  21.248 -    int nr_minors = 1;
  21.249 -
  21.250 -    di = kmalloc(sizeof(struct xlbd_disk_info), GFP_KERNEL);
  21.251 -    if (di == NULL)
  21.252 -        return NULL;
  21.253 -    memset(di, 0, sizeof(*di));
  21.254 -    di->mi = mi;
  21.255 -    di->xd_device = device;
  21.256 -    di->handle = handle;
  21.257 -
  21.258 -    if ((minor & ((1 << mi->type->partn_shift) - 1)) == 0)
  21.259 -        nr_minors = 1 << mi->type->partn_shift;
  21.260 -
  21.261 -    gd = alloc_disk(nr_minors);
  21.262 -    if (gd == NULL)
  21.263 -        goto out;
  21.264 +	struct xlbd_major_info *mi;
  21.265 +	int major, minor, index;
  21.266  
  21.267 -    if (nr_minors > 1)
  21.268 -        sprintf(gd->disk_name, "%s%c", mi->type->diskname,
  21.269 -                'a' + mi->index * mi->type->disks_per_major +
  21.270 -                    (minor >> mi->type->partn_shift));
  21.271 -    else
  21.272 -        sprintf(gd->disk_name, "%s%c%d", mi->type->diskname,
  21.273 -                'a' + mi->index * mi->type->disks_per_major +
  21.274 -                (minor >> mi->type->partn_shift),
  21.275 -                minor & ((1 << mi->type->partn_shift) - 1));
  21.276 -
  21.277 -    gd->major = mi->major;
  21.278 -    gd->first_minor = minor;
  21.279 -    gd->fops = &xlvbd_block_fops;
  21.280 -    gd->private_data = di;
  21.281 -    set_capacity(gd, capacity);
  21.282 +	major = BLKIF_MAJOR(vdevice);
  21.283 +	minor = BLKIF_MINOR(vdevice);
  21.284  
  21.285 -    if (xlvbd_init_blk_queue(gd, sector_size)) {
  21.286 -        del_gendisk(gd);
  21.287 -        goto out;
  21.288 -    }
  21.289 -
  21.290 -    di->rq = gd->queue;
  21.291 -
  21.292 -    if (info & VDISK_READONLY)
  21.293 -        set_disk_ro(gd, 1);
  21.294 +	switch (major) {
  21.295 +	case IDE0_MAJOR: index = 0; break;
  21.296 +	case IDE1_MAJOR: index = 1; break;
  21.297 +	case IDE2_MAJOR: index = 2; break;
  21.298 +	case IDE3_MAJOR: index = 3; break;
  21.299 +	case IDE4_MAJOR: index = 4; break;
  21.300 +	case IDE5_MAJOR: index = 5; break;
  21.301 +	case IDE6_MAJOR: index = 6; break;
  21.302 +	case IDE7_MAJOR: index = 7; break;
  21.303 +	case IDE8_MAJOR: index = 8; break;
  21.304 +	case IDE9_MAJOR: index = 9; break;
  21.305 +	case SCSI_DISK0_MAJOR: index = 10; break;
  21.306 +	case SCSI_DISK1_MAJOR ... SCSI_DISK7_MAJOR:
  21.307 +		index = 11 + major - SCSI_DISK1_MAJOR;
  21.308 +		break;
  21.309 +	case SCSI_CDROM_MAJOR: index = 18; break;
  21.310 +	default: index = 19; break;
  21.311 +	}
  21.312  
  21.313 -    if (info & VDISK_REMOVABLE)
  21.314 -        gd->flags |= GENHD_FL_REMOVABLE;
  21.315 -
  21.316 -    if (info & VDISK_CDROM)
  21.317 -        gd->flags |= GENHD_FL_CD;
  21.318 -
  21.319 -    add_disk(gd);
  21.320 -
  21.321 -    return gd;
  21.322 -
  21.323 -out:
  21.324 -    kfree(di);
  21.325 -    return NULL;
  21.326 +	mi = ((major_info[index] != NULL) ? major_info[index] :
  21.327 +	      xlbd_alloc_major_info(major, minor, index));
  21.328 +	mi->usage++;
  21.329 +	return mi;
  21.330  }
  21.331  
  21.332 -int xlvbd_add(blkif_sector_t capacity, int device, blkif_vdev_t handle,
  21.333 -	      u16 info, u16 sector_size)
  21.334 +static void
  21.335 +xlbd_put_major_info(struct xlbd_major_info *mi)
  21.336  {
  21.337 -    struct lvdisk *new;
  21.338 -    struct block_device *bd;
  21.339 -    struct gendisk *gd;
  21.340 -    struct xlbd_major_info *mi;
  21.341 -
  21.342 -    mi = xlbd_get_major_info(device);
  21.343 -    if (mi == NULL)
  21.344 -        return -EPERM;
  21.345 -
  21.346 -    new = xlvbd_device_alloc();
  21.347 -    if (new == NULL)
  21.348 -        return -ENOMEM;
  21.349 -    new->capacity = capacity;
  21.350 -    new->info = info;
  21.351 -    new->handle = handle;
  21.352 -    new->dev = MKDEV(MAJOR_XEN(device), MINOR_XEN(device));
  21.353 -
  21.354 -    bd = bdget(new->dev);
  21.355 -    if (bd == NULL)
  21.356 -        goto out;
  21.357 -    
  21.358 -    gd = xlvbd_alloc_gendisk(mi, MINOR_XEN(device), capacity, device, handle,
  21.359 -			     info, sector_size);
  21.360 -    if (gd == NULL)
  21.361 -        goto out_bd;
  21.362 -
  21.363 -    list_add(&new->list, &vbds_list);
  21.364 -out_bd:
  21.365 -    bdput(bd);
  21.366 -out:
  21.367 -    return 0;
  21.368 +	mi->usage--;
  21.369 +	/* XXX: release major if 0 */
  21.370  }
  21.371  
  21.372 -static int xlvbd_device_del(struct lvdisk *disk)
  21.373 +static int
  21.374 +xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size)
  21.375  {
  21.376 -    struct block_device *bd;
  21.377 -    struct gendisk *gd;
  21.378 -    struct xlbd_disk_info *di;
  21.379 -    int ret = 0, unused;
  21.380 -    request_queue_t *rq;
  21.381 -
  21.382 -    bd = bdget(disk->dev);
  21.383 -    if (bd == NULL)
  21.384 -        return -1;
  21.385 -
  21.386 -    gd = get_gendisk(disk->dev, &unused);
  21.387 -    di = gd->private_data;
  21.388 +	request_queue_t *rq;
  21.389  
  21.390 -#if 0 /* This is wrong: hda and hdb share same major, for example. */
  21.391 -    if (di->mi->usage != 0) {
  21.392 -        WPRINTK("disk removal failed: used [dev=%x]\n", disk->dev);
  21.393 -        ret = -1;
  21.394 -        goto out;
  21.395 -    }
  21.396 -#endif
  21.397 +	rq = blk_init_queue(do_blkif_request, &blkif_io_lock);
  21.398 +	if (rq == NULL)
  21.399 +		return -1;
  21.400  
  21.401 -    rq = gd->queue;
  21.402 -    del_gendisk(gd);
  21.403 -    put_disk(gd);
  21.404 -    blk_cleanup_queue(rq);
  21.405 +	elevator_init(rq, "noop");
  21.406  
  21.407 -    xlvbd_device_free(disk);
  21.408 -    bdput(bd);
  21.409 -    return ret;
  21.410 +	/* Hard sector size and max sectors impersonate the equiv. hardware. */
  21.411 +	blk_queue_hardsect_size(rq, sector_size);
  21.412 +	blk_queue_max_sectors(rq, 512);
  21.413 +
  21.414 +	/* Each segment in a request is up to an aligned page in size. */
  21.415 +	blk_queue_segment_boundary(rq, PAGE_SIZE - 1);
  21.416 +	blk_queue_max_segment_size(rq, PAGE_SIZE);
  21.417 +
  21.418 +	/* Ensure a merged request will fit in a single I/O ring slot. */
  21.419 +	blk_queue_max_phys_segments(rq, BLKIF_MAX_SEGMENTS_PER_REQUEST);
  21.420 +	blk_queue_max_hw_segments(rq, BLKIF_MAX_SEGMENTS_PER_REQUEST);
  21.421 +
  21.422 +	/* Make sure buffer addresses are sector-aligned. */
  21.423 +	blk_queue_dma_alignment(rq, 511);
  21.424 +
  21.425 +	gd->queue = rq;
  21.426 +
  21.427 +	return 0;
  21.428  }
  21.429  
  21.430 -void xlvbd_del(blkif_vdev_t handle)
  21.431 +static int
  21.432 +xlvbd_alloc_gendisk(int minor, blkif_sector_t capacity, int vdevice,
  21.433 +		    u16 vdisk_info, u16 sector_size,
  21.434 +		    struct blkfront_info *info)
  21.435  {
  21.436 -	struct lvdisk *i;
  21.437 +	struct gendisk *gd;
  21.438 +	struct xlbd_major_info *mi;
  21.439 +	int nr_minors = 1;
  21.440 +	int err = -ENODEV;
  21.441  
  21.442 -	list_for_each_entry(i, &vbds_list, list) {
  21.443 -		if (i->handle == handle) {
  21.444 -			xlvbd_device_del(i);
  21.445 -			return;
  21.446 -		}
  21.447 +	mi = xlbd_get_major_info(vdevice);
  21.448 +	if (mi == NULL)
  21.449 +		goto out;
  21.450 +	info->mi = mi;
  21.451 +
  21.452 +	if ((minor & ((1 << mi->type->partn_shift) - 1)) == 0)
  21.453 +		nr_minors = 1 << mi->type->partn_shift;
  21.454 +
  21.455 +	gd = alloc_disk(nr_minors);
  21.456 +	if (gd == NULL)
  21.457 +		goto out;
  21.458 +
  21.459 +	if (nr_minors > 1)
  21.460 +		sprintf(gd->disk_name, "%s%c", mi->type->diskname,
  21.461 +			'a' + mi->index * mi->type->disks_per_major +
  21.462 +			(minor >> mi->type->partn_shift));
  21.463 +	else
  21.464 +		sprintf(gd->disk_name, "%s%c%d", mi->type->diskname,
  21.465 +			'a' + mi->index * mi->type->disks_per_major +
  21.466 +			(minor >> mi->type->partn_shift),
  21.467 +			minor & ((1 << mi->type->partn_shift) - 1));
  21.468 +
  21.469 +	gd->major = mi->major;
  21.470 +	gd->first_minor = minor;
  21.471 +	gd->fops = &xlvbd_block_fops;
  21.472 +	gd->private_data = info;
  21.473 +	set_capacity(gd, capacity);
  21.474 +
  21.475 +	if (xlvbd_init_blk_queue(gd, sector_size)) {
  21.476 +		del_gendisk(gd);
  21.477 +		goto out;
  21.478  	}
  21.479 -	BUG();
  21.480 +
  21.481 +	info->rq = gd->queue;
  21.482 +
  21.483 +	if (vdisk_info & VDISK_READONLY)
  21.484 +		set_disk_ro(gd, 1);
  21.485 +
  21.486 +	if (vdisk_info & VDISK_REMOVABLE)
  21.487 +		gd->flags |= GENHD_FL_REMOVABLE;
  21.488 +
  21.489 +	if (vdisk_info & VDISK_CDROM)
  21.490 +		gd->flags |= GENHD_FL_CD;
  21.491 +
  21.492 +	add_disk(gd);
  21.493 +
  21.494 +	return 0;
  21.495 +
  21.496 + out:
  21.497 +	if (mi)
  21.498 +		xlbd_put_major_info(mi);
  21.499 +	return err;
  21.500  }
  21.501 +
  21.502 +int
  21.503 +xlvbd_add(blkif_sector_t capacity, int vdevice, u16 vdisk_info,
  21.504 +	  u16 sector_size, struct blkfront_info *info)
  21.505 +{
  21.506 +	struct block_device *bd;
  21.507 +	int err = 0;
  21.508 +
  21.509 +	info->dev = MKDEV(BLKIF_MAJOR(vdevice), BLKIF_MINOR(vdevice));
  21.510 +
  21.511 +	bd = bdget(info->dev);
  21.512 +	if (bd == NULL)
  21.513 +		return -ENODEV;
  21.514 +
  21.515 +	err = xlvbd_alloc_gendisk(BLKIF_MINOR(vdevice), capacity, vdevice,
  21.516 +				  vdisk_info, sector_size, info);
  21.517 +
  21.518 +	bdput(bd);
  21.519 +	return err;
  21.520 +}
  21.521 +
  21.522 +void
  21.523 +xlvbd_del(struct blkfront_info *info)
  21.524 +{
  21.525 +	struct block_device *bd;
  21.526 +	struct gendisk *gd;
  21.527 +	int unused;
  21.528 +	request_queue_t *rq;
  21.529 +
  21.530 +	bd = bdget(info->dev);
  21.531 +	if (bd == NULL)
  21.532 +		return;
  21.533 +
  21.534 +	gd = get_gendisk(info->dev, &unused);
  21.535 +	rq = gd->queue;
  21.536 +
  21.537 +	del_gendisk(gd);
  21.538 +	put_disk(gd);
  21.539 +	xlbd_put_major_info(info->mi);
  21.540 +	info->mi = NULL;
  21.541 +	blk_cleanup_queue(rq);
  21.542 +
  21.543 +	bdput(bd);
  21.544 +}
    22.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Tue Aug 23 18:25:51 2005 +0000
    22.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Tue Aug 23 18:27:22 2005 +0000
    22.3 @@ -102,12 +102,12 @@ dump_packet(int tag, void *addr, u32 ap)
    22.4  #endif
    22.5  
    22.6  #ifdef CONFIG_XEN_NETDEV_GRANT_TX
    22.7 -static grant_ref_t gref_tx_head, gref_tx_terminal;
    22.8 +static grant_ref_t gref_tx_head;
    22.9  static grant_ref_t grant_tx_ref[NETIF_TX_RING_SIZE + 1];
   22.10  #endif
   22.11  
   22.12  #ifdef CONFIG_XEN_NETDEV_GRANT_RX
   22.13 -static grant_ref_t gref_rx_head, gref_rx_terminal;
   22.14 +static grant_ref_t gref_rx_head;
   22.15  static grant_ref_t grant_rx_ref[NETIF_RX_RING_SIZE + 1];
   22.16  #endif
   22.17  
   22.18 @@ -441,8 +441,8 @@ static void network_alloc_rx_buffers(str
   22.19          
   22.20          np->rx->ring[MASK_NETIF_RX_IDX(req_prod + i)].req.id = id;
   22.21  #ifdef CONFIG_XEN_NETDEV_GRANT_RX
   22.22 -        if (unlikely((ref = gnttab_claim_grant_reference(&gref_rx_head, 
   22.23 -                                                gref_rx_terminal)) < 0)) {
   22.24 +	ref = gnttab_claim_grant_reference(&gref_rx_head);
   22.25 +        if (unlikely(ref < 0)) {
   22.26              printk(KERN_ALERT "#### netfront can't claim rx reference\n");
   22.27              BUG();
   22.28          }
   22.29 @@ -537,8 +537,8 @@ static int network_start_xmit(struct sk_
   22.30  
   22.31      tx->id   = id;
   22.32  #ifdef CONFIG_XEN_NETDEV_GRANT_TX
   22.33 -    if (unlikely((ref = gnttab_claim_grant_reference(&gref_tx_head, 
   22.34 -                                                     gref_tx_terminal)) < 0)) {
   22.35 +    ref = gnttab_claim_grant_reference(&gref_tx_head);
   22.36 +    if (unlikely(ref < 0)) {
   22.37          printk(KERN_ALERT "#### netfront can't claim tx grant reference\n");
   22.38          BUG();
   22.39      }
   22.40 @@ -929,8 +929,7 @@ static void send_interface_connect(struc
   22.41      msg->handle = np->handle;
   22.42      msg->tx_shmem_frame = virt_to_mfn(np->tx);
   22.43  #ifdef CONFIG_XEN_NETDEV_GRANT_TX
   22.44 -    msg->tx_shmem_ref   = (u32)gnttab_claim_grant_reference(&gref_tx_head, 
   22.45 -                                                            gref_tx_terminal);
   22.46 +    msg->tx_shmem_ref   = (u32)gnttab_claim_grant_reference(&gref_tx_head);
   22.47      if(msg->tx_shmem_ref < 0) { 
   22.48          printk(KERN_ALERT "#### netfront can't claim tx_shmem reference\n");
   22.49          BUG();
   22.50 @@ -941,8 +940,7 @@ static void send_interface_connect(struc
   22.51  
   22.52      msg->rx_shmem_frame = virt_to_mfn(np->rx);
   22.53  #ifdef CONFIG_XEN_NETDEV_GRANT_RX
   22.54 -    msg->rx_shmem_ref   = (u32)gnttab_claim_grant_reference(&gref_rx_head, 
   22.55 -                                                            gref_rx_terminal);
   22.56 +    msg->rx_shmem_ref   = (u32)gnttab_claim_grant_reference(&gref_rx_head);
   22.57      if(msg->rx_shmem_ref < 0) {
   22.58          printk(KERN_ALERT "#### netfront can't claim rx_shmem reference\n");
   22.59          BUG();
   22.60 @@ -1420,7 +1418,7 @@ static int __init netif_init(void)
   22.61  #ifdef CONFIG_XEN_NETDEV_GRANT_TX
   22.62      /* A grant for every ring slot, plus one for the ring itself */
   22.63      if (gnttab_alloc_grant_references(NETIF_TX_RING_SIZE + 1,
   22.64 -                                      &gref_tx_head, &gref_tx_terminal) < 0) {
   22.65 +                                      &gref_tx_head) < 0) {
   22.66          printk(KERN_ALERT "#### netfront can't alloc tx grant refs\n");
   22.67          return 1;
   22.68      }
   22.69 @@ -1429,7 +1427,7 @@ static int __init netif_init(void)
   22.70  #ifdef CONFIG_XEN_NETDEV_GRANT_RX
   22.71      /* A grant for every ring slot, plus one for the ring itself */
   22.72      if (gnttab_alloc_grant_references(NETIF_RX_RING_SIZE + 1,
   22.73 -                                      &gref_rx_head, &gref_rx_terminal) < 0) {
   22.74 +                                      &gref_rx_head) < 0) {
   22.75          printk(KERN_ALERT "#### netfront can't alloc rx grant refs\n");
   22.76          return 1;
   22.77      }
   22.78 @@ -1457,10 +1455,10 @@ static int __init netif_init(void)
   22.79  static void netif_exit(void)
   22.80  {
   22.81  #ifdef CONFIG_XEN_NETDEV_GRANT_TX
   22.82 -    gnttab_free_grant_references(NETIF_TX_RING_SIZE + 1, gref_tx_head);
   22.83 +    gnttab_free_grant_references(gref_tx_head);
   22.84  #endif
   22.85  #ifdef CONFIG_XEN_NETDEV_GRANT_RX
   22.86 -    gnttab_free_grant_references(NETIF_RX_RING_SIZE + 1, gref_rx_head);
   22.87 +    gnttab_free_grant_references(gref_rx_head);
   22.88  #endif
   22.89  }
   22.90  
    23.1 --- a/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c	Tue Aug 23 18:25:51 2005 +0000
    23.2 +++ b/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c	Tue Aug 23 18:27:22 2005 +0000
    23.3 @@ -167,7 +167,7 @@ static int privcmd_ioctl(struct inode *i
    23.4              if (ret)
    23.5                  goto batch_err;
    23.6  
    23.7 -            u.val = (mfn << PAGE_SHIFT) | pgprot_val(vma->vm_page_prot);
    23.8 +            u.val = pte_val_ma(pfn_pte_ma(mfn, vma->vm_page_prot));
    23.9              u.ptr = ptep;
   23.10  
   23.11              if ( unlikely(HYPERVISOR_mmu_update(&u, 1, NULL, m.dom) < 0) )
    24.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h	Tue Aug 23 18:25:51 2005 +0000
    24.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h	Tue Aug 23 18:27:22 2005 +0000
    24.3 @@ -60,9 +60,13 @@
    24.4  #define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)
    24.5  
    24.6  /**** MACHINE <-> PHYSICAL CONVERSION MACROS ****/
    24.7 +#define INVALID_P2M_ENTRY	(~0U)
    24.8 +#define FOREIGN_FRAME(m)	((m) | 0x80000000U)
    24.9  extern unsigned int *phys_to_machine_mapping;
   24.10 -#define pfn_to_mfn(_pfn) ((unsigned long)(phys_to_machine_mapping[(_pfn)]))
   24.11 -#define mfn_to_pfn(_mfn) ((unsigned long)(machine_to_phys_mapping[(_mfn)]))
   24.12 +#define pfn_to_mfn(pfn)	\
   24.13 +((unsigned long)phys_to_machine_mapping[(unsigned int)(pfn)] & 0x7FFFFFFFUL)
   24.14 +#define mfn_to_pfn(mfn)	\
   24.15 +((unsigned long)machine_to_phys_mapping[(unsigned int)(mfn)])
   24.16  
   24.17  /* Definitions for machine and pseudophysical addresses. */
   24.18  #ifdef CONFIG_X86_PAE
    25.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable-2level.h	Tue Aug 23 18:25:51 2005 +0000
    25.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable-2level.h	Tue Aug 23 18:27:22 2005 +0000
    25.3 @@ -63,17 +63,15 @@ inline static void set_pte_at_sync(struc
    25.4   * 
    25.5   * NB2. When deliberately mapping foreign pages into the p2m table, you *must*
    25.6   *      use FOREIGN_FRAME(). This will cause pte_pfn() to choke on it, as we
    25.7 - *      require. In all the cases we care about, the high bit gets shifted out
    25.8 - *      (e.g., phys_to_machine()) so behaviour there is correct.
    25.9 + *      require. In all the cases we care about, the FOREIGN_FRAME bit is
   25.10 + *      masked (e.g., pfn_to_mfn()) so behaviour there is correct.
   25.11   */
   25.12 -#define INVALID_P2M_ENTRY (~0U)
   25.13 -#define FOREIGN_FRAME(_m) ((_m) | (1UL<<((sizeof(unsigned long)*8)-1)))
   25.14  #define pte_mfn(_pte) ((_pte).pte_low >> PAGE_SHIFT)
   25.15  #define pte_pfn(_pte)							\
   25.16  ({									\
   25.17  	unsigned long mfn = pte_mfn(_pte);				\
   25.18  	unsigned long pfn = mfn_to_pfn(mfn);				\
   25.19 -	if ((pfn >= max_mapnr) || (pfn_to_mfn(pfn) != mfn))		\
   25.20 +	if ((pfn >= max_mapnr) || (phys_to_machine_mapping[pfn] != mfn))\
   25.21  		pfn = max_mapnr; /* special: force !pfn_valid() */	\
   25.22  	pfn;								\
   25.23  })
    26.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable-3level.h	Tue Aug 23 18:25:51 2005 +0000
    26.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable-3level.h	Tue Aug 23 18:27:22 2005 +0000
    26.3 @@ -150,15 +150,13 @@ static inline int pte_none(pte_t pte)
    26.4  	return !pte.pte_low && !pte.pte_high;
    26.5  }
    26.6  
    26.7 -#define INVALID_P2M_ENTRY (~0U)
    26.8 -#define FOREIGN_FRAME(_m) ((_m) | (1UL<<((sizeof(unsigned long)*8)-1)))
    26.9  #define pte_mfn(_pte) ( ((_pte).pte_low >> PAGE_SHIFT) |\
   26.10  		        (((_pte).pte_high & 0xfff) << (32-PAGE_SHIFT)) )
   26.11  #define pte_pfn(_pte)                                                  \
   26.12  ({                                                                     \
   26.13         unsigned long mfn = pte_mfn(_pte);                              \
   26.14         unsigned long pfn = mfn_to_pfn(mfn);                            \
   26.15 -       if ((pfn >= max_mapnr) || (pfn_to_mfn(pfn) != mfn))             \
   26.16 +       if ((pfn >= max_mapnr) || (phys_to_machine_mapping[pfn] != mfn))\
   26.17                 pfn = max_mapnr; /* special: force !pfn_valid() */      \
   26.18         pfn;                                                            \
   26.19  })
    27.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/page.h	Tue Aug 23 18:25:51 2005 +0000
    27.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/page.h	Tue Aug 23 18:27:22 2005 +0000
    27.3 @@ -62,9 +62,13 @@ void copy_page(void *, void *);
    27.4  #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
    27.5  
    27.6  /**** MACHINE <-> PHYSICAL CONVERSION MACROS ****/
    27.7 +#define INVALID_P2M_ENTRY	(~0U)
    27.8 +#define FOREIGN_FRAME(m)	((m) | 0x80000000U)
    27.9  extern u32 *phys_to_machine_mapping;
   27.10 -#define pfn_to_mfn(_pfn) ((unsigned long) phys_to_machine_mapping[(unsigned int)(_pfn)])
   27.11 -#define mfn_to_pfn(_mfn) ((unsigned long) machine_to_phys_mapping[(unsigned int)(_mfn)])
   27.12 +#define pfn_to_mfn(pfn)	\
   27.13 +((unsigned long)phys_to_machine_mapping[(unsigned int)(pfn)] & 0x7FFFFFFFUL)
   27.14 +#define mfn_to_pfn(mfn)	\
   27.15 +((unsigned long)machine_to_phys_mapping[(unsigned int)(mfn)])
   27.16  
   27.17  /* Definitions for machine and pseudophysical addresses. */
   27.18  typedef unsigned long paddr_t;
    28.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/pgtable.h	Tue Aug 23 18:25:51 2005 +0000
    28.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/pgtable.h	Tue Aug 23 18:27:22 2005 +0000
    28.3 @@ -300,17 +300,15 @@ inline static void set_pte_at(struct mm_
    28.4   * 
    28.5   * NB2. When deliberately mapping foreign pages into the p2m table, you *must*
    28.6   *      use FOREIGN_FRAME(). This will cause pte_pfn() to choke on it, as we
    28.7 - *      require. In all the cases we care about, the high bit gets shifted out
    28.8 - *      (e.g., phys_to_machine()) so behaviour there is correct.
    28.9 + *      require. In all the cases we care about, the FOREIGN_FRAME bit is
   28.10 + *      masked (e.g., pfn_to_mfn()) so behaviour there is correct.
   28.11   */
   28.12 -#define INVALID_P2M_ENTRY (~0U)
   28.13 -#define FOREIGN_FRAME(_m) ((_m) | (1UL<<((sizeof(unsigned long)*8)-1)))
   28.14  #define pte_mfn(_pte) (((_pte).pte & PTE_MASK) >> PAGE_SHIFT)
   28.15  #define pte_pfn(_pte)							\
   28.16  ({									\
   28.17  	unsigned long mfn = pte_mfn(_pte);                              \
   28.18  	unsigned pfn = mfn_to_pfn(mfn);                                 \
   28.19 -	if ((pfn >= max_mapnr) || (pfn_to_mfn(pfn) != mfn))		\
   28.20 +	if ((pfn >= max_mapnr) || (phys_to_machine_mapping[pfn] != mfn))\
   28.21  		pfn = max_mapnr; /* special: force !pfn_valid() */	\
   28.22  	pfn;								\
   28.23  })
    29.1 --- a/linux-2.6-xen-sparse/include/asm-xen/gnttab.h	Tue Aug 23 18:25:51 2005 +0000
    29.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/gnttab.h	Tue Aug 23 18:27:22 2005 +0000
    29.3 @@ -19,54 +19,46 @@
    29.4  
    29.5  /* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */
    29.6  #define NR_GRANT_FRAMES 4
    29.7 -#define NR_GRANT_ENTRIES (NR_GRANT_FRAMES * PAGE_SIZE / sizeof(grant_entry_t))
    29.8 -
    29.9 -int
   29.10 -gnttab_grant_foreign_access(
   29.11 -    domid_t domid, unsigned long frame, int readonly);
   29.12 -
   29.13 -void
   29.14 -gnttab_end_foreign_access(
   29.15 -    grant_ref_t ref, int readonly);
   29.16  
   29.17 -int
   29.18 -gnttab_grant_foreign_transfer(
   29.19 -    domid_t domid, unsigned long pfn);
   29.20 +struct gnttab_free_callback {
   29.21 +    struct gnttab_free_callback *next;
   29.22 +    void (*fn)(void *);
   29.23 +    void *arg;
   29.24 +    u16 count;
   29.25 +};
   29.26  
   29.27 -unsigned long
   29.28 -gnttab_end_foreign_transfer(
   29.29 -    grant_ref_t ref);
   29.30 +int gnttab_grant_foreign_access(domid_t domid, unsigned long frame,
   29.31 +				int readonly);
   29.32  
   29.33 -int
   29.34 -gnttab_query_foreign_access( 
   29.35 -    grant_ref_t ref );
   29.36 +void gnttab_end_foreign_access(grant_ref_t ref, int readonly);
   29.37 +
   29.38 +int gnttab_grant_foreign_transfer(domid_t domid, unsigned long pfn);
   29.39 +
   29.40 +unsigned long gnttab_end_foreign_transfer(grant_ref_t ref);
   29.41 +
   29.42 +int gnttab_query_foreign_access(grant_ref_t ref);
   29.43  
   29.44  /*
   29.45   * operations on reserved batches of grant references
   29.46   */
   29.47 -int
   29.48 -gnttab_alloc_grant_references(
   29.49 -    u16 count, grant_ref_t *pprivate_head, grant_ref_t *private_terminal );
   29.50 -
   29.51 -void
   29.52 -gnttab_free_grant_references(
   29.53 -    u16 count, grant_ref_t private_head );
   29.54 -
   29.55 -int
   29.56 -gnttab_claim_grant_reference( grant_ref_t *pprivate_head, grant_ref_t terminal
   29.57 -);
   29.58 +int gnttab_alloc_grant_references(u16 count, grant_ref_t *pprivate_head);
   29.59  
   29.60 -void
   29.61 -gnttab_release_grant_reference(
   29.62 -    grant_ref_t *private_head, grant_ref_t release );
   29.63 +void gnttab_free_grant_reference(grant_ref_t ref);
   29.64  
   29.65 -void
   29.66 -gnttab_grant_foreign_access_ref(
   29.67 -    grant_ref_t ref, domid_t domid, unsigned long frame, int readonly);
   29.68 +void gnttab_free_grant_references(grant_ref_t head);
   29.69  
   29.70 -void
   29.71 -gnttab_grant_foreign_transfer_ref(
   29.72 -    grant_ref_t, domid_t domid, unsigned long pfn);
   29.73 +int gnttab_claim_grant_reference(grant_ref_t *pprivate_head);
   29.74  
   29.75 +void gnttab_release_grant_reference(grant_ref_t *private_head,
   29.76 +				    grant_ref_t release);
   29.77 +
   29.78 +void gnttab_request_free_callback(struct gnttab_free_callback *callback,
   29.79 +				  void (*fn)(void *), void *arg, u16 count);
   29.80 +
   29.81 +void gnttab_grant_foreign_access_ref(grant_ref_t ref, domid_t domid,
   29.82 +				     unsigned long frame, int readonly);
   29.83 +
   29.84 +void gnttab_grant_foreign_transfer_ref(grant_ref_t, domid_t domid,
   29.85 +				       unsigned long pfn);
   29.86  
   29.87  #endif /* __ASM_GNTTAB_H__ */
    30.1 --- a/tools/xenstat/xentop/Makefile	Tue Aug 23 18:25:51 2005 +0000
    30.2 +++ b/tools/xenstat/xentop/Makefile	Tue Aug 23 18:27:22 2005 +0000
    30.3 @@ -28,7 +28,7 @@ sbindir=$(prefix)/sbin
    30.4  
    30.5  CFLAGS += -DGCC_PRINTF -Wall -Werror -I$(XEN_LIBXENSTAT)
    30.6  LDFLAGS += -L$(XEN_LIBXENSTAT)
    30.7 -LDLIBS += -lxenstat -lcurses
    30.8 +LDLIBS += -lxenstat -lncurses
    30.9  
   30.10  all: xentop
   30.11  
    31.1 --- a/xen/arch/x86/io_apic.c	Tue Aug 23 18:25:51 2005 +0000
    31.2 +++ b/xen/arch/x86/io_apic.c	Tue Aug 23 18:27:22 2005 +0000
    31.3 @@ -1751,8 +1751,30 @@ int ioapic_guest_write(int apicid, int a
    31.4      
    31.5      pin = (address - 0x10) >> 1;
    31.6  
    31.7 +    *(u32 *)&rte = val;
    31.8      rte.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS);
    31.9 -    *(int *)&rte = val;
   31.10 +
   31.11 +    /*
   31.12 +     * What about weird destination types?
   31.13 +     *  SMI:    Ignore? Ought to be set up by the BIOS.
   31.14 +     *  NMI:    Ignore? Watchdog functionality is Xen's concern.
   31.15 +     *  INIT:   Definitely ignore: probably a guest OS bug.
   31.16 +     *  ExtINT: Ignore? Linux only asserts this at start of day.
   31.17 +     * For now, print a message and return an error. We can fix up on demand.
   31.18 +     */
   31.19 +    if ( rte.delivery_mode > dest_LowestPrio )
   31.20 +    {
   31.21 +        printk("ERROR: Attempt to write weird IOAPIC destination mode!\n");
   31.22 +        printk("       APIC=%d/%d, lo-reg=%x\n", apicid, pin, val);
   31.23 +        return -EINVAL;
   31.24 +    }
   31.25 +
   31.26 +    /*
   31.27 +     * The guest does not know physical APIC arrangement (flat vs. cluster).
   31.28 +     * Apply genapic conventions for this platform.
   31.29 +     */
   31.30 +    rte.delivery_mode = INT_DELIVERY_MODE;
   31.31 +    rte.dest_mode     = INT_DEST_MODE;
   31.32  
   31.33      if ( rte.vector >= FIRST_DEVICE_VECTOR )
   31.34      {
    32.1 --- a/xen/arch/x86/mm.c	Tue Aug 23 18:25:51 2005 +0000
    32.2 +++ b/xen/arch/x86/mm.c	Tue Aug 23 18:27:22 2005 +0000
    32.3 @@ -444,7 +444,7 @@ get_page_from_l1e(
    32.4  
    32.5      if ( unlikely(l1e_get_flags(l1e) & L1_DISALLOW_MASK) )
    32.6      {
    32.7 -        MEM_LOG("Bad L1 flags %x\n", l1e_get_flags(l1e) & L1_DISALLOW_MASK);
    32.8 +        MEM_LOG("Bad L1 flags %x", l1e_get_flags(l1e) & L1_DISALLOW_MASK);
    32.9          return 0;
   32.10      }
   32.11  
   32.12 @@ -490,7 +490,7 @@ get_page_from_l2e(
   32.13  
   32.14      if ( unlikely((l2e_get_flags(l2e) & L2_DISALLOW_MASK)) )
   32.15      {
   32.16 -        MEM_LOG("Bad L2 flags %x\n", l2e_get_flags(l2e) & L2_DISALLOW_MASK);
   32.17 +        MEM_LOG("Bad L2 flags %x", l2e_get_flags(l2e) & L2_DISALLOW_MASK);
   32.18          return 0;
   32.19      }
   32.20  
   32.21 @@ -523,7 +523,7 @@ get_page_from_l3e(
   32.22  
   32.23      if ( unlikely((l3e_get_flags(l3e) & L3_DISALLOW_MASK)) )
   32.24      {
   32.25 -        MEM_LOG("Bad L3 flags %x\n", l3e_get_flags(l3e) & L3_DISALLOW_MASK);
   32.26 +        MEM_LOG("Bad L3 flags %x", l3e_get_flags(l3e) & L3_DISALLOW_MASK);
   32.27          return 0;
   32.28      }
   32.29  
   32.30 @@ -557,7 +557,7 @@ get_page_from_l4e(
   32.31  
   32.32      if ( unlikely((l4e_get_flags(l4e) & L4_DISALLOW_MASK)) )
   32.33      {
   32.34 -        MEM_LOG("Bad L4 flags %x\n", l4e_get_flags(l4e) & L4_DISALLOW_MASK);
   32.35 +        MEM_LOG("Bad L4 flags %x", l4e_get_flags(l4e) & L4_DISALLOW_MASK);
   32.36          return 0;
   32.37      }
   32.38  
   32.39 @@ -1025,7 +1025,7 @@ static inline int update_l1e(l1_pgentry_
   32.40           unlikely(o != l1e_get_intpte(ol1e)) )
   32.41      {
   32.42          MEM_LOG("Failed to update %" PRIpte " -> %" PRIpte
   32.43 -                ": saw %" PRIpte "\n",
   32.44 +                ": saw %" PRIpte,
   32.45                  l1e_get_intpte(ol1e),
   32.46                  l1e_get_intpte(nl1e),
   32.47                  o);
   32.48 @@ -1051,7 +1051,7 @@ static int mod_l1_entry(l1_pgentry_t *pl
   32.49      {
   32.50          if ( unlikely(l1e_get_flags(nl1e) & L1_DISALLOW_MASK) )
   32.51          {
   32.52 -            MEM_LOG("Bad L1 flags %x\n",
   32.53 +            MEM_LOG("Bad L1 flags %x",
   32.54                      l1e_get_flags(nl1e) & L1_DISALLOW_MASK);
   32.55              return 0;
   32.56          }
   32.57 @@ -1113,7 +1113,7 @@ static int mod_l2_entry(l2_pgentry_t *pl
   32.58      {
   32.59          if ( unlikely(l2e_get_flags(nl2e) & L2_DISALLOW_MASK) )
   32.60          {
   32.61 -            MEM_LOG("Bad L2 flags %x\n",
   32.62 +            MEM_LOG("Bad L2 flags %x",
   32.63                      l2e_get_flags(nl2e) & L2_DISALLOW_MASK);
   32.64              return 0;
   32.65          }
   32.66 @@ -1175,7 +1175,7 @@ static int mod_l3_entry(l3_pgentry_t *pl
   32.67      {
   32.68          if ( unlikely(l3e_get_flags(nl3e) & L3_DISALLOW_MASK) )
   32.69          {
   32.70 -            MEM_LOG("Bad L3 flags %x\n",
   32.71 +            MEM_LOG("Bad L3 flags %x",
   32.72                      l3e_get_flags(nl3e) & L3_DISALLOW_MASK);
   32.73              return 0;
   32.74          }
   32.75 @@ -1237,7 +1237,7 @@ static int mod_l4_entry(l4_pgentry_t *pl
   32.76      {
   32.77          if ( unlikely(l4e_get_flags(nl4e) & L4_DISALLOW_MASK) )
   32.78          {
   32.79 -            MEM_LOG("Bad L4 flags %x\n",
   32.80 +            MEM_LOG("Bad L4 flags %x",
   32.81                      l4e_get_flags(nl4e) & L4_DISALLOW_MASK);
   32.82              return 0;
   32.83          }
   32.84 @@ -1598,7 +1598,7 @@ static int set_foreigndom(unsigned int c
   32.85              percpu_info[cpu].foreign = dom_io;
   32.86              break;
   32.87          default:
   32.88 -            MEM_LOG("Dom %u cannot set foreign dom\n", d->domain_id);
   32.89 +            MEM_LOG("Dom %u cannot set foreign dom", d->domain_id);
   32.90              okay = 0;
   32.91              break;
   32.92          }
   32.93 @@ -1831,7 +1831,7 @@ int do_mmuext_op(
   32.94          case MMUEXT_FLUSH_CACHE:
   32.95              if ( unlikely(!IS_CAPABLE_PHYSDEV(d)) )
   32.96              {
   32.97 -                MEM_LOG("Non-physdev domain tried to FLUSH_CACHE.\n");
   32.98 +                MEM_LOG("Non-physdev domain tried to FLUSH_CACHE.");
   32.99                  okay = 0;
  32.100              }
  32.101              else
  32.102 @@ -1845,7 +1845,7 @@ int do_mmuext_op(
  32.103              if ( shadow_mode_external(d) )
  32.104              {
  32.105                  MEM_LOG("ignoring SET_LDT hypercall from external "
  32.106 -                        "domain %u\n", d->domain_id);
  32.107 +                        "domain %u", d->domain_id);
  32.108                  okay = 0;
  32.109                  break;
  32.110              }
  32.111 @@ -1916,7 +1916,7 @@ int do_mmuext_op(
  32.112                   unlikely(IS_XEN_HEAP_FRAME(page)) )
  32.113              {
  32.114                  MEM_LOG("Transferee has no reservation headroom (%d,%d), or "
  32.115 -                        "page is in Xen heap (%lx), or dom is dying (%ld).\n",
  32.116 +                        "page is in Xen heap (%lx), or dom is dying (%ld).",
  32.117                          e->tot_pages, e->max_pages, op.mfn, e->domain_flags);
  32.118                  okay = 0;
  32.119                  goto reassign_fail;
  32.120 @@ -1937,7 +1937,7 @@ int do_mmuext_op(
  32.121                       unlikely(_nd != _d) )
  32.122                  {
  32.123                      MEM_LOG("Bad page values %lx: ed=%p(%u), sd=%p,"
  32.124 -                            " caf=%08x, taf=%" PRtype_info "\n",
  32.125 +                            " caf=%08x, taf=%" PRtype_info,
  32.126                              page_to_pfn(page), d, d->domain_id,
  32.127                              unpickle_domptr(_nd), x, page->u.inuse.type_info);
  32.128                      okay = 0;
  32.129 @@ -2301,7 +2301,7 @@ int update_grant_pte_mapping(
  32.130      if ( ((type_info & PGT_type_mask) != PGT_l1_page_table) ||
  32.131           !get_page_type(page, type_info & (PGT_type_mask|PGT_va_mask)) )
  32.132      {
  32.133 -        DPRINTK("Grant map attempted to update a non-L1 page\n");
  32.134 +        MEM_LOG("Grant map attempted to update a non-L1 page");
  32.135          rc = GNTST_general_error;
  32.136          goto failed;
  32.137      }
  32.138 @@ -2363,7 +2363,7 @@ int clear_grant_pte_mapping(
  32.139      if ( ((type_info & PGT_type_mask) != PGT_l1_page_table) ||
  32.140           !get_page_type(page, type_info & (PGT_type_mask|PGT_va_mask)) )
  32.141      {
  32.142 -        DPRINTK("Grant map attempted to update a non-L1 page\n");
  32.143 +        MEM_LOG("Grant map attempted to update a non-L1 page");
  32.144          rc = GNTST_general_error;
  32.145          goto failed;
  32.146      }
  32.147 @@ -2378,7 +2378,7 @@ int clear_grant_pte_mapping(
  32.148      /* Check that the virtual address supplied is actually mapped to frame. */
  32.149      if ( unlikely((l1e_get_intpte(ol1e) >> PAGE_SHIFT) != frame) )
  32.150      {
  32.151 -        DPRINTK("PTE entry %lx for address %lx doesn't match frame %lx\n",
  32.152 +        MEM_LOG("PTE entry %lx for address %lx doesn't match frame %lx",
  32.153                  (unsigned long)l1e_get_intpte(ol1e), addr, frame);
  32.154          put_page_type(page);
  32.155          rc = GNTST_general_error;
  32.156 @@ -2388,7 +2388,7 @@ int clear_grant_pte_mapping(
  32.157      /* Delete pagetable entry. */
  32.158      if ( unlikely(__put_user(0, (intpte_t *)va)))
  32.159      {
  32.160 -        DPRINTK("Cannot delete PTE entry at %p.\n", va);
  32.161 +        MEM_LOG("Cannot delete PTE entry at %p", va);
  32.162          put_page_type(page);
  32.163          rc = GNTST_general_error;
  32.164          goto failed;
  32.165 @@ -2452,7 +2452,7 @@ int clear_grant_va_mapping(unsigned long
  32.166  
  32.167      if ( unlikely(__get_user(ol1e.l1, &pl1e->l1) != 0) )
  32.168      {
  32.169 -        DPRINTK("Could not find PTE entry for address %lx\n", addr);
  32.170 +        MEM_LOG("Could not find PTE entry for address %lx", addr);
  32.171          return GNTST_general_error;
  32.172      }
  32.173  
  32.174 @@ -2462,7 +2462,7 @@ int clear_grant_va_mapping(unsigned long
  32.175       */
  32.176      if ( unlikely(l1e_get_pfn(ol1e) != frame) )
  32.177      {
  32.178 -        DPRINTK("PTE entry %lx for address %lx doesn't match frame %lx\n",
  32.179 +        MEM_LOG("PTE entry %lx for address %lx doesn't match frame %lx",
  32.180                  l1e_get_pfn(ol1e), addr, frame);
  32.181          return GNTST_general_error;
  32.182      }
  32.183 @@ -2470,7 +2470,7 @@ int clear_grant_va_mapping(unsigned long
  32.184      /* Delete pagetable entry. */
  32.185      if ( unlikely(__put_user(0, &pl1e->l1)) )
  32.186      {
  32.187 -        DPRINTK("Cannot delete PTE entry at %p.\n", (unsigned long *)pl1e);
  32.188 +        MEM_LOG("Cannot delete PTE entry at %p", (unsigned long *)pl1e);
  32.189          return GNTST_general_error;
  32.190      }
  32.191      
  32.192 @@ -2930,7 +2930,7 @@ int revalidate_l1(
  32.193  
  32.194          if ( unlikely(!get_page_from_l1e(nl1e, d)) )
  32.195          {
  32.196 -            MEM_LOG("ptwr: Could not re-validate l1 page\n");
  32.197 +            MEM_LOG("ptwr: Could not re-validate l1 page");
  32.198              /*
  32.199               * Make the remaining p.t's consistent before crashing, so the
  32.200               * reference counts are correct.
  32.201 @@ -3056,7 +3056,7 @@ static int ptwr_emulated_update(
  32.202      /* Aligned access only, thank you. */
  32.203      if ( !access_ok(addr, bytes) || ((addr & (bytes-1)) != 0) )
  32.204      {
  32.205 -        MEM_LOG("ptwr_emulate: Unaligned or bad size ptwr access (%d, %lx)\n",
  32.206 +        MEM_LOG("ptwr_emulate: Unaligned or bad size ptwr access (%d, %lx)",
  32.207                  bytes, addr);
  32.208          return X86EMUL_UNHANDLEABLE;
  32.209      }
  32.210 @@ -3089,7 +3089,7 @@ static int ptwr_emulated_update(
  32.211      if (__copy_from_user(&pte, &linear_pg_table[l1_linear_offset(addr)],
  32.212                           sizeof(pte)))
  32.213      {
  32.214 -        MEM_LOG("ptwr_emulate: Cannot read thru linear_pg_table\n");
  32.215 +        MEM_LOG("ptwr_emulate: Cannot read thru linear_pg_table");
  32.216          return X86EMUL_UNHANDLEABLE;
  32.217      }
  32.218  
  32.219 @@ -3102,7 +3102,7 @@ static int ptwr_emulated_update(
  32.220           (page_get_owner(page) != d) )
  32.221      {
  32.222          MEM_LOG("ptwr_emulate: Page is mistyped or bad pte "
  32.223 -                "(%lx, %" PRtype_info ")\n",
  32.224 +                "(%lx, %" PRtype_info ")",
  32.225                  l1e_get_pfn(pte), page->u.inuse.type_info);
  32.226          return X86EMUL_UNHANDLEABLE;
  32.227      }
    33.1 --- a/xen/arch/x86/vmx.c	Tue Aug 23 18:25:51 2005 +0000
    33.2 +++ b/xen/arch/x86/vmx.c	Tue Aug 23 18:27:22 2005 +0000
    33.3 @@ -1712,9 +1712,6 @@ asmlinkage void vmx_vmexit_handler(struc
    33.4      default:
    33.5          __vmx_bug(&regs);       /* should not happen */
    33.6      }
    33.7 -
    33.8 -    vmx_intr_assist(v);
    33.9 -    return;
   33.10  }
   33.11  
   33.12  asmlinkage void load_cr2(void)
    34.1 --- a/xen/arch/x86/vmx_io.c	Tue Aug 23 18:25:51 2005 +0000
    34.2 +++ b/xen/arch/x86/vmx_io.c	Tue Aug 23 18:27:22 2005 +0000
    34.3 @@ -631,12 +631,14 @@ static inline int irq_masked(unsigned lo
    34.4      return ((eflags & X86_EFLAGS_IF) == 0);
    34.5  }
    34.6  
    34.7 -void vmx_intr_assist(struct vcpu *v) 
    34.8 +asmlinkage void vmx_intr_assist(void) 
    34.9  {
   34.10      int intr_type = 0;
   34.11 -    int highest_vector = find_highest_pending_irq(v, &intr_type);
   34.12 +    int highest_vector;
   34.13      unsigned long intr_fields, eflags, interruptibility, cpu_exec_control;
   34.14 +    struct vcpu *v = current;
   34.15  
   34.16 +    highest_vector = find_highest_pending_irq(v, &intr_type);
   34.17      __vmread(CPU_BASED_VM_EXEC_CONTROL, &cpu_exec_control);
   34.18  
   34.19      if (highest_vector == -1) {
   34.20 @@ -712,9 +714,6 @@ void vmx_do_resume(struct vcpu *d)
   34.21  
   34.22      /* We can't resume the guest if we're waiting on I/O */
   34.23      ASSERT(!test_bit(ARCH_VMX_IO_WAIT, &d->arch.arch_vmx.flags));
   34.24 -
   34.25 -    /* We always check for interrupts before resuming guest */
   34.26 -    vmx_intr_assist(d);
   34.27  }
   34.28  
   34.29  #endif /* CONFIG_VMX */
    35.1 --- a/xen/arch/x86/x86_32/entry.S	Tue Aug 23 18:25:51 2005 +0000
    35.2 +++ b/xen/arch/x86/x86_32/entry.S	Tue Aug 23 18:27:22 2005 +0000
    35.3 @@ -140,6 +140,7 @@ 1:
    35.4          jnz 2f
    35.5  
    35.6  /* vmx_restore_all_guest */
    35.7 +        call vmx_intr_assist
    35.8          call load_cr2
    35.9          .endif
   35.10          VMX_RESTORE_ALL_NOSEGREGS
    36.1 --- a/xen/arch/x86/x86_32/traps.c	Tue Aug 23 18:25:51 2005 +0000
    36.2 +++ b/xen/arch/x86/x86_32/traps.c	Tue Aug 23 18:27:22 2005 +0000
    36.3 @@ -1,5 +1,6 @@
    36.4  
    36.5  #include <xen/config.h>
    36.6 +#include <xen/domain_page.h>
    36.7  #include <xen/init.h>
    36.8  #include <xen/sched.h>
    36.9  #include <xen/lib.h>
   36.10 @@ -86,24 +87,33 @@ void show_registers(struct cpu_user_regs
   36.11  
   36.12  void show_page_walk(unsigned long addr)
   36.13  {
   36.14 -    l2_pgentry_t pmd;
   36.15 -    l1_pgentry_t *pte;
   36.16 -
   36.17 -    if ( addr < PAGE_OFFSET )
   36.18 -        return;
   36.19 +    unsigned long pfn = read_cr3() >> PAGE_SHIFT;
   36.20 +    intpte_t *ptab, ent;
   36.21  
   36.22      printk("Pagetable walk from %08lx:\n", addr);
   36.23 -    
   36.24 -    pmd = idle_pg_table_l2[l2_linear_offset(addr)];
   36.25 -    printk(" L2 = %"PRIpte" %s\n", l2e_get_intpte(pmd),
   36.26 -           (l2e_get_flags(pmd) & _PAGE_PSE) ? "(2/4MB)" : "");
   36.27 -    if ( !(l2e_get_flags(pmd) & _PAGE_PRESENT) ||
   36.28 -         (l2e_get_flags(pmd) & _PAGE_PSE) )
   36.29 +
   36.30 +#ifdef CONFIG_X86_PAE
   36.31 +    ptab = map_domain_page(pfn);
   36.32 +    ent = ptab[l3_table_offset(addr)];
   36.33 +    printk(" L3 = %"PRIpte"\n", ent);
   36.34 +    unmap_domain_page(ptab);
   36.35 +    if ( !(ent & _PAGE_PRESENT) )
   36.36          return;
   36.37 +    pfn = ent >> PAGE_SHIFT;
   36.38 +#endif
   36.39  
   36.40 -    pte  = __va(l2e_get_paddr(pmd));
   36.41 -    pte += l1_table_offset(addr);
   36.42 -    printk("  L1 = %"PRIpte"\n", l1e_get_intpte(*pte));
   36.43 +    ptab = map_domain_page(pfn);
   36.44 +    ent = ptab[l2_table_offset(addr)];
   36.45 +    printk("  L2 = %"PRIpte" %s\n", ent, (ent & _PAGE_PSE) ? "(PSE)" : "");
   36.46 +    unmap_domain_page(ptab);
   36.47 +    if ( !(ent & _PAGE_PRESENT) || (ent & _PAGE_PSE) )
   36.48 +        return;
   36.49 +    pfn = ent >> PAGE_SHIFT;
   36.50 +
   36.51 +    ptab = map_domain_page(ent >> PAGE_SHIFT);
   36.52 +    ent = ptab[l2_table_offset(addr)];
   36.53 +    printk("   L1 = %"PRIpte"\n", ent);
   36.54 +    unmap_domain_page(ptab);
   36.55  }
   36.56  
   36.57  #define DOUBLEFAULT_STACK_SIZE 1024
    37.1 --- a/xen/arch/x86/x86_64/entry.S	Tue Aug 23 18:25:51 2005 +0000
    37.2 +++ b/xen/arch/x86/x86_64/entry.S	Tue Aug 23 18:27:22 2005 +0000
    37.3 @@ -233,6 +233,7 @@ 1:
    37.4          jnz  2f 
    37.5  
    37.6  /* vmx_restore_all_guest */
    37.7 +        call vmx_intr_assist
    37.8          call load_cr2
    37.9          .endif
   37.10          /* 
    38.1 --- a/xen/include/asm-x86/vmx.h	Tue Aug 23 18:25:51 2005 +0000
    38.2 +++ b/xen/include/asm-x86/vmx.h	Tue Aug 23 18:27:22 2005 +0000
    38.3 @@ -31,7 +31,7 @@
    38.4  extern void vmx_asm_vmexit_handler(struct cpu_user_regs);
    38.5  extern void vmx_asm_do_resume(void);
    38.6  extern void vmx_asm_do_launch(void);
    38.7 -extern void vmx_intr_assist(struct vcpu *d);
    38.8 +extern void vmx_intr_assist(void);
    38.9  
   38.10  extern void arch_vmx_do_launch(struct vcpu *);
   38.11  extern void arch_vmx_do_resume(struct vcpu *);
   38.12 @@ -355,7 +355,7 @@ static inline int __vmxon (u64 addr)
   38.13  }
   38.14  
   38.15  /* Make sure that xen intercepts any FP accesses from current */
   38.16 -static inline void vmx_stts()
   38.17 +static inline void vmx_stts(void)
   38.18  {
   38.19      unsigned long cr0;
   38.20  
    39.1 --- a/xen/include/public/io/blkif.h	Tue Aug 23 18:25:51 2005 +0000
    39.2 +++ b/xen/include/public/io/blkif.h	Tue Aug 23 18:27:22 2005 +0000
    39.3 @@ -58,6 +58,9 @@ typedef struct blkif_response {
    39.4  #define BLKIF_RSP_ERROR  -1 /* non-specific 'error' */
    39.5  #define BLKIF_RSP_OKAY    0 /* non-specific 'okay'  */
    39.6  
    39.7 +#define BLKIF_MAJOR(dev) ((dev)>>8)
    39.8 +#define BLKIF_MINOR(dev) ((dev) & 0xff)
    39.9 +
   39.10  /*
   39.11   * Generate blkif ring structures and types.
   39.12   */