direct-io.hg

changeset 6475:b043928b0873

merge?
author cl349@firebug.cl.cam.ac.uk
date Tue Aug 30 16:15:27 2005 +0000 (2005-08-30)
parents 8fe8a99b1c2a 7296ed60874f
children f0bf239844a6 c8549bb0d311
files linux-2.6-xen-sparse/arch/xen/i386/kernel/pci-dma.c linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c linux-2.6-xen-sparse/drivers/xen/console/Makefile linux-2.6-xen-sparse/drivers/xen/console/console.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/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/hypercall.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/hypercall.h tools/Makefile tools/console/Makefile tools/console/daemon/io.c tools/console/daemon/utils.c tools/examples/Makefile tools/libxc/xc_core.c tools/libxc/xc_domain.c tools/libxc/xc_linux_build.c tools/libxc/xc_linux_restore.c tools/libxc/xc_private.c tools/libxc/xc_vmx_build.c tools/libxc/xenctrl.h tools/libxc/xenguest.h tools/libxc/xg_private.c tools/misc/mbootpack/Makefile tools/misc/mbootpack/buildimage.c tools/misc/mbootpack/mbootpack.c tools/misc/mbootpack/mbootpack.h tools/python/xen/lowlevel/xc/xc.c tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/image.py tools/xcs/Makefile tools/xcutils/Makefile tools/xenstat/Makefile xen/arch/x86/x86_32/entry.S xen/arch/x86/x86_64/entry.S xen/common/Makefile xen/common/memory.c xen/common/page_alloc.c xen/include/public/memory.h xen/include/public/xen.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/pci-dma.c	Tue Aug 30 16:14:53 2005 +0000
     1.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/pci-dma.c	Tue Aug 30 16:15:27 2005 +0000
     1.3 @@ -115,9 +115,9 @@ dma_supported(struct device *dev, u64 ma
     1.4  	if (swiotlb)
     1.5  		return swiotlb_dma_supported(dev, mask);
     1.6  	/*
     1.7 -         * By default we'll BUG when an infeasible DMA is requested, and
     1.8 -         * request swiotlb=force (see IOMMU_BUG_ON).
     1.9 -         */
    1.10 +	 * By default we'll BUG when an infeasible DMA is requested, and
    1.11 +	 * request swiotlb=force (see IOMMU_BUG_ON).
    1.12 +	 */
    1.13  	return 1;
    1.14  }
    1.15  EXPORT_SYMBOL(dma_supported);
     2.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c	Tue Aug 30 16:14:53 2005 +0000
     2.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c	Tue Aug 30 16:15:27 2005 +0000
     2.3 @@ -55,6 +55,7 @@
     2.4  #include <asm/io.h>
     2.5  #include <asm-xen/hypervisor.h>
     2.6  #include <asm-xen/xen-public/physdev.h>
     2.7 +#include <asm-xen/xen-public/memory.h>
     2.8  #include "setup_arch_pre.h"
     2.9  #include <bios_ebda.h>
    2.10  
    2.11 @@ -1585,15 +1586,21 @@ void __init setup_arch(char **cmdline_p)
    2.12  				(unsigned int *)xen_start_info.mfn_list,
    2.13  				xen_start_info.nr_pages * sizeof(unsigned int));
    2.14  		} else {
    2.15 +			struct xen_memory_reservation reservation = {
    2.16 +				.extent_start = (unsigned long *)xen_start_info.mfn_list + max_pfn,
    2.17 +				.nr_extents   = xen_start_info.nr_pages - max_pfn,
    2.18 +				.extent_order = 0,
    2.19 +				.domid        = DOMID_SELF
    2.20 +			};
    2.21 +
    2.22  			memcpy(phys_to_machine_mapping,
    2.23  				(unsigned int *)xen_start_info.mfn_list,
    2.24  				max_pfn * sizeof(unsigned int));
    2.25  			/* N.B. below relies on sizeof(int) == sizeof(long). */
    2.26 -			if (HYPERVISOR_dom_mem_op(
    2.27 -				MEMOP_decrease_reservation,
    2.28 -				(unsigned long *)xen_start_info.mfn_list + max_pfn,
    2.29 -				xen_start_info.nr_pages - max_pfn, 0) !=
    2.30 -			    (xen_start_info.nr_pages - max_pfn)) BUG();
    2.31 +			BUG_ON(HYPERVISOR_memory_op(
    2.32 +				XENMEM_decrease_reservation,
    2.33 +				&reservation) !=
    2.34 +			    (xen_start_info.nr_pages - max_pfn));
    2.35  		}
    2.36  		free_bootmem(
    2.37  			__pa(xen_start_info.mfn_list), 
     3.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c	Tue Aug 30 16:14:53 2005 +0000
     3.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c	Tue Aug 30 16:15:27 2005 +0000
     3.3 @@ -35,6 +35,7 @@
     3.4  #include <asm/pgtable.h>
     3.5  #include <asm-xen/hypervisor.h>
     3.6  #include <asm-xen/balloon.h>
     3.7 +#include <asm-xen/xen-public/memory.h>
     3.8  #include <linux/module.h>
     3.9  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    3.10  #include <linux/percpu.h>
    3.11 @@ -320,6 +321,12 @@ void xen_create_contiguous_region(unsign
    3.12  	pmd_t         *pmd;
    3.13  	pte_t         *pte;
    3.14  	unsigned long  mfn, i, flags;
    3.15 +	struct xen_memory_reservation reservation = {
    3.16 +		.extent_start = &mfn,
    3.17 +		.nr_extents   = 1,
    3.18 +		.extent_order = 0,
    3.19 +		.domid        = DOMID_SELF
    3.20 +	};
    3.21  
    3.22  	scrub_pages(vstart, 1 << order);
    3.23  
    3.24 @@ -336,13 +343,15 @@ void xen_create_contiguous_region(unsign
    3.25  			vstart + (i*PAGE_SIZE), __pte_ma(0), 0));
    3.26  		phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] =
    3.27  			INVALID_P2M_ENTRY;
    3.28 -		BUG_ON(HYPERVISOR_dom_mem_op(
    3.29 -			MEMOP_decrease_reservation, &mfn, 1, 0) != 1);
    3.30 +		BUG_ON(HYPERVISOR_memory_op(
    3.31 +			XENMEM_decrease_reservation, &reservation) != 1);
    3.32  	}
    3.33  
    3.34  	/* 2. Get a new contiguous memory extent. */
    3.35 -	BUG_ON(HYPERVISOR_dom_mem_op(
    3.36 -		MEMOP_increase_reservation, &mfn, 1, order | (32<<8)) != 1);
    3.37 +	reservation.extent_order = order;
    3.38 +	reservation.address_bits = 31; /* aacraid limitation */
    3.39 +	BUG_ON(HYPERVISOR_memory_op(
    3.40 +		XENMEM_increase_reservation, &reservation) != 1);
    3.41  
    3.42  	/* 3. Map the new extent in place of old pages. */
    3.43  	for (i = 0; i < (1<<order); i++) {
    3.44 @@ -367,6 +376,12 @@ void xen_destroy_contiguous_region(unsig
    3.45  	pmd_t         *pmd;
    3.46  	pte_t         *pte;
    3.47  	unsigned long  mfn, i, flags;
    3.48 +	struct xen_memory_reservation reservation = {
    3.49 +		.extent_start = &mfn,
    3.50 +		.nr_extents   = 1,
    3.51 +		.extent_order = 0,
    3.52 +		.domid        = DOMID_SELF
    3.53 +	};
    3.54  
    3.55  	scrub_pages(vstart, 1 << order);
    3.56  
    3.57 @@ -385,14 +400,14 @@ void xen_destroy_contiguous_region(unsig
    3.58  			vstart + (i*PAGE_SIZE), __pte_ma(0), 0));
    3.59  		phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] =
    3.60  			INVALID_P2M_ENTRY;
    3.61 -		BUG_ON(HYPERVISOR_dom_mem_op(
    3.62 -			MEMOP_decrease_reservation, &mfn, 1, 0) != 1);
    3.63 +		BUG_ON(HYPERVISOR_memory_op(
    3.64 +			XENMEM_decrease_reservation, &reservation) != 1);
    3.65  	}
    3.66  
    3.67  	/* 2. Map new pages in place of old pages. */
    3.68  	for (i = 0; i < (1<<order); i++) {
    3.69 -		BUG_ON(HYPERVISOR_dom_mem_op(
    3.70 -			MEMOP_increase_reservation, &mfn, 1, 0) != 1);
    3.71 +		BUG_ON(HYPERVISOR_memory_op(
    3.72 +			XENMEM_increase_reservation, &reservation) != 1);
    3.73  		BUG_ON(HYPERVISOR_update_va_mapping(
    3.74  			vstart + (i*PAGE_SIZE),
    3.75  			pfn_pte_ma(mfn, PAGE_KERNEL), 0));
     4.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c	Tue Aug 30 16:14:53 2005 +0000
     4.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c	Tue Aug 30 16:15:27 2005 +0000
     4.3 @@ -734,9 +734,9 @@ void __init setup_arch(char **cmdline_p)
     4.4  		/* Make sure we have a large enough P->M table. */
     4.5  		if (end_pfn > xen_start_info.nr_pages) {
     4.6  			phys_to_machine_mapping = alloc_bootmem(
     4.7 -				max_pfn * sizeof(u32));
     4.8 +				end_pfn * sizeof(u32));
     4.9  			memset(phys_to_machine_mapping, ~0,
    4.10 -			       max_pfn * sizeof(u32));
    4.11 +			       end_pfn * sizeof(u32));
    4.12  			memcpy(phys_to_machine_mapping,
    4.13  			       (u32 *)xen_start_info.mfn_list,
    4.14  			       xen_start_info.nr_pages * sizeof(u32));
    4.15 @@ -749,11 +749,8 @@ void __init setup_arch(char **cmdline_p)
    4.16  		pfn_to_mfn_frame_list = alloc_bootmem(PAGE_SIZE);
    4.17  
    4.18  		for ( i=0, j=0; i < end_pfn; i+=(PAGE_SIZE/sizeof(u32)), j++ )
    4.19 -		{	
    4.20  			pfn_to_mfn_frame_list[j] = 
    4.21  				virt_to_mfn(&phys_to_machine_mapping[i]);
    4.22 -		}
    4.23 -
    4.24  	}
    4.25  #endif
    4.26  
     5.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c	Tue Aug 30 16:14:53 2005 +0000
     5.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c	Tue Aug 30 16:15:27 2005 +0000
     5.3 @@ -466,7 +466,7 @@ static inline int make_readonly(unsigned
     5.4      return readonly;
     5.5  }
     5.6  
     5.7 -void __init phys_pud_init(pud_t *pud, unsigned long address, unsigned long end)
     5.8 +static void __init phys_pud_init(pud_t *pud, unsigned long address, unsigned long end)
     5.9  { 
    5.10          long i, j, k; 
    5.11          unsigned long paddr;
    5.12 @@ -502,16 +502,17 @@ void __init phys_pud_init(pud_t *pud, un
    5.13                          pte = alloc_low_page(&pte_phys);
    5.14                          pte_save = pte;
    5.15                          for (k = 0; k < PTRS_PER_PTE; pte++, k++, paddr += PTE_SIZE) {
    5.16 +                                if ((paddr >= end) ||
    5.17 +                                    ((paddr >> PAGE_SHIFT)
    5.18 +                                     >= xen_start_info.nr_pages)) { 
    5.19 +                                        __set_pte(pte, __pte(0)); 
    5.20 +                                        continue;
    5.21 +                                }
    5.22                                  if (make_readonly(paddr)) {
    5.23                                          __set_pte(pte, 
    5.24                                                  __pte(paddr | (_KERNPG_TABLE & ~_PAGE_RW)));
    5.25                                          continue;
    5.26                                  }
    5.27 -                                if (paddr >= end) { 
    5.28 -                                        for (; k < PTRS_PER_PTE; k++, pte++)
    5.29 -                                                __set_pte(pte, __pte(0)); 
    5.30 -                                        break;
    5.31 -                                }
    5.32                                  __set_pte(pte, __pte(paddr | _KERNPG_TABLE));
    5.33                          }
    5.34                          pte = pte_save;
     6.1 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Tue Aug 30 16:14:53 2005 +0000
     6.2 +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Tue Aug 30 16:15:27 2005 +0000
     6.3 @@ -44,6 +44,7 @@
     6.4  #include <asm-xen/xen_proc.h>
     6.5  #include <asm-xen/hypervisor.h>
     6.6  #include <asm-xen/balloon.h>
     6.7 +#include <asm-xen/xen-public/memory.h>
     6.8  #include <asm/pgalloc.h>
     6.9  #include <asm/pgtable.h>
    6.10  #include <asm/uaccess.h>
    6.11 @@ -168,6 +169,11 @@ static void balloon_process(void *unused
    6.12  	struct page   *page;
    6.13  	long           credit, debt, rc;
    6.14  	void          *v;
    6.15 +	struct xen_memory_reservation reservation = {
    6.16 +		.address_bits = 0,
    6.17 +		.extent_order = 0,
    6.18 +		.domid        = DOMID_SELF
    6.19 +	};
    6.20  
    6.21  	down(&balloon_mutex);
    6.22  
    6.23 @@ -180,14 +186,18 @@ static void balloon_process(void *unused
    6.24  			goto out;
    6.25  
    6.26  		balloon_lock(flags);
    6.27 -		rc = HYPERVISOR_dom_mem_op(
    6.28 -			MEMOP_increase_reservation, mfn_list, credit, 0);
    6.29 +		reservation.extent_start = mfn_list;
    6.30 +		reservation.nr_extents   = credit;
    6.31 +		rc = HYPERVISOR_memory_op(
    6.32 +			XENMEM_increase_reservation, &reservation);
    6.33  		balloon_unlock(flags);
    6.34  		if (rc < credit) {
    6.35  			/* We hit the Xen hard limit: reprobe. */
    6.36 -			BUG_ON(HYPERVISOR_dom_mem_op(
    6.37 -				MEMOP_decrease_reservation,
    6.38 -				mfn_list, rc, 0) != rc);
    6.39 +			reservation.extent_start = mfn_list;
    6.40 +			reservation.nr_extents   = rc;
    6.41 +			BUG_ON(HYPERVISOR_memory_op(
    6.42 +				XENMEM_decrease_reservation,
    6.43 +				&reservation) != rc);
    6.44  			hard_limit = current_pages + rc - driver_pages;
    6.45  			vfree(mfn_list);
    6.46  			goto retry;
    6.47 @@ -261,8 +271,10 @@ static void balloon_process(void *unused
    6.48  			balloon_append(pfn_to_page(pfn));
    6.49  		}
    6.50  
    6.51 -		BUG_ON(HYPERVISOR_dom_mem_op(
    6.52 -			MEMOP_decrease_reservation,mfn_list, debt, 0) != debt);
    6.53 +		reservation.extent_start = mfn_list;
    6.54 +		reservation.nr_extents   = debt;
    6.55 +		BUG_ON(HYPERVISOR_memory_op(
    6.56 +			XENMEM_decrease_reservation, &reservation) != debt);
    6.57  
    6.58  		current_pages -= debt;
    6.59  	}
    6.60 @@ -438,11 +450,17 @@ static int dealloc_pte_fn(
    6.61  	pte_t *pte, struct page *pte_page, unsigned long addr, void *data)
    6.62  {
    6.63  	unsigned long mfn = pte_mfn(*pte);
    6.64 +	struct xen_memory_reservation reservation = {
    6.65 +		.extent_start = &mfn,
    6.66 +		.nr_extents   = 1,
    6.67 +		.extent_order = 0,
    6.68 +		.domid        = DOMID_SELF
    6.69 +	};
    6.70  	set_pte(pte, __pte_ma(0));
    6.71  	phys_to_machine_mapping[__pa(addr) >> PAGE_SHIFT] =
    6.72  		INVALID_P2M_ENTRY;
    6.73 -	BUG_ON(HYPERVISOR_dom_mem_op(
    6.74 -		MEMOP_decrease_reservation, &mfn, 1, 0) != 1);
    6.75 +	BUG_ON(HYPERVISOR_memory_op(
    6.76 +		XENMEM_decrease_reservation, &reservation) != 1);
    6.77  	return 0;
    6.78  }
    6.79  
     7.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Tue Aug 30 16:14:53 2005 +0000
     7.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Tue Aug 30 16:15:27 2005 +0000
     7.3 @@ -12,6 +12,7 @@
     7.4  
     7.5  #include "common.h"
     7.6  #include <asm-xen/balloon.h>
     7.7 +#include <asm-xen/xen-public/memory.h>
     7.8  
     7.9  #if defined(CONFIG_XEN_NETDEV_GRANT_TX) || defined(CONFIG_XEN_NETDEV_GRANT_RX)
    7.10  #include <asm-xen/xen-public/grant_table.h>
    7.11 @@ -110,10 +111,16 @@ static spinlock_t mfn_lock = SPIN_LOCK_U
    7.12  static unsigned long alloc_mfn(void)
    7.13  {
    7.14      unsigned long mfn = 0, flags;
    7.15 +    struct xen_memory_reservation reservation = {
    7.16 +        .extent_start = mfn_list,
    7.17 +        .nr_extents   = MAX_MFN_ALLOC,
    7.18 +        .extent_order = 0,
    7.19 +        .domid        = DOMID_SELF
    7.20 +    };
    7.21      spin_lock_irqsave(&mfn_lock, flags);
    7.22      if ( unlikely(alloc_index == 0) )
    7.23 -        alloc_index = HYPERVISOR_dom_mem_op(
    7.24 -            MEMOP_increase_reservation, mfn_list, MAX_MFN_ALLOC, 0);
    7.25 +        alloc_index = HYPERVISOR_memory_op(
    7.26 +            XENMEM_increase_reservation, &reservation);
    7.27      if ( alloc_index != 0 )
    7.28          mfn = mfn_list[--alloc_index];
    7.29      spin_unlock_irqrestore(&mfn_lock, flags);
    7.30 @@ -124,11 +131,17 @@ static unsigned long alloc_mfn(void)
    7.31  static void free_mfn(unsigned long mfn)
    7.32  {
    7.33      unsigned long flags;
    7.34 +    struct xen_memory_reservation reservation = {
    7.35 +        .extent_start = &mfn,
    7.36 +        .nr_extents   = 1,
    7.37 +        .extent_order = 0,
    7.38 +        .domid        = DOMID_SELF
    7.39 +    };
    7.40      spin_lock_irqsave(&mfn_lock, flags);
    7.41      if ( alloc_index != MAX_MFN_ALLOC )
    7.42          mfn_list[alloc_index++] = mfn;
    7.43 -    else if ( HYPERVISOR_dom_mem_op(MEMOP_decrease_reservation,
    7.44 -                                    &mfn, 1, 0) != 1 )
    7.45 +    else if ( HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation)
    7.46 +              != 1 )
    7.47          BUG();
    7.48      spin_unlock_irqrestore(&mfn_lock, flags);
    7.49  }
     8.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Tue Aug 30 16:14:53 2005 +0000
     8.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Tue Aug 30 16:15:27 2005 +0000
     8.3 @@ -50,6 +50,7 @@
     8.4  #include <asm-xen/evtchn.h>
     8.5  #include <asm-xen/xenbus.h>
     8.6  #include <asm-xen/xen-public/io/netif.h>
     8.7 +#include <asm-xen/xen-public/memory.h>
     8.8  #include <asm-xen/balloon.h>
     8.9  #include <asm/page.h>
    8.10  #include <asm/uaccess.h>
    8.11 @@ -328,6 +329,7 @@ static void network_alloc_rx_buffers(str
    8.12      struct sk_buff *skb;
    8.13      int i, batch_target;
    8.14      NETIF_RING_IDX req_prod = np->rx->req_prod;
    8.15 +    struct xen_memory_reservation reservation;
    8.16  #ifdef CONFIG_XEN_NETDEV_GRANT_RX
    8.17      int ref;
    8.18  #endif
    8.19 @@ -388,12 +390,15 @@ static void network_alloc_rx_buffers(str
    8.20      rx_mcl[i-1].args[MULTI_UVMFLAGS_INDEX] = UVMF_TLB_FLUSH|UVMF_ALL;
    8.21  
    8.22      /* Give away a batch of pages. */
    8.23 -    rx_mcl[i].op = __HYPERVISOR_dom_mem_op;
    8.24 -    rx_mcl[i].args[0] = MEMOP_decrease_reservation;
    8.25 -    rx_mcl[i].args[1] = (unsigned long)rx_pfn_array;
    8.26 -    rx_mcl[i].args[2] = (unsigned long)i;
    8.27 -    rx_mcl[i].args[3] = 0;
    8.28 -    rx_mcl[i].args[4] = DOMID_SELF;
    8.29 +    rx_mcl[i].op = __HYPERVISOR_memory_op;
    8.30 +    rx_mcl[i].args[0] = XENMEM_decrease_reservation;
    8.31 +    rx_mcl[i].args[1] = (unsigned long)&reservation;
    8.32 +
    8.33 +    reservation.extent_start = rx_pfn_array;
    8.34 +    reservation.nr_extents   = i;
    8.35 +    reservation.extent_order = 0;
    8.36 +    reservation.address_bits = 0;
    8.37 +    reservation.domid        = DOMID_SELF;
    8.38  
    8.39      /* Tell the ballon driver what is going on. */
    8.40      balloon_update_driver_allowance(i);
    8.41 @@ -401,7 +406,7 @@ static void network_alloc_rx_buffers(str
    8.42      /* Zap PTEs and give away pages in one big multicall. */
    8.43      (void)HYPERVISOR_multicall(rx_mcl, i+1);
    8.44  
    8.45 -    /* Check return status of HYPERVISOR_dom_mem_op(). */
    8.46 +    /* Check return status of HYPERVISOR_memory_op(). */
    8.47      if (unlikely(rx_mcl[i].result != i))
    8.48          panic("Unable to reduce memory reservation\n");
    8.49  
     9.1 --- a/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c	Tue Aug 30 16:14:53 2005 +0000
     9.2 +++ b/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c	Tue Aug 30 16:15:27 2005 +0000
     9.3 @@ -66,7 +66,7 @@ static int privcmd_ioctl(struct inode *i
     9.4          {
     9.5              long ign1, ign2, ign3;
     9.6              __asm__ __volatile__ (
     9.7 -                "movq   %5,%%r10; movq %6,%%r8;" TRAP_INSTR
     9.8 +                "movq %8,%%r10; movq %9,%%r8;" TRAP_INSTR
     9.9                  : "=a" (ret), "=D" (ign1), "=S" (ign2), "=d" (ign3)
    9.10                  : "0" ((unsigned long)hypercall.op), 
    9.11                  "1" ((unsigned long)hypercall.arg[0]), 
    10.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Tue Aug 30 16:14:53 2005 +0000
    10.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Tue Aug 30 16:15:27 2005 +0000
    10.3 @@ -209,6 +209,7 @@ int xenbus_register_device(struct xenbus
    10.4  {
    10.5  	return xenbus_register_driver(drv, &xenbus_frontend);
    10.6  }
    10.7 +EXPORT_SYMBOL(xenbus_register_device);
    10.8  
    10.9  int xenbus_register_backend(struct xenbus_driver *drv)
   10.10  {
    11.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Tue Aug 30 16:14:53 2005 +0000
    11.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Tue Aug 30 16:15:27 2005 +0000
    11.3 @@ -246,6 +246,7 @@ void *xenbus_read(const char *dir, const
    11.4  {
    11.5  	return xs_single(XS_READ, join(dir, node), len);
    11.6  }
    11.7 +EXPORT_SYMBOL(xenbus_read);
    11.8  
    11.9  /* Write the value of a single file.
   11.10   * Returns -err on failure.  createflags can be 0, O_CREAT, or O_CREAT|O_EXCL.
   11.11 @@ -298,6 +299,7 @@ int xenbus_transaction_start(const char 
   11.12  {
   11.13  	return xs_error(xs_single(XS_TRANSACTION_START, subtree, NULL));
   11.14  }
   11.15 +EXPORT_SYMBOL(xenbus_transaction_start);
   11.16  
   11.17  /* End a transaction.
   11.18   * If abandon is true, transaction is discarded instead of committed.
   11.19 @@ -312,6 +314,7 @@ int xenbus_transaction_end(int abort)
   11.20  		strcpy(abortstr, "T");
   11.21  	return xs_error(xs_single(XS_TRANSACTION_END, abortstr, NULL));
   11.22  }
   11.23 +EXPORT_SYMBOL(xenbus_transaction_end);
   11.24  
   11.25  /* Single read and scanf: returns -errno or num scanned. */
   11.26  int xenbus_scanf(const char *dir, const char *node, const char *fmt, ...)
   11.27 @@ -333,6 +336,7 @@ int xenbus_scanf(const char *dir, const 
   11.28  		return -ERANGE;
   11.29  	return ret;
   11.30  }
   11.31 +EXPORT_SYMBOL(xenbus_scanf);
   11.32  
   11.33  /* Single printf and write: returns -errno or 0. */
   11.34  int xenbus_printf(const char *dir, const char *node, const char *fmt, ...)
   11.35 @@ -348,6 +352,7 @@ int xenbus_printf(const char *dir, const
   11.36  	BUG_ON(ret > sizeof(printf_buffer)-1);
   11.37  	return xenbus_write(dir, node, printf_buffer, O_CREAT);
   11.38  }
   11.39 +EXPORT_SYMBOL(xenbus_printf);
   11.40  
   11.41  /* Report a (negative) errno into the store, with explanation. */
   11.42  void xenbus_dev_error(struct xenbus_device *dev, int err, const char *fmt, ...)
   11.43 @@ -369,6 +374,7 @@ void xenbus_dev_error(struct xenbus_devi
   11.44  		printk("xenbus: failed to write error node for %s (%s)\n",
   11.45  		       dev->nodename, printf_buffer);
   11.46  }
   11.47 +EXPORT_SYMBOL(xenbus_dev_error);
   11.48  
   11.49  /* Clear any error. */
   11.50  void xenbus_dev_ok(struct xenbus_device *dev)
   11.51 @@ -381,6 +387,7 @@ void xenbus_dev_ok(struct xenbus_device 
   11.52  			dev->has_error = 0;
   11.53  	}
   11.54  }
   11.55 +EXPORT_SYMBOL(xenbus_dev_ok);
   11.56  	
   11.57  /* Takes tuples of names, scanf-style args, and void **, NULL terminated. */
   11.58  int xenbus_gather(const char *dir, ...)
   11.59 @@ -410,6 +417,7 @@ int xenbus_gather(const char *dir, ...)
   11.60  	va_end(ap);
   11.61  	return ret;
   11.62  }
   11.63 +EXPORT_SYMBOL(xenbus_gather);
   11.64  
   11.65  static int xs_watch(const char *path, const char *token)
   11.66  {
   11.67 @@ -482,6 +490,7 @@ int register_xenbus_watch(struct xenbus_
   11.68  		list_add(&watch->list, &watches);
   11.69  	return err;
   11.70  }
   11.71 +EXPORT_SYMBOL(register_xenbus_watch);
   11.72  
   11.73  void unregister_xenbus_watch(struct xenbus_watch *watch)
   11.74  {
   11.75 @@ -499,6 +508,7 @@ void unregister_xenbus_watch(struct xenb
   11.76  		       "XENBUS Failed to release watch %s: %i\n",
   11.77  		       watch->node, err);
   11.78  }
   11.79 +EXPORT_SYMBOL(unregister_xenbus_watch);
   11.80  
   11.81  /* Re-register callbacks to all watches. */
   11.82  void reregister_xenbus_watches(void)
    12.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/hypercall.h	Tue Aug 30 16:14:53 2005 +0000
    12.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/hypercall.h	Tue Aug 30 16:15:27 2005 +0000
    12.3 @@ -236,12 +236,10 @@ HYPERVISOR_update_descriptor(
    12.4  }
    12.5  
    12.6  static inline int
    12.7 -HYPERVISOR_dom_mem_op(
    12.8 -	unsigned int op, unsigned long *extent_list,
    12.9 -	unsigned long nr_extents, unsigned int extent_order)
   12.10 +HYPERVISOR_memory_op(
   12.11 +	unsigned int cmd, void *arg)
   12.12  {
   12.13 -	return _hypercall5(int, dom_mem_op, op, extent_list,
   12.14 -			   nr_extents, extent_order, DOMID_SELF);
   12.15 +	return _hypercall2(int, memory_op, cmd, arg);
   12.16  }
   12.17  
   12.18  static inline int
    13.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/hypercall.h	Tue Aug 30 16:14:53 2005 +0000
    13.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/hypercall.h	Tue Aug 30 16:15:27 2005 +0000
    13.3 @@ -231,12 +231,10 @@ HYPERVISOR_update_descriptor(
    13.4  }
    13.5  
    13.6  static inline int
    13.7 -HYPERVISOR_dom_mem_op(
    13.8 -	unsigned int op, unsigned long *extent_list,
    13.9 -	unsigned long nr_extents, unsigned int extent_order)
   13.10 +HYPERVISOR_memory_op(
   13.11 +	unsigned int cmd, void *arg)
   13.12  {
   13.13 -	return _hypercall5(int, dom_mem_op, op, extent_list,
   13.14 -			   nr_extents, extent_order, DOMID_SELF);
   13.15 +	return _hypercall2(int, memory_op, cmd, arg);
   13.16  }
   13.17  
   13.18  static inline int
    14.1 --- a/tools/Makefile	Tue Aug 30 16:14:53 2005 +0000
    14.2 +++ b/tools/Makefile	Tue Aug 30 16:15:27 2005 +0000
    14.3 @@ -7,15 +7,19 @@ SUBDIRS += xenstore
    14.4  SUBDIRS += misc
    14.5  SUBDIRS += examples
    14.6  SUBDIRS += xentrace
    14.7 -SUBDIRS += python
    14.8  SUBDIRS += xcs
    14.9  SUBDIRS += xcutils
   14.10 -#SUBDIRS += pygrub
   14.11  SUBDIRS += firmware
   14.12  SUBDIRS += security
   14.13  SUBDIRS += console
   14.14  SUBDIRS += xenstat
   14.15  
   14.16 +# These don't cross-compile
   14.17 +ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH))
   14.18 +SUBDIRS += python
   14.19 +#SUBDIRS += pygrub
   14.20 +endif
   14.21 +
   14.22  .PHONY: all install clean check check_clean ioemu eioemuinstall ioemuclean
   14.23  
   14.24  all: check
    15.1 --- a/tools/console/Makefile	Tue Aug 30 16:14:53 2005 +0000
    15.2 +++ b/tools/console/Makefile	Tue Aug 30 16:15:27 2005 +0000
    15.3 @@ -9,8 +9,7 @@ INSTALL         = install
    15.4  INSTALL_PROG    = $(INSTALL) -m0755
    15.5  INSTALL_DIR     = $(INSTALL) -d -m0755
    15.6  
    15.7 -CC       = gcc
    15.8 -CFLAGS   = -Wall -Werror -g3
    15.9 +CFLAGS  += -Wall -Werror -g3
   15.10  
   15.11  CFLAGS  += -I $(XEN_XCS)
   15.12  CFLAGS  += -I $(XEN_LIBXC)
    16.1 --- a/tools/examples/Makefile	Tue Aug 30 16:14:53 2005 +0000
    16.2 +++ b/tools/examples/Makefile	Tue Aug 30 16:15:27 2005 +0000
    16.3 @@ -1,3 +1,6 @@
    16.4 +XEN_ROOT = ../../
    16.5 +include $(XEN_ROOT)/tools/Rules.mk
    16.6 +
    16.7  INSTALL		= install
    16.8  INSTALL_DIR	= $(INSTALL) -d -m0755
    16.9  INSTALL_PROG	= $(INSTALL) -m0755
    17.1 --- a/tools/libxc/xc_core.c	Tue Aug 30 16:14:53 2005 +0000
    17.2 +++ b/tools/libxc/xc_core.c	Tue Aug 30 16:15:27 2005 +0000
    17.3 @@ -2,6 +2,7 @@
    17.4  #define ELFSIZE 32
    17.5  #include "xc_elf.h"
    17.6  #include <stdlib.h>
    17.7 +#include <unistd.h>
    17.8  #include <zlib.h>
    17.9  
   17.10  /* number of pages to write at a time */
    18.1 --- a/tools/libxc/xc_domain.c	Tue Aug 30 16:14:53 2005 +0000
    18.2 +++ b/tools/libxc/xc_domain.c	Tue Aug 30 16:15:27 2005 +0000
    18.3 @@ -7,6 +7,7 @@
    18.4   */
    18.5  
    18.6  #include "xc_private.h"
    18.7 +#include <xen/memory.h>
    18.8  
    18.9  int xc_domain_create(int xc_handle,
   18.10                       u32 ssidref,
   18.11 @@ -265,9 +266,13 @@ int xc_domain_memory_increase_reservatio
   18.12  {
   18.13      int err;
   18.14      unsigned int npages = mem_kb / (PAGE_SIZE/1024);
   18.15 +    struct xen_memory_reservation reservation = {
   18.16 +        .nr_extents   = npages,
   18.17 +        .extent_order = 0,
   18.18 +        .domid        = domid
   18.19 +    };
   18.20  
   18.21 -    err = xc_dom_mem_op(xc_handle, MEMOP_increase_reservation, NULL,
   18.22 -                        npages, 0, domid);
   18.23 +    err = xc_memory_op(xc_handle, XENMEM_increase_reservation, &reservation);
   18.24      if (err == npages)
   18.25          return 0;
   18.26  
    19.1 --- a/tools/libxc/xc_linux_build.c	Tue Aug 30 16:14:53 2005 +0000
    19.2 +++ b/tools/libxc/xc_linux_build.c	Tue Aug 30 16:15:27 2005 +0000
    19.3 @@ -17,6 +17,7 @@
    19.4  #include "xc_elf.h"
    19.5  #include "xc_aout9.h"
    19.6  #include <stdlib.h>
    19.7 +#include <unistd.h>
    19.8  #include <zlib.h>
    19.9  
   19.10  #if defined(__i386__)
    20.1 --- a/tools/libxc/xc_linux_restore.c	Tue Aug 30 16:14:53 2005 +0000
    20.2 +++ b/tools/libxc/xc_linux_restore.c	Tue Aug 30 16:15:27 2005 +0000
    20.3 @@ -8,11 +8,10 @@
    20.4  
    20.5  #include <stdlib.h>
    20.6  #include <unistd.h>
    20.7 -
    20.8  #include "xg_private.h"
    20.9  #include <xenctrl.h>
   20.10 -
   20.11  #include <xen/linux/suspend.h>
   20.12 +#include <xen/memory.h>
   20.13  
   20.14  #define MAX_BATCH_SIZE 1024
   20.15  
   20.16 @@ -411,7 +410,8 @@ int xc_linux_restore(int xc_handle, int 
   20.17  
   20.18      /* Get the list of PFNs that are not in the psuedo-phys map */
   20.19      {
   20.20 -	unsigned int count, *pfntab;
   20.21 +	unsigned int count;
   20.22 +        unsigned long *pfntab;
   20.23  	int rc;
   20.24  
   20.25  	if ( read_exact(io_fd, &count, sizeof(count)) != sizeof(count) )
   20.26 @@ -443,9 +443,15 @@ int xc_linux_restore(int xc_handle, int 
   20.27  
   20.28  	if ( count > 0 )
   20.29  	{
   20.30 -	    if ( (rc = xc_dom_mem_op( xc_handle,
   20.31 -				       MEMOP_decrease_reservation,
   20.32 -				       pfntab, count, 0, dom )) <0 )
   20.33 +            struct xen_memory_reservation reservation = {
   20.34 +                .extent_start = pfntab,
   20.35 +                .nr_extents   = count,
   20.36 +                .extent_order = 0,
   20.37 +                .domid        = dom
   20.38 +            };
   20.39 +	    if ( (rc = xc_memory_op(xc_handle,
   20.40 +                                    XENMEM_decrease_reservation,
   20.41 +                                    &reservation)) != count )
   20.42  	    {
   20.43  		ERR("Could not decrease reservation : %d",rc);
   20.44  		goto out;
    21.1 --- a/tools/libxc/xc_private.c	Tue Aug 30 16:14:53 2005 +0000
    21.2 +++ b/tools/libxc/xc_private.c	Tue Aug 30 16:15:27 2005 +0000
    21.3 @@ -6,6 +6,7 @@
    21.4  
    21.5  #include <zlib.h>
    21.6  #include "xc_private.h"
    21.7 +#include <xen/memory.h>
    21.8  
    21.9  void *xc_map_foreign_batch(int xc_handle, u32 dom, int prot,
   21.10                             unsigned long *arr, int num )
   21.11 @@ -187,28 +188,43 @@ int xc_finish_mmu_updates(int xc_handle,
   21.12      return flush_mmu_updates(xc_handle, mmu);
   21.13  }
   21.14  
   21.15 -int xc_dom_mem_op(int xc_handle,
   21.16 -		  unsigned int memop, 
   21.17 -		  unsigned int *extent_list, 
   21.18 -		  unsigned int nr_extents,
   21.19 -		  unsigned int extent_order,
   21.20 -		  domid_t domid)
   21.21 +int xc_memory_op(int xc_handle,
   21.22 +                 int cmd,
   21.23 +                 void *arg)
   21.24  {
   21.25      privcmd_hypercall_t hypercall;
   21.26 +    struct xen_memory_reservation *reservation = arg;
   21.27      long ret = -EINVAL;
   21.28  
   21.29 -    hypercall.op     = __HYPERVISOR_dom_mem_op;
   21.30 -    hypercall.arg[0] = (unsigned long)memop;
   21.31 -    hypercall.arg[1] = (unsigned long)extent_list;
   21.32 -    hypercall.arg[2] = (unsigned long)nr_extents;
   21.33 -    hypercall.arg[3] = (unsigned long)extent_order;
   21.34 -    hypercall.arg[4] = (unsigned long)domid;
   21.35 +    hypercall.op     = __HYPERVISOR_memory_op;
   21.36 +    hypercall.arg[0] = (unsigned long)cmd;
   21.37 +    hypercall.arg[1] = (unsigned long)arg;
   21.38  
   21.39 -    if ( (extent_list != NULL) && 
   21.40 -         (mlock(extent_list, nr_extents*sizeof(unsigned long)) != 0) )
   21.41 +    switch ( cmd )
   21.42      {
   21.43 -        PERROR("Could not lock memory for Xen hypercall");
   21.44 -        goto out1;
   21.45 +    case XENMEM_increase_reservation:
   21.46 +    case XENMEM_decrease_reservation:
   21.47 +        if ( mlock(reservation, sizeof(*reservation)) != 0 )
   21.48 +        {
   21.49 +            PERROR("Could not mlock");
   21.50 +            goto out1;
   21.51 +        }
   21.52 +        if ( (reservation->extent_start != NULL) &&
   21.53 +             (mlock(reservation->extent_start,
   21.54 +                    reservation->nr_extents * sizeof(unsigned long)) != 0) )
   21.55 +        {
   21.56 +            PERROR("Could not mlock");
   21.57 +            safe_munlock(reservation, sizeof(*reservation));
   21.58 +            goto out1;
   21.59 +        }
   21.60 +        break;
   21.61 +    case XENMEM_maximum_ram_page:
   21.62 +        if ( mlock(arg, sizeof(unsigned long)) != 0 )
   21.63 +        {
   21.64 +            PERROR("Could not mlock");
   21.65 +            goto out1;
   21.66 +        }
   21.67 +        break;
   21.68      }
   21.69  
   21.70      if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
   21.71 @@ -217,8 +233,19 @@ int xc_dom_mem_op(int xc_handle,
   21.72                  " rebuild the user-space tool set?\n",ret,errno);
   21.73      }
   21.74  
   21.75 -    if ( extent_list != NULL )
   21.76 -        safe_munlock(extent_list, nr_extents*sizeof(unsigned long));
   21.77 +    switch ( cmd )
   21.78 +    {
   21.79 +    case XENMEM_increase_reservation:
   21.80 +    case XENMEM_decrease_reservation:
   21.81 +        safe_munlock(reservation, sizeof(*reservation));
   21.82 +        if ( reservation->extent_start != NULL )
   21.83 +            safe_munlock(reservation->extent_start,
   21.84 +                         reservation->nr_extents * sizeof(unsigned long));
   21.85 +        break;
   21.86 +    case XENMEM_maximum_ram_page:
   21.87 +        safe_munlock(arg, sizeof(unsigned long));
   21.88 +        break;
   21.89 +    }
   21.90  
   21.91   out1:
   21.92      return ret;
    22.1 --- a/tools/libxc/xc_vmx_build.c	Tue Aug 30 16:14:53 2005 +0000
    22.2 +++ b/tools/libxc/xc_vmx_build.c	Tue Aug 30 16:15:27 2005 +0000
    22.3 @@ -7,6 +7,7 @@
    22.4  #define ELFSIZE 32
    22.5  #include "xc_elf.h"
    22.6  #include <stdlib.h>
    22.7 +#include <unistd.h>
    22.8  #include <zlib.h>
    22.9  #include <xen/io/ioreq.h>
   22.10  #include "linux_boot_params.h"
    23.1 --- a/tools/libxc/xenctrl.h	Tue Aug 30 16:14:53 2005 +0000
    23.2 +++ b/tools/libxc/xenctrl.h	Tue Aug 30 16:15:27 2005 +0000
    23.3 @@ -430,9 +430,7 @@ int xc_ia64_get_pfn_list(int xc_handle, 
    23.4  int xc_mmuext_op(int xc_handle, struct mmuext_op *op, unsigned int nr_ops,
    23.5  		 domid_t dom);
    23.6  
    23.7 -int xc_dom_mem_op(int xc_handle, unsigned int memop, unsigned int *extent_list,
    23.8 -		  unsigned int nr_extents, unsigned int extent_order,
    23.9 -		  domid_t domid);
   23.10 +int xc_memory_op(int xc_handle, int cmd, void *arg);
   23.11  
   23.12  int xc_get_pfn_type_batch(int xc_handle, u32 dom, int num, unsigned long *arr);
   23.13  
    24.1 --- a/tools/libxc/xg_private.c	Tue Aug 30 16:14:53 2005 +0000
    24.2 +++ b/tools/libxc/xg_private.c	Tue Aug 30 16:15:27 2005 +0000
    24.3 @@ -5,6 +5,7 @@
    24.4   */
    24.5  
    24.6  #include <stdlib.h>
    24.7 +#include <unistd.h>
    24.8  #include <zlib.h>
    24.9  
   24.10  #include "xg_private.h"
    25.1 --- a/tools/misc/mbootpack/Makefile	Tue Aug 30 16:14:53 2005 +0000
    25.2 +++ b/tools/misc/mbootpack/Makefile	Tue Aug 30 16:15:27 2005 +0000
    25.3 @@ -20,8 +20,7 @@ GDB	:= gdb
    25.4  INCS	:= -I. -I-
    25.5  DEFS	:= 
    25.6  LDFLAGS	:= 
    25.7 -CC	:= gcc
    25.8 -CFLAGS 	:= -Wall -Wpointer-arith -Wcast-qual -Wno-unused -Wno-format
    25.9 +CFLAGS	:= -Wall -Wpointer-arith -Wcast-qual -Wno-unused -Wno-format
   25.10  CFLAGS	+= -Wmissing-prototypes
   25.11  #CFLAGS	+= -pipe -g -O0 -Wcast-align
   25.12  CFLAGS	+= -pipe -O3 
   25.13 @@ -34,7 +33,7 @@ DEPFLAGS = -Wp,-MD,.$(@F).d
   25.14  DEPS     = .*.d
   25.15  
   25.16  mbootpack: $(OBJS)
   25.17 -	$(CC) -o $@ $(filter-out %.a, $^) $(LDFLAGS)
   25.18 +	$(HOSTCC) -o $@ $(filter-out %.a, $^) $(LDFLAGS)
   25.19  
   25.20  clean:
   25.21  	$(RM) mbootpack *.o $(DEPS) bootsect setup bzimage_header.c bin2c
   25.22 @@ -48,7 +47,7 @@ setup: setup.S
   25.23  	$(LD) -m elf_i386 -Ttext 0x0 -s --oformat binary setup.o -o $@
   25.24  
   25.25  bin2c: bin2c.o 
   25.26 -	$(CC) -o $@ $^ 
   25.27 +	$(HOSTCC) -o $@ $^ 
   25.28  
   25.29  bzimage_header.c: bootsect setup bin2c
   25.30  	./bin2c -n 8 -b1 -a bzimage_bootsect bootsect > bzimage_header.c
   25.31 @@ -58,10 +57,10 @@ buildimage.c: bzimage_header.c
   25.32  	@
   25.33  
   25.34  %.o: %.S
   25.35 -	$(CC) $(DEPFLAGS) $(CFLAGS) $(INCS) $(DEFS) -c $< -o $@
   25.36 +	$(HOSTCC) $(DEPFLAGS) $(CFLAGS) $(INCS) $(DEFS) -c $< -o $@
   25.37  
   25.38  %.o: %.c
   25.39 -	$(CC) $(DEPFLAGS) $(CFLAGS) $(INCS) $(DEFS) -c $< -o $@
   25.40 +	$(HOSTCC) $(DEPFLAGS) $(CFLAGS) $(INCS) $(DEFS) -c $< -o $@
   25.41  
   25.42  .PHONY: all clean gdb
   25.43  .PRECIOUS: $(OBJS) $(OBJS:.o=.c) $(DEPS)
    26.1 --- a/tools/misc/mbootpack/buildimage.c	Tue Aug 30 16:14:53 2005 +0000
    26.2 +++ b/tools/misc/mbootpack/buildimage.c	Tue Aug 30 16:15:27 2005 +0000
    26.3 @@ -43,6 +43,7 @@
    26.4  #include "mbootpack.h"
    26.5  #include "mb_header.h"
    26.6  
    26.7 +
    26.8  /*  We will build an image that a bzImage-capable bootloader will load like 
    26.9   *  this:
   26.10   * 
   26.11 @@ -105,8 +106,8 @@ void make_bzImage(section_t *sections,
   26.12      section_t *s;
   26.13  
   26.14      /* Patch the kernel and mbi addresses into the setup code */
   26.15 -    *(address_t *)(bzimage_setup + BZ_ENTRY_OFFSET) = entry;
   26.16 -    *(address_t *)(bzimage_setup + BZ_MBI_OFFSET) = mbi;
   26.17 +    *(address_t *)(bzimage_setup + BZ_ENTRY_OFFSET) = eswap(entry);
   26.18 +    *(address_t *)(bzimage_setup + BZ_MBI_OFFSET) = eswap(mbi);
   26.19      if (!quiet) printf("Kernel entry is %p, MBI is %p.\n", entry, mbi);
   26.20  
   26.21      /* Write out header and trampoline */
    27.1 --- a/tools/misc/mbootpack/mbootpack.c	Tue Aug 30 16:14:53 2005 +0000
    27.2 +++ b/tools/misc/mbootpack/mbootpack.c	Tue Aug 30 16:15:27 2005 +0000
    27.3 @@ -252,20 +252,21 @@ static address_t load_kernel(const char 
    27.4      for (i = 0; i <= MIN(len - 12, MULTIBOOT_SEARCH - 12); i += 4)
    27.5      {
    27.6          mbh = (struct multiboot_header *)(headerbuf + i);
    27.7 -        if (mbh->magic != MULTIBOOT_MAGIC 
    27.8 -            || ((mbh->magic+mbh->flags+mbh->checksum) & 0xffffffff))
    27.9 +        if (eswap(mbh->magic) != MULTIBOOT_MAGIC 
   27.10 +            || ((eswap(mbh->magic)+eswap(mbh->flags)+eswap(mbh->checksum)) 
   27.11 +				& 0xffffffff))
   27.12          {
   27.13              /* Not a multiboot header */
   27.14              continue;
   27.15          }
   27.16 -        if (mbh->flags & MULTIBOOT_UNSUPPORTED) {
   27.17 +        if (eswap(mbh->flags) & MULTIBOOT_UNSUPPORTED) {
   27.18              /* Requires options we don't support */
   27.19              printf("Fatal: found a multiboot header, but it "
   27.20                      "requires multiboot options that I\n"
   27.21                      "don't understand.  Sorry.\n");
   27.22              exit(1);
   27.23          } 
   27.24 -        if (mbh->flags & MULTIBOOT_VIDEO_MODE) { 
   27.25 +        if (eswap(mbh->flags) & MULTIBOOT_VIDEO_MODE) { 
   27.26              /* Asked for screen mode information */
   27.27              /* XXX carry on regardless */
   27.28              printf("Warning: found a multiboot header which asks "
   27.29 @@ -275,22 +276,22 @@ static address_t load_kernel(const char 
   27.30          }
   27.31          /* This kernel will do: place and load it */
   27.32  
   27.33 -        if (mbh->flags & MULTIBOOT_AOUT_KLUDGE) {
   27.34 +        if (eswap(mbh->flags) & MULTIBOOT_AOUT_KLUDGE) {
   27.35  
   27.36              /* Load using the offsets in the multiboot header */
   27.37              if(!quiet) 
   27.38                  printf("Loading %s using multiboot header.\n", filename);
   27.39  
   27.40              /* How much is there? */
   27.41 -            start = mbh->load_addr;            
   27.42 -            if (mbh->load_end_addr != 0) 
   27.43 -                loadsize = mbh->load_end_addr - mbh->load_addr;
   27.44 +            start = eswap(mbh->load_addr);            
   27.45 +            if (eswap(mbh->load_end_addr) != 0) 
   27.46 +                loadsize = eswap(mbh->load_end_addr) - eswap(mbh->load_addr);
   27.47              else 
   27.48                  loadsize = sb.st_size;
   27.49              
   27.50              /* How much memory will it take up? */ 
   27.51 -            if (mbh->bss_end_addr != 0)
   27.52 -                size = mbh->bss_end_addr - mbh->load_addr;
   27.53 +            if (eswap(mbh->bss_end_addr) != 0)
   27.54 +                size = eswap(mbh->bss_end_addr) - eswap(mbh->load_addr);
   27.55              else
   27.56                  size = loadsize;
   27.57              
   27.58 @@ -335,32 +336,34 @@ static address_t load_kernel(const char 
   27.59              
   27.60              /* Done. */
   27.61              if (!quiet) printf("Loaded kernel from %s\n", filename);
   27.62 -            return mbh->entry_addr;
   27.63 +            return eswap(mbh->entry_addr);
   27.64              
   27.65          } else {
   27.66  
   27.67              /* Now look for an ELF32 header */    
   27.68              ehdr = (Elf32_Ehdr *)headerbuf;
   27.69 -            if (*(unsigned long *)ehdr != 0x464c457f 
   27.70 +            if (*(unsigned long *)ehdr != eswap(0x464c457f)
   27.71                  || ehdr->e_ident[EI_DATA] != ELFDATA2LSB
   27.72                  || ehdr->e_ident[EI_CLASS] != ELFCLASS32
   27.73 -                || ehdr->e_machine != EM_386)
   27.74 +                || eswap(ehdr->e_machine) != EM_386)
   27.75              {
   27.76                  printf("Fatal: kernel has neither ELF32/x86 nor multiboot load"
   27.77                         " headers.\n");
   27.78                  exit(1);
   27.79              }
   27.80 -            if (ehdr->e_phoff + ehdr->e_phnum*sizeof(*phdr) > HEADERBUF_SIZE) {
   27.81 +            if (eswap(ehdr->e_phoff) + eswap(ehdr->e_phnum)*sizeof(*phdr) 
   27.82 +				> HEADERBUF_SIZE) {
   27.83                  /* Don't expect this will happen with sane kernels */
   27.84                  printf("Fatal: too much ELF for me.  Try increasing "
   27.85                         "HEADERBUF_SIZE in mbootpack.\n");
   27.86                  exit(1);
   27.87              }
   27.88 -            if (ehdr->e_phoff + ehdr->e_phnum*sizeof (*phdr) > len) {
   27.89 +            if (eswap(ehdr->e_phoff) + eswap(ehdr->e_phnum)*sizeof (*phdr) 
   27.90 +				> len) {
   27.91                  printf("Fatal: malformed ELF header overruns EOF.\n");
   27.92                  exit(1);
   27.93              }
   27.94 -            if (ehdr->e_phnum <= 0) {
   27.95 +            if (eswap(ehdr->e_phnum) <= 0) {
   27.96                  printf("Fatal: ELF kernel has no program headers.\n");
   27.97                  exit(1);
   27.98              }
   27.99 @@ -368,22 +371,22 @@ static address_t load_kernel(const char 
  27.100              if(!quiet) 
  27.101                  printf("Loading %s using ELF header.\n", filename);
  27.102  
  27.103 -            if (ehdr->e_type != ET_EXEC 
  27.104 -                || ehdr->e_version != EV_CURRENT
  27.105 -                || ehdr->e_phentsize != sizeof (Elf32_Phdr)) {
  27.106 +            if (eswap(ehdr->e_type) != ET_EXEC 
  27.107 +                || eswap(ehdr->e_version) != EV_CURRENT
  27.108 +                || eswap(ehdr->e_phentsize) != sizeof (Elf32_Phdr)) {
  27.109                  printf("Warning: funny-looking ELF header.\n");
  27.110              }
  27.111 -            phdr = (Elf32_Phdr *)(headerbuf + ehdr->e_phoff);
  27.112 +            phdr = (Elf32_Phdr *)(headerbuf + eswap(ehdr->e_phoff));
  27.113  
  27.114              /* Obey the program headers to load the kernel */
  27.115 -            for(i = 0; i < ehdr->e_phnum; i++) {
  27.116 +            for(i = 0; i < eswap(ehdr->e_phnum); i++) {
  27.117  
  27.118 -                start = phdr[i].p_paddr;
  27.119 -                size = phdr[i].p_memsz;
  27.120 -                if (phdr[i].p_type != PT_LOAD) 
  27.121 +                start = eswap(phdr[i].p_paddr);
  27.122 +                size = eswap(phdr[i].p_memsz);
  27.123 +                if (eswap(phdr[i].p_type) != PT_LOAD) 
  27.124                      loadsize = 0;
  27.125                  else 
  27.126 -                    loadsize = MIN((long int)phdr[i].p_filesz, size);
  27.127 +                    loadsize = MIN((long int)eswap(phdr[i].p_filesz), size);
  27.128  
  27.129                  if ((buffer = malloc(size)) == NULL) {
  27.130                      printf("Fatal: malloc() for kernel load failed: %s\n",
  27.131 @@ -396,7 +399,7 @@ static address_t load_kernel(const char 
  27.132  
  27.133                  /* Load section from file */ 
  27.134                  if (loadsize > 0) {
  27.135 -                    if (fseek(fp, phdr[i].p_offset, SEEK_SET) != 0) {
  27.136 +                    if (fseek(fp, eswap(phdr[i].p_offset), SEEK_SET) != 0) {
  27.137                          printf("Fatal: seek failed in %s\n",
  27.138                                  strerror(errno));
  27.139                          exit(1);
  27.140 @@ -452,7 +455,7 @@ static address_t load_kernel(const char 
  27.141           
  27.142              /* Done! */
  27.143              if (!quiet) printf("Loaded kernel from %s\n", filename);
  27.144 -            return ehdr->e_entry;
  27.145 +            return eswap(ehdr->e_entry);
  27.146          }
  27.147  
  27.148      }
  27.149 @@ -568,12 +571,12 @@ int main(int argc, char **argv)
  27.150      /* Command line */
  27.151      p = (char *)(mbi + 1);
  27.152      sprintf(p, "%s %s", imagename, command_line);
  27.153 -    mbi->cmdline = ((address_t)p) + mbi_reloc_offset;
  27.154 +    mbi->cmdline = eswap(((address_t)p) + mbi_reloc_offset);
  27.155      p += command_line_len;
  27.156  
  27.157      /* Bootloader ID */
  27.158      sprintf(p, version_string);
  27.159 -    mbi->boot_loader_name = ((address_t)p) + mbi_reloc_offset;
  27.160 +    mbi->boot_loader_name = eswap(((address_t)p) + mbi_reloc_offset);
  27.161      p += strlen(version_string) + 1;
  27.162  
  27.163      /* Next is space for the module command lines */
  27.164 @@ -582,17 +585,17 @@ int main(int argc, char **argv)
  27.165      /* Last come the module info structs */
  27.166      modp = (struct mod_list *)
  27.167          ((((address_t)p + mod_command_line_space) + 3) & ~3);
  27.168 -    mbi->mods_count = modules;
  27.169 -    mbi->mods_addr = ((address_t)modp) + mbi_reloc_offset;
  27.170 +    mbi->mods_count = eswap(modules);
  27.171 +    mbi->mods_addr = eswap(((address_t)modp) + mbi_reloc_offset);
  27.172  
  27.173      /* Memory information will be added at boot time, by setup.S 
  27.174       * or trampoline.S. */
  27.175 -    mbi->flags = MB_INFO_CMDLINE | MB_INFO_BOOT_LOADER_NAME;
  27.176 +    mbi->flags = eswap(MB_INFO_CMDLINE | MB_INFO_BOOT_LOADER_NAME);
  27.177  
  27.178  
  27.179      /* Load the modules */
  27.180      if (modules) {
  27.181 -        mbi->flags |= MB_INFO_MODS;
  27.182 +        mbi->flags = eswap(eswap(mbi->flags) | MB_INFO_MODS);
  27.183                  
  27.184          /* Go back and parse the module command lines */
  27.185          optind = opterr = 1;
  27.186 @@ -652,10 +655,10 @@ int main(int argc, char **argv)
  27.187              if (p != NULL) *p = ' ';
  27.188  
  27.189              /* Fill in the module info struct */
  27.190 -            modp->mod_start = start;
  27.191 -            modp->mod_end = start + size;
  27.192 -            modp->cmdline = (address_t)mod_clp + mbi_reloc_offset;
  27.193 -            modp->pad = 0;
  27.194 +            modp->mod_start = eswap(start);
  27.195 +            modp->mod_end = eswap(start + size);
  27.196 +            modp->cmdline = eswap((address_t)mod_clp + mbi_reloc_offset);
  27.197 +            modp->pad = eswap(0);
  27.198              modp++;
  27.199  
  27.200              /* Store the module command line */
    28.1 --- a/tools/misc/mbootpack/mbootpack.h	Tue Aug 30 16:14:53 2005 +0000
    28.2 +++ b/tools/misc/mbootpack/mbootpack.h	Tue Aug 30 16:15:27 2005 +0000
    28.3 @@ -32,6 +32,24 @@
    28.4  #undef NDEBUG
    28.5  #include <stdio.h>
    28.6  
    28.7 +#include <endian.h>
    28.8 +#include <byteswap.h>
    28.9 +#if __BYTE_ORDER == __LITTLE_ENDIAN
   28.10 +#define eswap(x) (x)
   28.11 +#else 
   28.12 +#define eswap(x)                                               \
   28.13 +        ({                                                      \
   28.14 +               typeof(x) y = (x);                              \
   28.15 +               switch(sizeof(y))                               \
   28.16 +               {                                               \
   28.17 +               case 2: y = __bswap_16(y); break;               \
   28.18 +               case 4: y = __bswap_32(y); break;               \
   28.19 +               case 8: y = __bswap_64(y); break;               \
   28.20 +               }                                               \
   28.21 +               y;                                              \
   28.22 +        })	
   28.23 +#endif			
   28.24 +
   28.25  /* Flags */
   28.26  extern int quiet;
   28.27  
    29.1 --- a/tools/xcs/Makefile	Tue Aug 30 16:14:53 2005 +0000
    29.2 +++ b/tools/xcs/Makefile	Tue Aug 30 16:15:27 2005 +0000
    29.3 @@ -10,8 +10,7 @@ INSTALL         = install
    29.4  INSTALL_PROG    = $(INSTALL) -m0755
    29.5  INSTALL_DIR     = $(INSTALL) -d -m0755
    29.6  
    29.7 -CC       = gcc
    29.8 -CFLAGS   = -Wall -Werror -g3 -D _XOPEN_SOURCE=600
    29.9 +CFLAGS   += -Wall -Werror -g3 -D _XOPEN_SOURCE=600
   29.10  
   29.11  CFLAGS  += -I $(XEN_XC)
   29.12  CFLAGS  += -I $(XEN_LIBXC)
    30.1 --- a/tools/xcutils/Makefile	Tue Aug 30 16:14:53 2005 +0000
    30.2 +++ b/tools/xcutils/Makefile	Tue Aug 30 16:15:27 2005 +0000
    30.3 @@ -19,8 +19,6 @@ PROGRAMS_INSTALL_DIR	= /usr/libexec/xen
    30.4  
    30.5  INCLUDES += -I $(XEN_LIBXC)
    30.6  
    30.7 -CC := gcc
    30.8 -
    30.9  CFLAGS += -Wall -Werror -O3 -fno-strict-aliasing
   30.10  CFLAGS += $(INCLUDES)
   30.11  
    31.1 --- a/tools/xenstat/Makefile	Tue Aug 30 16:14:53 2005 +0000
    31.2 +++ b/tools/xenstat/Makefile	Tue Aug 30 16:15:27 2005 +0000
    31.3 @@ -3,7 +3,11 @@ include $(XEN_ROOT)/tools/Rules.mk
    31.4  
    31.5  SUBDIRS :=
    31.6  SUBDIRS += libxenstat
    31.7 +
    31.8 +# This doesn't cross-compile (cross-compile environments rarely have curses)
    31.9 +ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH))
   31.10  SUBDIRS += xentop
   31.11 +endif
   31.12  
   31.13  .PHONY: all install clean
   31.14  
    32.1 --- a/xen/arch/x86/x86_32/entry.S	Tue Aug 30 16:14:53 2005 +0000
    32.2 +++ b/xen/arch/x86/x86_32/entry.S	Tue Aug 30 16:15:27 2005 +0000
    32.3 @@ -790,7 +790,7 @@ ENTRY(hypercall_table)
    32.4          .long do_get_debugreg
    32.5          .long do_update_descriptor  /* 10 */
    32.6          .long do_ni_hypercall
    32.7 -        .long do_dom_mem_op
    32.8 +        .long do_memory_op
    32.9          .long do_multicall
   32.10          .long do_update_va_mapping
   32.11          .long do_set_timer_op       /* 15 */
   32.12 @@ -823,7 +823,7 @@ ENTRY(hypercall_args_table)
   32.13          .byte 1 /* do_get_debugreg      */
   32.14          .byte 4 /* do_update_descriptor */  /* 10 */
   32.15          .byte 0 /* do_ni_hypercall      */
   32.16 -        .byte 5 /* do_dom_mem_op        */
   32.17 +        .byte 2 /* do_memory_op         */
   32.18          .byte 2 /* do_multicall         */
   32.19          .byte 4 /* do_update_va_mapping */
   32.20          .byte 2 /* do_set_timer_op      */  /* 15 */
    33.1 --- a/xen/arch/x86/x86_64/entry.S	Tue Aug 30 16:14:53 2005 +0000
    33.2 +++ b/xen/arch/x86/x86_64/entry.S	Tue Aug 30 16:15:27 2005 +0000
    33.3 @@ -616,7 +616,7 @@ ENTRY(hypercall_table)
    33.4          .quad do_get_debugreg
    33.5          .quad do_update_descriptor  /* 10 */
    33.6          .quad do_ni_hypercall
    33.7 -        .quad do_dom_mem_op
    33.8 +        .quad do_memory_op
    33.9          .quad do_multicall
   33.10          .quad do_update_va_mapping
   33.11          .quad do_set_timer_op       /* 15 */
   33.12 @@ -649,7 +649,7 @@ ENTRY(hypercall_args_table)
   33.13          .byte 1 /* do_get_debugreg      */
   33.14          .byte 2 /* do_update_descriptor */  /* 10 */
   33.15          .byte 0 /* do_ni_hypercall      */
   33.16 -        .byte 5 /* do_dom_mem_op        */
   33.17 +        .byte 2 /* do_memory_op         */
   33.18          .byte 2 /* do_multicall         */
   33.19          .byte 3 /* do_update_va_mapping */
   33.20          .byte 1 /* do_set_timer_op      */  /* 15 */
    34.1 --- a/xen/common/Makefile	Tue Aug 30 16:14:53 2005 +0000
    34.2 +++ b/xen/common/Makefile	Tue Aug 30 16:15:27 2005 +0000
    34.3 @@ -2,7 +2,6 @@
    34.4  include $(BASEDIR)/Rules.mk
    34.5  
    34.6  ifeq ($(TARGET_ARCH),ia64)
    34.7 -#OBJS := $(subst dom_mem_ops.o,,$(OBJS))
    34.8  OBJS := $(subst grant_table.o,,$(OBJS))
    34.9  endif
   34.10  
    35.1 --- a/xen/common/dom_mem_ops.c	Tue Aug 30 16:14:53 2005 +0000
    35.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.3 @@ -1,186 +0,0 @@
    35.4 -/******************************************************************************
    35.5 - * dom_mem_ops.c
    35.6 - *
    35.7 - * Code to handle memory related requests from domains eg. balloon driver.
    35.8 - *
    35.9 - * Copyright (c) 2003-2004, B Dragovic & K A Fraser.
   35.10 - */
   35.11 -
   35.12 -#include <xen/config.h>
   35.13 -#include <xen/types.h>
   35.14 -#include <xen/lib.h>
   35.15 -#include <xen/mm.h>
   35.16 -#include <xen/perfc.h>
   35.17 -#include <xen/sched.h>
   35.18 -#include <xen/event.h>
   35.19 -#include <xen/shadow.h>
   35.20 -#include <asm/current.h>
   35.21 -#include <asm/hardirq.h>
   35.22 -
   35.23 -/*
   35.24 - * To allow safe resume of do_dom_mem_op() after preemption, we need to know 
   35.25 - * at what point in the page list to resume. For this purpose I steal the 
   35.26 - * high-order bits of the @op parameter, which are otherwise unused and zero.
   35.27 - */
   35.28 -#define START_EXTENT_SHIFT 4 /* op[:4] == start_extent */
   35.29 -
   35.30 -#define PREEMPT_CHECK(_op)                          \
   35.31 -    if ( hypercall_preempt_check() )                \
   35.32 -        return hypercall5_create_continuation(      \
   35.33 -            __HYPERVISOR_dom_mem_op,                \
   35.34 -            (_op) | (i << START_EXTENT_SHIFT),      \
   35.35 -            extent_list, nr_extents, extent_order,  \
   35.36 -            (d == current->domain) ? DOMID_SELF : d->domain_id);
   35.37 -
   35.38 -static long
   35.39 -alloc_dom_mem(struct domain *d, 
   35.40 -              unsigned long *extent_list, 
   35.41 -              unsigned long  start_extent,
   35.42 -              unsigned int   nr_extents,
   35.43 -              unsigned int   extent_order,
   35.44 -    		  unsigned int   flags)
   35.45 -{
   35.46 -    struct pfn_info *page;
   35.47 -    unsigned long    i;
   35.48 -
   35.49 -    if ( (extent_list != NULL) && 
   35.50 -         !array_access_ok(extent_list, nr_extents, sizeof(*extent_list)) )
   35.51 -        return start_extent;
   35.52 -
   35.53 -    if ( (extent_order != 0) && !IS_CAPABLE_PHYSDEV(current->domain) )
   35.54 -    {
   35.55 -        DPRINTK("Only I/O-capable domains may allocate > order-0 memory.\n");
   35.56 -        return start_extent;
   35.57 -    }
   35.58 -
   35.59 -    for ( i = start_extent; i < nr_extents; i++ )
   35.60 -    {
   35.61 -        PREEMPT_CHECK(MEMOP_increase_reservation);
   35.62 -
   35.63 -        if ( unlikely((page = alloc_domheap_pages(d, extent_order,
   35.64 -                                                  flags)) == NULL) )
   35.65 -        {
   35.66 -            DPRINTK("Could not allocate a frame\n");
   35.67 -            return i;
   35.68 -        }
   35.69 -
   35.70 -        /* Inform the domain of the new page's machine address. */ 
   35.71 -        if ( (extent_list != NULL) && 
   35.72 -             (__put_user(page_to_pfn(page), &extent_list[i]) != 0) )
   35.73 -            return i;
   35.74 -    }
   35.75 -
   35.76 -    return i;
   35.77 -}
   35.78 -    
   35.79 -static long
   35.80 -free_dom_mem(struct domain *d,
   35.81 -             unsigned long *extent_list, 
   35.82 -             unsigned long  start_extent,
   35.83 -             unsigned int   nr_extents,
   35.84 -             unsigned int   extent_order)
   35.85 -{
   35.86 -    struct pfn_info *page;
   35.87 -    unsigned long    i, j, mpfn;
   35.88 -
   35.89 -    if ( !array_access_ok(extent_list, nr_extents, sizeof(*extent_list)) )
   35.90 -        return start_extent;
   35.91 -
   35.92 -    for ( i = start_extent; i < nr_extents; i++ )
   35.93 -    {
   35.94 -        PREEMPT_CHECK(MEMOP_decrease_reservation);
   35.95 -
   35.96 -        if ( unlikely(__get_user(mpfn, &extent_list[i]) != 0) )
   35.97 -            return i;
   35.98 -
   35.99 -        for ( j = 0; j < (1 << extent_order); j++ )
  35.100 -        {
  35.101 -            if ( unlikely((mpfn + j) >= max_page) )
  35.102 -            {
  35.103 -                DPRINTK("Domain %u page number out of range (%lx >= %lx)\n", 
  35.104 -                        d->domain_id, mpfn + j, max_page);
  35.105 -                return i;
  35.106 -            }
  35.107 -            
  35.108 -            page = &frame_table[mpfn + j];
  35.109 -            if ( unlikely(!get_page(page, d)) )
  35.110 -            {
  35.111 -                DPRINTK("Bad page free for domain %u\n", d->domain_id);
  35.112 -                return i;
  35.113 -            }
  35.114 -
  35.115 -            if ( test_and_clear_bit(_PGT_pinned, &page->u.inuse.type_info) )
  35.116 -                put_page_and_type(page);
  35.117 -            
  35.118 -            if ( test_and_clear_bit(_PGC_allocated, &page->count_info) )
  35.119 -                put_page(page);
  35.120 -
  35.121 -            shadow_sync_and_drop_references(d, page);
  35.122 -
  35.123 -            put_page(page);
  35.124 -        }
  35.125 -    }
  35.126 -
  35.127 -    return i;
  35.128 -}
  35.129 -
  35.130 -long
  35.131 -do_dom_mem_op(unsigned long  op, 
  35.132 -              unsigned long *extent_list, 
  35.133 -              unsigned int   nr_extents,
  35.134 -              unsigned int   extent_order,
  35.135 -              domid_t        domid)
  35.136 -{
  35.137 -    struct domain *d;
  35.138 -    unsigned long  rc, start_extent;
  35.139 -    unsigned int   address_bits_order;
  35.140 -
  35.141 -    /* Extract @start_extent from @op. */
  35.142 -    start_extent  = op >> START_EXTENT_SHIFT;
  35.143 -    op           &= (1 << START_EXTENT_SHIFT) - 1;
  35.144 -
  35.145 -    /* seperate extent_order and address_bits_order */
  35.146 -    address_bits_order = (extent_order >> 8) & 0xff;
  35.147 -    extent_order &= 0xff;
  35.148 -
  35.149 -    if ( unlikely(start_extent > nr_extents) )
  35.150 -        return -EINVAL;
  35.151 -
  35.152 -    if ( likely(domid == DOMID_SELF) )
  35.153 -        d = current->domain;
  35.154 -    else if ( unlikely(!IS_PRIV(current->domain)) )
  35.155 -        return -EPERM;
  35.156 -    else if ( unlikely((d = find_domain_by_id(domid)) == NULL) )
  35.157 -        return -ESRCH;
  35.158 -
  35.159 -    switch ( op )
  35.160 -    {
  35.161 -    case MEMOP_increase_reservation:
  35.162 -        rc = alloc_dom_mem(
  35.163 -            d, extent_list, start_extent, nr_extents, extent_order,
  35.164 -            (address_bits_order <= 32) ? ALLOC_DOM_DMA : 0);
  35.165 -        break;
  35.166 -    case MEMOP_decrease_reservation:
  35.167 -        rc = free_dom_mem(
  35.168 -            d, extent_list, start_extent, nr_extents, extent_order);
  35.169 -        break;
  35.170 -    default:
  35.171 -        rc = -ENOSYS;
  35.172 -        break;
  35.173 -    }
  35.174 -
  35.175 -    if ( unlikely(domid != DOMID_SELF) )
  35.176 -        put_domain(d);
  35.177 -
  35.178 -    return rc;
  35.179 -}
  35.180 -
  35.181 -/*
  35.182 - * Local variables:
  35.183 - * mode: C
  35.184 - * c-set-style: "BSD"
  35.185 - * c-basic-offset: 4
  35.186 - * tab-width: 4
  35.187 - * indent-tabs-mode: nil
  35.188 - * End:
  35.189 - */
    36.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.2 +++ b/xen/common/memory.c	Tue Aug 30 16:15:27 2005 +0000
    36.3 @@ -0,0 +1,205 @@
    36.4 +/******************************************************************************
    36.5 + * memory.c
    36.6 + *
    36.7 + * Code to handle memory-related requests.
    36.8 + *
    36.9 + * Copyright (c) 2003-2004, B Dragovic
   36.10 + * Copyright (c) 2003-2005, K A Fraser
   36.11 + */
   36.12 +
   36.13 +#include <xen/config.h>
   36.14 +#include <xen/types.h>
   36.15 +#include <xen/lib.h>
   36.16 +#include <xen/mm.h>
   36.17 +#include <xen/perfc.h>
   36.18 +#include <xen/sched.h>
   36.19 +#include <xen/event.h>
   36.20 +#include <xen/shadow.h>
   36.21 +#include <asm/current.h>
   36.22 +#include <asm/hardirq.h>
   36.23 +#include <public/memory.h>
   36.24 +
   36.25 +static long
   36.26 +increase_reservation(
   36.27 +    struct domain *d, 
   36.28 +    unsigned long *extent_list, 
   36.29 +    unsigned int   nr_extents,
   36.30 +    unsigned int   extent_order,
   36.31 +    unsigned int   flags)
   36.32 +{
   36.33 +    struct pfn_info *page;
   36.34 +    unsigned long    i;
   36.35 +
   36.36 +    if ( (extent_list != NULL)
   36.37 +         && !array_access_ok(extent_list, nr_extents, sizeof(*extent_list)) )
   36.38 +        return 0;
   36.39 +
   36.40 +    if ( (extent_order != 0) && !IS_CAPABLE_PHYSDEV(current->domain) )
   36.41 +    {
   36.42 +        DPRINTK("Only I/O-capable domains may allocate > order-0 memory.\n");
   36.43 +        return 0;
   36.44 +    }
   36.45 +
   36.46 +    for ( i = 0; i < nr_extents; i++ )
   36.47 +    {
   36.48 +        if ( hypercall_preempt_check() )
   36.49 +            return i;
   36.50 +
   36.51 +        if ( unlikely((page = alloc_domheap_pages(
   36.52 +            d, extent_order, flags)) == NULL) )
   36.53 +        {
   36.54 +            DPRINTK("Could not allocate a frame\n");
   36.55 +            return i;
   36.56 +        }
   36.57 +
   36.58 +        /* Inform the domain of the new page's machine address. */ 
   36.59 +        if ( (extent_list != NULL)
   36.60 +             && (__put_user(page_to_pfn(page), &extent_list[i]) != 0) )
   36.61 +            return i;
   36.62 +    }
   36.63 +
   36.64 +    return nr_extents;
   36.65 +}
   36.66 +    
   36.67 +static long
   36.68 +decrease_reservation(
   36.69 +    struct domain *d, 
   36.70 +    unsigned long *extent_list, 
   36.71 +    unsigned int   nr_extents,
   36.72 +    unsigned int   extent_order,
   36.73 +    unsigned int   flags)
   36.74 +{
   36.75 +    struct pfn_info *page;
   36.76 +    unsigned long    i, j, mpfn;
   36.77 +
   36.78 +    if ( !array_access_ok(extent_list, nr_extents, sizeof(*extent_list)) )
   36.79 +        return 0;
   36.80 +
   36.81 +    for ( i = 0; i < nr_extents; i++ )
   36.82 +    {
   36.83 +        if ( hypercall_preempt_check() )
   36.84 +            return i;
   36.85 +
   36.86 +        if ( unlikely(__get_user(mpfn, &extent_list[i]) != 0) )
   36.87 +            return i;
   36.88 +
   36.89 +        for ( j = 0; j < (1 << extent_order); j++ )
   36.90 +        {
   36.91 +            if ( unlikely((mpfn + j) >= max_page) )
   36.92 +            {
   36.93 +                DPRINTK("Domain %u page number out of range (%lx >= %lx)\n", 
   36.94 +                        d->domain_id, mpfn + j, max_page);
   36.95 +                return i;
   36.96 +            }
   36.97 +            
   36.98 +            page = &frame_table[mpfn + j];
   36.99 +            if ( unlikely(!get_page(page, d)) )
  36.100 +            {
  36.101 +                DPRINTK("Bad page free for domain %u\n", d->domain_id);
  36.102 +                return i;
  36.103 +            }
  36.104 +
  36.105 +            if ( test_and_clear_bit(_PGT_pinned, &page->u.inuse.type_info) )
  36.106 +                put_page_and_type(page);
  36.107 +            
  36.108 +            if ( test_and_clear_bit(_PGC_allocated, &page->count_info) )
  36.109 +                put_page(page);
  36.110 +
  36.111 +            shadow_sync_and_drop_references(d, page);
  36.112 +
  36.113 +            put_page(page);
  36.114 +        }
  36.115 +    }
  36.116 +
  36.117 +    return nr_extents;
  36.118 +}
  36.119 +
  36.120 +/*
  36.121 + * To allow safe resume of do_memory_op() after preemption, we need to know 
  36.122 + * at what point in the page list to resume. For this purpose I steal the 
  36.123 + * high-order bits of the @cmd parameter, which are otherwise unused and zero.
  36.124 + */
  36.125 +#define START_EXTENT_SHIFT 4 /* cmd[:4] == start_extent */
  36.126 +
  36.127 +long do_memory_op(int cmd, void *arg)
  36.128 +{
  36.129 +    struct domain *d;
  36.130 +    int rc, start_extent, op, flags = 0;
  36.131 +    struct xen_memory_reservation reservation;
  36.132 +
  36.133 +    op = cmd & ((1 << START_EXTENT_SHIFT) - 1);
  36.134 +
  36.135 +    switch ( op )
  36.136 +    {
  36.137 +    case XENMEM_increase_reservation:
  36.138 +    case XENMEM_decrease_reservation:
  36.139 +        if ( copy_from_user(&reservation, arg, sizeof(reservation)) )
  36.140 +            return -EFAULT;
  36.141 +
  36.142 +        start_extent = cmd >> START_EXTENT_SHIFT;
  36.143 +        if ( unlikely(start_extent > reservation.nr_extents) )
  36.144 +            return -EINVAL;
  36.145 +        
  36.146 +        if ( reservation.extent_start != NULL )
  36.147 +            reservation.extent_start += start_extent;
  36.148 +        reservation.nr_extents -= start_extent;
  36.149 +
  36.150 +        if ( unlikely(reservation.address_bits != 0)
  36.151 +             && (reservation.address_bits > (get_order(max_page)+PAGE_SHIFT)) )
  36.152 +        {
  36.153 +            if ( reservation.address_bits < 31 )
  36.154 +                return -ENOMEM;
  36.155 +            flags = ALLOC_DOM_DMA;
  36.156 +        }
  36.157 +
  36.158 +        if ( likely(reservation.domid == DOMID_SELF) )
  36.159 +            d = current->domain;
  36.160 +        else if ( !IS_PRIV(current->domain) )
  36.161 +            return -EPERM;
  36.162 +        else if ( (d = find_domain_by_id(reservation.domid)) == NULL )
  36.163 +            return -ESRCH;
  36.164 +
  36.165 +        rc = ((op == XENMEM_increase_reservation) ?
  36.166 +              increase_reservation : decrease_reservation)(
  36.167 +                  d,
  36.168 +                  reservation.extent_start,
  36.169 +                  reservation.nr_extents,
  36.170 +                  reservation.extent_order,
  36.171 +                  flags);
  36.172 +
  36.173 +        if ( unlikely(reservation.domid != DOMID_SELF) )
  36.174 +            put_domain(d);
  36.175 +
  36.176 +        rc += start_extent;
  36.177 +
  36.178 +        if ( (rc != reservation.nr_extents) && hypercall_preempt_check() )
  36.179 +            return hypercall2_create_continuation(
  36.180 +                __HYPERVISOR_memory_op,
  36.181 +                op | (rc << START_EXTENT_SHIFT),
  36.182 +                arg);
  36.183 +        
  36.184 +        break;
  36.185 +
  36.186 +    case XENMEM_maximum_ram_page:
  36.187 +        if ( put_user(max_page, (unsigned long *)arg) )
  36.188 +            return -EFAULT;
  36.189 +        rc = -ENOSYS;
  36.190 +        break;
  36.191 +
  36.192 +    default:
  36.193 +        rc = -ENOSYS;
  36.194 +        break;
  36.195 +    }
  36.196 +
  36.197 +    return rc;
  36.198 +}
  36.199 +
  36.200 +/*
  36.201 + * Local variables:
  36.202 + * mode: C
  36.203 + * c-set-style: "BSD"
  36.204 + * c-basic-offset: 4
  36.205 + * tab-width: 4
  36.206 + * indent-tabs-mode: nil
  36.207 + * End:
  36.208 + */
    37.1 --- a/xen/common/page_alloc.c	Tue Aug 30 16:14:53 2005 +0000
    37.2 +++ b/xen/common/page_alloc.c	Tue Aug 30 16:15:27 2005 +0000
    37.3 @@ -216,7 +216,7 @@ unsigned long alloc_boot_pages(unsigned 
    37.4  #define NR_ZONES    3
    37.5  
    37.6  
    37.7 -#define MAX_DMADOM_PFN 0xFFFFF
    37.8 +#define MAX_DMADOM_PFN 0x7FFFF /* 31 addressable bits */
    37.9  #define pfn_dom_zone_type(_pfn)                                 \
   37.10      (((_pfn) <= MAX_DMADOM_PFN) ? MEMZONE_DMADOM : MEMZONE_DOM)
   37.11  
    38.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.2 +++ b/xen/include/public/memory.h	Tue Aug 30 16:15:27 2005 +0000
    38.3 @@ -0,0 +1,50 @@
    38.4 +/******************************************************************************
    38.5 + * memory.h
    38.6 + * 
    38.7 + * Memory reservation and information.
    38.8 + * 
    38.9 + * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
   38.10 + */
   38.11 +
   38.12 +#ifndef __XEN_PUBLIC_MEMORY_H__
   38.13 +#define __XEN_PUBLIC_MEMORY_H__
   38.14 +
   38.15 +/* arg == addr of struct xen_memory_reservation. */
   38.16 +#define XENMEM_increase_reservation 0
   38.17 +
   38.18 +/* arg == addr of struct xen_memory_reservation. */
   38.19 +#define XENMEM_decrease_reservation 1
   38.20 +
   38.21 +/* arg == addr of unsigned long. */
   38.22 +#define XENMEM_maximum_ram_page     2
   38.23 +
   38.24 +typedef struct xen_memory_reservation {
   38.25 +
   38.26 +    /*
   38.27 +     * MFN bases of extents to free (XENMEM_decrease_reservation).
   38.28 +     * MFN bases of extents that were allocated (XENMEM_increase_reservation).
   38.29 +     */
   38.30 +    unsigned long *extent_start;
   38.31 +
   38.32 +    /* Number of extents, and size/alignment of each (2^extent_order pages). */
   38.33 +    unsigned long  nr_extents;
   38.34 +    unsigned int   extent_order;
   38.35 +
   38.36 +    /*
   38.37 +     * XENMEM_increase_reservation: maximum # bits addressable by the user
   38.38 +     * of the allocated region (e.g., I/O devices often have a 32-bit
   38.39 +     * limitation even in 64-bit systems). If zero then the user has no
   38.40 +     * addressing restriction.
   38.41 +     * XENMEM_decrease_reservation: unused.
   38.42 +     */
   38.43 +    unsigned int   address_bits;
   38.44 +
   38.45 +    /*
   38.46 +     * Domain whose reservation is being changed.
   38.47 +     * Unprivileged domains can specify only DOMID_SELF.
   38.48 +     */
   38.49 +    domid_t        domid;
   38.50 +
   38.51 +} xen_memory_reservation_t;
   38.52 +
   38.53 +#endif /* __XEN_PUBLIC_MEMORY_H__ */
    39.1 --- a/xen/include/public/xen.h	Tue Aug 30 16:14:53 2005 +0000
    39.2 +++ b/xen/include/public/xen.h	Tue Aug 30 16:15:27 2005 +0000
    39.3 @@ -42,7 +42,7 @@
    39.4  #define __HYPERVISOR_set_debugreg          8
    39.5  #define __HYPERVISOR_get_debugreg          9
    39.6  #define __HYPERVISOR_update_descriptor    10
    39.7 -#define __HYPERVISOR_dom_mem_op           12
    39.8 +#define __HYPERVISOR_memory_op            12
    39.9  #define __HYPERVISOR_multicall            13
   39.10  #define __HYPERVISOR_update_va_mapping    14
   39.11  #define __HYPERVISOR_set_timer_op         15
   39.12 @@ -225,12 +225,6 @@ struct mmuext_op {
   39.13  #define CONSOLEIO_read          1
   39.14  
   39.15  /*
   39.16 - * Commands to HYPERVISOR_dom_mem_op().
   39.17 - */
   39.18 -#define MEMOP_increase_reservation 0
   39.19 -#define MEMOP_decrease_reservation 1
   39.20 -
   39.21 -/*
   39.22   * Commands to HYPERVISOR_vm_assist().
   39.23   */
   39.24  #define VMASST_CMD_enable                0