ia64/xen-unstable

changeset 11102:9c953e1b6fad

[LINUX] Split useful bits of page.h into new header maddr.h.

Split the bits of page.h which are needed by PV-on-HVM drivers out
into a separate header file, so that it's a bit easier to get the xenolinux
machine address functions when compiled against a native kernel.

Signed-off-by: Steven Smith <ssmith@xensource.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Mon Aug 14 13:54:10 2006 +0100 (2006-08-14)
parents 22f278b5fcef
children 9519445d9e9d
files linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/maddr.h linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/page.h linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-2level.h linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-3level.h linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/maddr.h linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/page.h linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/pgtable.h
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/maddr.h	Mon Aug 14 13:54:10 2006 +0100
     1.3 @@ -0,0 +1,160 @@
     1.4 +#ifndef _I386_MADDR_H
     1.5 +#define _I386_MADDR_H
     1.6 +
     1.7 +#include <xen/features.h>
     1.8 +#include <xen/interface/xen.h>
     1.9 +
    1.10 +/**** MACHINE <-> PHYSICAL CONVERSION MACROS ****/
    1.11 +#define INVALID_P2M_ENTRY	(~0UL)
    1.12 +#define FOREIGN_FRAME_BIT	(1UL<<31)
    1.13 +#define FOREIGN_FRAME(m)	((m) | FOREIGN_FRAME_BIT)
    1.14 +
    1.15 +#ifdef CONFIG_XEN
    1.16 +
    1.17 +extern unsigned long *phys_to_machine_mapping;
    1.18 +
    1.19 +#undef machine_to_phys_mapping
    1.20 +extern unsigned long *machine_to_phys_mapping;
    1.21 +extern unsigned int   machine_to_phys_order;
    1.22 +
    1.23 +static inline unsigned long pfn_to_mfn(unsigned long pfn)
    1.24 +{
    1.25 +	if (xen_feature(XENFEAT_auto_translated_physmap))
    1.26 +		return pfn;
    1.27 +	return phys_to_machine_mapping[(unsigned int)(pfn)] &
    1.28 +		~FOREIGN_FRAME_BIT;
    1.29 +}
    1.30 +
    1.31 +static inline int phys_to_machine_mapping_valid(unsigned long pfn)
    1.32 +{
    1.33 +	if (xen_feature(XENFEAT_auto_translated_physmap))
    1.34 +		return 1;
    1.35 +	return (phys_to_machine_mapping[pfn] != INVALID_P2M_ENTRY);
    1.36 +}
    1.37 +
    1.38 +static inline unsigned long mfn_to_pfn(unsigned long mfn)
    1.39 +{
    1.40 +	extern unsigned long max_mapnr;
    1.41 +	unsigned long pfn;
    1.42 +
    1.43 +	if (xen_feature(XENFEAT_auto_translated_physmap))
    1.44 +		return mfn;
    1.45 +
    1.46 +	if (unlikely((mfn >> machine_to_phys_order) != 0))
    1.47 +		return max_mapnr;
    1.48 +
    1.49 +	/* The array access can fail (e.g., device space beyond end of RAM). */
    1.50 +	asm (
    1.51 +		"1:	movl %1,%0\n"
    1.52 +		"2:\n"
    1.53 +		".section .fixup,\"ax\"\n"
    1.54 +		"3:	movl %2,%0\n"
    1.55 +		"	jmp  2b\n"
    1.56 +		".previous\n"
    1.57 +		".section __ex_table,\"a\"\n"
    1.58 +		"	.align 4\n"
    1.59 +		"	.long 1b,3b\n"
    1.60 +		".previous"
    1.61 +		: "=r" (pfn)
    1.62 +		: "m" (machine_to_phys_mapping[mfn]), "m" (max_mapnr) );
    1.63 +
    1.64 +	return pfn;
    1.65 +}
    1.66 +
    1.67 +/*
    1.68 + * We detect special mappings in one of two ways:
    1.69 + *  1. If the MFN is an I/O page then Xen will set the m2p entry
    1.70 + *     to be outside our maximum possible pseudophys range.
    1.71 + *  2. If the MFN belongs to a different domain then we will certainly
    1.72 + *     not have MFN in our p2m table. Conversely, if the page is ours,
    1.73 + *     then we'll have p2m(m2p(MFN))==MFN.
    1.74 + * If we detect a special mapping then it doesn't have a 'struct page'.
    1.75 + * We force !pfn_valid() by returning an out-of-range pointer.
    1.76 + *
    1.77 + * NB. These checks require that, for any MFN that is not in our reservation,
    1.78 + * there is no PFN such that p2m(PFN) == MFN. Otherwise we can get confused if
    1.79 + * we are foreign-mapping the MFN, and the other domain as m2p(MFN) == PFN.
    1.80 + * Yikes! Various places must poke in INVALID_P2M_ENTRY for safety.
    1.81 + *
    1.82 + * NB2. When deliberately mapping foreign pages into the p2m table, you *must*
    1.83 + *      use FOREIGN_FRAME(). This will cause pte_pfn() to choke on it, as we
    1.84 + *      require. In all the cases we care about, the FOREIGN_FRAME bit is
    1.85 + *      masked (e.g., pfn_to_mfn()) so behaviour there is correct.
    1.86 + */
    1.87 +static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
    1.88 +{
    1.89 +	extern unsigned long max_mapnr;
    1.90 +	unsigned long pfn = mfn_to_pfn(mfn);
    1.91 +	if ((pfn < max_mapnr)
    1.92 +	    && !xen_feature(XENFEAT_auto_translated_physmap)
    1.93 +	    && (phys_to_machine_mapping[pfn] != mfn))
    1.94 +		return max_mapnr; /* force !pfn_valid() */
    1.95 +	return pfn;
    1.96 +}
    1.97 +
    1.98 +static inline void set_phys_to_machine(unsigned long pfn, unsigned long mfn)
    1.99 +{
   1.100 +	if (xen_feature(XENFEAT_auto_translated_physmap)) {
   1.101 +		BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY);
   1.102 +		return;
   1.103 +	}
   1.104 +	phys_to_machine_mapping[pfn] = mfn;
   1.105 +}
   1.106 +
   1.107 +
   1.108 +#else /* !CONFIG_XEN */
   1.109 +
   1.110 +#define pfn_to_mfn(pfn) (pfn)
   1.111 +#define mfn_to_pfn(mfn) (mfn)
   1.112 +#define mfn_to_local_pfn(mfn) (mfn)
   1.113 +#define set_phys_to_machine(pfn, mfn) BUG_ON((pfn) != (mfn))
   1.114 +#define phys_to_machine_mapping_valid(pfn) (1)
   1.115 +
   1.116 +#endif /* !CONFIG_XEN */
   1.117 +
   1.118 +/* Definitions for machine and pseudophysical addresses. */
   1.119 +#ifdef CONFIG_X86_PAE
   1.120 +typedef unsigned long long paddr_t;
   1.121 +typedef unsigned long long maddr_t;
   1.122 +#else
   1.123 +typedef unsigned long paddr_t;
   1.124 +typedef unsigned long maddr_t;
   1.125 +#endif
   1.126 +
   1.127 +static inline maddr_t phys_to_machine(paddr_t phys)
   1.128 +{
   1.129 +	maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT);
   1.130 +	machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
   1.131 +	return machine;
   1.132 +}
   1.133 +static inline paddr_t machine_to_phys(maddr_t machine)
   1.134 +{
   1.135 +	paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT);
   1.136 +	phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
   1.137 +	return phys;
   1.138 +}
   1.139 +
   1.140 +/* VIRT <-> MACHINE conversion */
   1.141 +#define virt_to_machine(v)	(phys_to_machine(__pa(v)))
   1.142 +#define virt_to_mfn(v)		(pfn_to_mfn(__pa(v) >> PAGE_SHIFT))
   1.143 +#define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
   1.144 +
   1.145 +#ifdef CONFIG_X86_PAE
   1.146 +static inline pte_t pfn_pte_ma(unsigned long page_nr, pgprot_t pgprot)
   1.147 +{
   1.148 +	pte_t pte;
   1.149 +
   1.150 +	pte.pte_high = (page_nr >> (32 - PAGE_SHIFT)) | \
   1.151 +					(pgprot_val(pgprot) >> 32);
   1.152 +	pte.pte_high &= (__supported_pte_mask >> 32);
   1.153 +	pte.pte_low = ((page_nr << PAGE_SHIFT) | pgprot_val(pgprot)) & \
   1.154 +							__supported_pte_mask;
   1.155 +	return pte;
   1.156 +}
   1.157 +#else
   1.158 +#define pfn_pte_ma(pfn, prot)	__pte_ma(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
   1.159 +#endif
   1.160 +
   1.161 +#define __pte_ma(x)	((pte_t) { (x) } )
   1.162 +
   1.163 +#endif /* _I386_MADDR_H */
     2.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/page.h	Mon Aug 14 11:35:57 2006 +0100
     2.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/page.h	Mon Aug 14 13:54:10 2006 +0100
     2.3 @@ -60,123 +60,6 @@
     2.4  #define clear_user_page(page, vaddr, pg)	clear_page(page)
     2.5  #define copy_user_page(to, from, vaddr, pg)	copy_page(to, from)
     2.6  
     2.7 -/**** MACHINE <-> PHYSICAL CONVERSION MACROS ****/
     2.8 -#define INVALID_P2M_ENTRY	(~0UL)
     2.9 -#define FOREIGN_FRAME_BIT	(1UL<<31)
    2.10 -#define FOREIGN_FRAME(m)	((m) | FOREIGN_FRAME_BIT)
    2.11 -
    2.12 -extern unsigned long *phys_to_machine_mapping;
    2.13 -
    2.14 -#undef machine_to_phys_mapping
    2.15 -extern unsigned long *machine_to_phys_mapping;
    2.16 -extern unsigned int   machine_to_phys_order;
    2.17 -
    2.18 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
    2.19 -{
    2.20 -	if (xen_feature(XENFEAT_auto_translated_physmap))
    2.21 -		return pfn;
    2.22 -	return phys_to_machine_mapping[(unsigned int)(pfn)] &
    2.23 -		~FOREIGN_FRAME_BIT;
    2.24 -}
    2.25 -
    2.26 -static inline int phys_to_machine_mapping_valid(unsigned long pfn)
    2.27 -{
    2.28 -	if (xen_feature(XENFEAT_auto_translated_physmap))
    2.29 -		return 1;
    2.30 -	return (phys_to_machine_mapping[pfn] != INVALID_P2M_ENTRY);
    2.31 -}
    2.32 -
    2.33 -static inline unsigned long mfn_to_pfn(unsigned long mfn)
    2.34 -{
    2.35 -	extern unsigned long max_mapnr;
    2.36 -	unsigned long pfn;
    2.37 -
    2.38 -	if (xen_feature(XENFEAT_auto_translated_physmap))
    2.39 -		return mfn;
    2.40 -
    2.41 -	if (unlikely((mfn >> machine_to_phys_order) != 0))
    2.42 -		return max_mapnr;
    2.43 -
    2.44 -	/* The array access can fail (e.g., device space beyond end of RAM). */
    2.45 -	asm (
    2.46 -		"1:	movl %1,%0\n"
    2.47 -		"2:\n"
    2.48 -		".section .fixup,\"ax\"\n"
    2.49 -		"3:	movl %2,%0\n"
    2.50 -		"	jmp  2b\n"
    2.51 -		".previous\n"
    2.52 -		".section __ex_table,\"a\"\n"
    2.53 -		"	.align 4\n"
    2.54 -		"	.long 1b,3b\n"
    2.55 -		".previous"
    2.56 -		: "=r" (pfn)
    2.57 -		: "m" (machine_to_phys_mapping[mfn]), "m" (max_mapnr) );
    2.58 -
    2.59 -	return pfn;
    2.60 -}
    2.61 -
    2.62 -/*
    2.63 - * We detect special mappings in one of two ways:
    2.64 - *  1. If the MFN is an I/O page then Xen will set the m2p entry
    2.65 - *     to be outside our maximum possible pseudophys range.
    2.66 - *  2. If the MFN belongs to a different domain then we will certainly
    2.67 - *     not have MFN in our p2m table. Conversely, if the page is ours,
    2.68 - *     then we'll have p2m(m2p(MFN))==MFN.
    2.69 - * If we detect a special mapping then it doesn't have a 'struct page'.
    2.70 - * We force !pfn_valid() by returning an out-of-range pointer.
    2.71 - *
    2.72 - * NB. These checks require that, for any MFN that is not in our reservation,
    2.73 - * there is no PFN such that p2m(PFN) == MFN. Otherwise we can get confused if
    2.74 - * we are foreign-mapping the MFN, and the other domain as m2p(MFN) == PFN.
    2.75 - * Yikes! Various places must poke in INVALID_P2M_ENTRY for safety.
    2.76 - *
    2.77 - * NB2. When deliberately mapping foreign pages into the p2m table, you *must*
    2.78 - *      use FOREIGN_FRAME(). This will cause pte_pfn() to choke on it, as we
    2.79 - *      require. In all the cases we care about, the FOREIGN_FRAME bit is
    2.80 - *      masked (e.g., pfn_to_mfn()) so behaviour there is correct.
    2.81 - */
    2.82 -static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
    2.83 -{
    2.84 -	extern unsigned long max_mapnr;
    2.85 -	unsigned long pfn = mfn_to_pfn(mfn);
    2.86 -	if ((pfn < max_mapnr)
    2.87 -	    && !xen_feature(XENFEAT_auto_translated_physmap)
    2.88 -	    && (phys_to_machine_mapping[pfn] != mfn))
    2.89 -		return max_mapnr; /* force !pfn_valid() */
    2.90 -	return pfn;
    2.91 -}
    2.92 -
    2.93 -static inline void set_phys_to_machine(unsigned long pfn, unsigned long mfn)
    2.94 -{
    2.95 -	if (xen_feature(XENFEAT_auto_translated_physmap)) {
    2.96 -		BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY);
    2.97 -		return;
    2.98 -	}
    2.99 -	phys_to_machine_mapping[pfn] = mfn;
   2.100 -}
   2.101 -
   2.102 -/* Definitions for machine and pseudophysical addresses. */
   2.103 -#ifdef CONFIG_X86_PAE
   2.104 -typedef unsigned long long paddr_t;
   2.105 -typedef unsigned long long maddr_t;
   2.106 -#else
   2.107 -typedef unsigned long paddr_t;
   2.108 -typedef unsigned long maddr_t;
   2.109 -#endif
   2.110 -
   2.111 -static inline maddr_t phys_to_machine(paddr_t phys)
   2.112 -{
   2.113 -	maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT);
   2.114 -	machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
   2.115 -	return machine;
   2.116 -}
   2.117 -static inline paddr_t machine_to_phys(maddr_t machine)
   2.118 -{
   2.119 -	paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT);
   2.120 -	phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
   2.121 -	return phys;
   2.122 -}
   2.123 -
   2.124  /*
   2.125   * These are used to make use of C type-checking..
   2.126   */
   2.127 @@ -187,6 +70,8 @@ typedef struct { unsigned long pte_low, 
   2.128  typedef struct { unsigned long long pmd; } pmd_t;
   2.129  typedef struct { unsigned long long pgd; } pgd_t;
   2.130  typedef struct { unsigned long long pgprot; } pgprot_t;
   2.131 +#define pgprot_val(x)	((x).pgprot)
   2.132 +#include <asm/maddr.h>
   2.133  #define __pte(x) ({ unsigned long long _x = (x);        \
   2.134      if (_x & 1) _x = phys_to_machine(_x);               \
   2.135      ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); })
   2.136 @@ -227,6 +112,8 @@ static inline unsigned long long pte_val
   2.137  typedef struct { unsigned long pte_low; } pte_t;
   2.138  typedef struct { unsigned long pgd; } pgd_t;
   2.139  typedef struct { unsigned long pgprot; } pgprot_t;
   2.140 +#define pgprot_val(x)	((x).pgprot)
   2.141 +#include <asm/maddr.h>
   2.142  #define boot_pte_t pte_t /* or would you rather have a typedef */
   2.143  #define pte_val(x)	(((x).pte_low & 1) ? machine_to_phys((x).pte_low) : \
   2.144  			 (x).pte_low)
   2.145 @@ -252,9 +139,6 @@ static inline unsigned long pgd_val(pgd_
   2.146  #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
   2.147  #endif
   2.148  
   2.149 -#define pgprot_val(x)	((x).pgprot)
   2.150 -
   2.151 -#define __pte_ma(x)	((pte_t) { (x) } )
   2.152  #define __pgprot(x)	((pgprot_t) { (x) } )
   2.153  
   2.154  #endif /* !__ASSEMBLY__ */
   2.155 @@ -323,11 +207,6 @@ extern int page_is_ram(unsigned long pag
   2.156  	((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \
   2.157  		 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
   2.158  
   2.159 -/* VIRT <-> MACHINE conversion */
   2.160 -#define virt_to_machine(v)	(phys_to_machine(__pa(v)))
   2.161 -#define virt_to_mfn(v)		(pfn_to_mfn(__pa(v) >> PAGE_SHIFT))
   2.162 -#define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
   2.163 -
   2.164  #define __HAVE_ARCH_GATE_AREA 1
   2.165  
   2.166  #endif /* __KERNEL__ */
     3.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-2level.h	Mon Aug 14 11:35:57 2006 +0100
     3.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-2level.h	Mon Aug 14 13:54:10 2006 +0100
     3.3 @@ -45,7 +45,6 @@
     3.4  
     3.5  #define pte_none(x)		(!(x).pte_low)
     3.6  #define pfn_pte(pfn, prot)	__pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
     3.7 -#define pfn_pte_ma(pfn, prot)	__pte_ma(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
     3.8  #define pfn_pmd(pfn, prot)	__pmd(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
     3.9  
    3.10  /*
     4.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-3level.h	Mon Aug 14 11:35:57 2006 +0100
     4.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-3level.h	Mon Aug 14 13:54:10 2006 +0100
     4.3 @@ -151,18 +151,6 @@ static inline int pte_none(pte_t pte)
     4.4  
     4.5  extern unsigned long long __supported_pte_mask;
     4.6  
     4.7 -static inline pte_t pfn_pte_ma(unsigned long page_nr, pgprot_t pgprot)
     4.8 -{
     4.9 -	pte_t pte;
    4.10 -
    4.11 -	pte.pte_high = (page_nr >> (32 - PAGE_SHIFT)) | \
    4.12 -					(pgprot_val(pgprot) >> 32);
    4.13 -	pte.pte_high &= (__supported_pte_mask >> 32);
    4.14 -	pte.pte_low = ((page_nr << PAGE_SHIFT) | pgprot_val(pgprot)) & \
    4.15 -							__supported_pte_mask;
    4.16 -	return pte;
    4.17 -}
    4.18 -
    4.19  static inline pte_t pfn_pte(unsigned long page_nr, pgprot_t pgprot)
    4.20  {
    4.21  	return pfn_pte_ma(pfn_to_mfn(page_nr), pgprot);
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/maddr.h	Mon Aug 14 13:54:10 2006 +0100
     5.3 @@ -0,0 +1,139 @@
     5.4 +#ifndef _X86_64_MADDR_H
     5.5 +#define _X86_64_MADDR_H
     5.6 +
     5.7 +#include <xen/features.h>
     5.8 +#include <xen/interface/xen.h>
     5.9 +
    5.10 +/**** MACHINE <-> PHYSICAL CONVERSION MACROS ****/
    5.11 +#define INVALID_P2M_ENTRY	(~0UL)
    5.12 +#define FOREIGN_FRAME_BIT	(1UL<<63)
    5.13 +#define FOREIGN_FRAME(m)	((m) | FOREIGN_FRAME_BIT)
    5.14 +
    5.15 +#ifdef CONFIG_XEN
    5.16 +
    5.17 +extern unsigned long *phys_to_machine_mapping;
    5.18 +
    5.19 +#undef machine_to_phys_mapping
    5.20 +extern unsigned long *machine_to_phys_mapping;
    5.21 +extern unsigned int   machine_to_phys_order;
    5.22 +
    5.23 +static inline unsigned long pfn_to_mfn(unsigned long pfn)
    5.24 +{
    5.25 +	if (xen_feature(XENFEAT_auto_translated_physmap))
    5.26 +		return pfn;
    5.27 +	return phys_to_machine_mapping[(unsigned int)(pfn)] &
    5.28 +		~FOREIGN_FRAME_BIT;
    5.29 +}
    5.30 +
    5.31 +static inline int phys_to_machine_mapping_valid(unsigned long pfn)
    5.32 +{
    5.33 +	if (xen_feature(XENFEAT_auto_translated_physmap))
    5.34 +		return 1;
    5.35 +	return (phys_to_machine_mapping[pfn] != INVALID_P2M_ENTRY);
    5.36 +}
    5.37 +
    5.38 +static inline unsigned long mfn_to_pfn(unsigned long mfn)
    5.39 +{
    5.40 +	unsigned long pfn;
    5.41 +
    5.42 +	if (xen_feature(XENFEAT_auto_translated_physmap))
    5.43 +		return mfn;
    5.44 +
    5.45 +	if (unlikely((mfn >> machine_to_phys_order) != 0))
    5.46 +		return end_pfn;
    5.47 +
    5.48 +	/* The array access can fail (e.g., device space beyond end of RAM). */
    5.49 +	asm (
    5.50 +		"1:	movq %1,%0\n"
    5.51 +		"2:\n"
    5.52 +		".section .fixup,\"ax\"\n"
    5.53 +		"3:	movq %2,%0\n"
    5.54 +		"	jmp  2b\n"
    5.55 +		".previous\n"
    5.56 +		".section __ex_table,\"a\"\n"
    5.57 +		"	.align 8\n"
    5.58 +		"	.quad 1b,3b\n"
    5.59 +		".previous"
    5.60 +		: "=r" (pfn)
    5.61 +		: "m" (machine_to_phys_mapping[mfn]), "m" (end_pfn) );
    5.62 +
    5.63 +	return pfn;
    5.64 +}
    5.65 +
    5.66 +/*
    5.67 + * We detect special mappings in one of two ways:
    5.68 + *  1. If the MFN is an I/O page then Xen will set the m2p entry
    5.69 + *     to be outside our maximum possible pseudophys range.
    5.70 + *  2. If the MFN belongs to a different domain then we will certainly
    5.71 + *     not have MFN in our p2m table. Conversely, if the page is ours,
    5.72 + *     then we'll have p2m(m2p(MFN))==MFN.
    5.73 + * If we detect a special mapping then it doesn't have a 'struct page'.
    5.74 + * We force !pfn_valid() by returning an out-of-range pointer.
    5.75 + *
    5.76 + * NB. These checks require that, for any MFN that is not in our reservation,
    5.77 + * there is no PFN such that p2m(PFN) == MFN. Otherwise we can get confused if
    5.78 + * we are foreign-mapping the MFN, and the other domain as m2p(MFN) == PFN.
    5.79 + * Yikes! Various places must poke in INVALID_P2M_ENTRY for safety.
    5.80 + *
    5.81 + * NB2. When deliberately mapping foreign pages into the p2m table, you *must*
    5.82 + *      use FOREIGN_FRAME(). This will cause pte_pfn() to choke on it, as we
    5.83 + *      require. In all the cases we care about, the FOREIGN_FRAME bit is
    5.84 + *      masked (e.g., pfn_to_mfn()) so behaviour there is correct.
    5.85 + */
    5.86 +static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
    5.87 +{
    5.88 +	unsigned long pfn = mfn_to_pfn(mfn);
    5.89 +	if ((pfn < end_pfn)
    5.90 +	    && !xen_feature(XENFEAT_auto_translated_physmap)
    5.91 +	    && (phys_to_machine_mapping[pfn] != mfn))
    5.92 +		return end_pfn; /* force !pfn_valid() */
    5.93 +	return pfn;
    5.94 +}
    5.95 +
    5.96 +static inline void set_phys_to_machine(unsigned long pfn, unsigned long mfn)
    5.97 +{
    5.98 +	if (xen_feature(XENFEAT_auto_translated_physmap)) {
    5.99 +		BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY);
   5.100 +		return;
   5.101 +	}
   5.102 +	phys_to_machine_mapping[pfn] = mfn;
   5.103 +}
   5.104 +
   5.105 +#else /* !CONFIG_XEN */
   5.106 +
   5.107 +#define pfn_to_mfn(pfn) (pfn)
   5.108 +#define mfn_to_pfn(mfn) (mfn)
   5.109 +#define mfn_to_local_pfn(mfn) (mfn)
   5.110 +#define set_phys_to_machine(pfn, mfn) BUG_ON((pfn) != (mfn))
   5.111 +#define phys_to_machine_mapping_valid(pfn) (1)
   5.112 +
   5.113 +#endif /* !CONFIG_XEN */
   5.114 +
   5.115 +/* Definitions for machine and pseudophysical addresses. */
   5.116 +typedef unsigned long paddr_t;
   5.117 +typedef unsigned long maddr_t;
   5.118 +
   5.119 +static inline maddr_t phys_to_machine(paddr_t phys)
   5.120 +{
   5.121 +	maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT);
   5.122 +	machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
   5.123 +	return machine;
   5.124 +}
   5.125 +
   5.126 +static inline paddr_t machine_to_phys(maddr_t machine)
   5.127 +{
   5.128 +	paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT);
   5.129 +	phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
   5.130 +	return phys;
   5.131 +}
   5.132 +
   5.133 +/* VIRT <-> MACHINE conversion */
   5.134 +#define virt_to_machine(v)	(phys_to_machine(__pa(v)))
   5.135 +#define virt_to_mfn(v)		(pfn_to_mfn(__pa(v) >> PAGE_SHIFT))
   5.136 +#define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
   5.137 +
   5.138 +#define __pte_ma(x)     ((pte_t) { (x) } )
   5.139 +#define pfn_pte_ma(pfn, prot)	__pte_ma((((pfn) << PAGE_SHIFT) | pgprot_val(prot)) & __supported_pte_mask)
   5.140 +
   5.141 +#endif /* _X86_64_MADDR_H */
   5.142 +
     6.1 --- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/page.h	Mon Aug 14 11:35:57 2006 +0100
     6.2 +++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/page.h	Mon Aug 14 13:54:10 2006 +0100
     6.3 @@ -7,7 +7,6 @@
     6.4  #include <linux/kernel.h>
     6.5  #include <linux/types.h>
     6.6  #include <asm/bug.h>
     6.7 -#include <xen/features.h>
     6.8  #endif
     6.9  #include <xen/interface/xen.h> 
    6.10  #include <xen/foreign_page.h>
    6.11 @@ -69,6 +68,8 @@
    6.12  
    6.13  extern unsigned long end_pfn;
    6.14  
    6.15 +#include <asm/maddr.h>
    6.16 +
    6.17  void clear_page(void *);
    6.18  void copy_page(void *, void *);
    6.19  
    6.20 @@ -78,118 +79,6 @@ void copy_page(void *, void *);
    6.21  #define alloc_zeroed_user_highpage(vma, vaddr) alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO, vma, vaddr)
    6.22  #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
    6.23  
    6.24 -/**** MACHINE <-> PHYSICAL CONVERSION MACROS ****/
    6.25 -#define INVALID_P2M_ENTRY	(~0UL)
    6.26 -#define FOREIGN_FRAME_BIT	(1UL<<63)
    6.27 -#define FOREIGN_FRAME(m)	((m) | FOREIGN_FRAME_BIT)
    6.28 -
    6.29 -extern unsigned long *phys_to_machine_mapping;
    6.30 -
    6.31 -#undef machine_to_phys_mapping
    6.32 -extern unsigned long *machine_to_phys_mapping;
    6.33 -extern unsigned int   machine_to_phys_order;
    6.34 -
    6.35 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
    6.36 -{
    6.37 -	if (xen_feature(XENFEAT_auto_translated_physmap))
    6.38 -		return pfn;
    6.39 -	return phys_to_machine_mapping[(unsigned int)(pfn)] &
    6.40 -		~FOREIGN_FRAME_BIT;
    6.41 -}
    6.42 -
    6.43 -static inline int phys_to_machine_mapping_valid(unsigned long pfn)
    6.44 -{
    6.45 -	if (xen_feature(XENFEAT_auto_translated_physmap))
    6.46 -		return 1;
    6.47 -	return (phys_to_machine_mapping[pfn] != INVALID_P2M_ENTRY);
    6.48 -}
    6.49 -
    6.50 -static inline unsigned long mfn_to_pfn(unsigned long mfn)
    6.51 -{
    6.52 -	unsigned long pfn;
    6.53 -
    6.54 -	if (xen_feature(XENFEAT_auto_translated_physmap))
    6.55 -		return mfn;
    6.56 -
    6.57 -	if (unlikely((mfn >> machine_to_phys_order) != 0))
    6.58 -		return end_pfn;
    6.59 -
    6.60 -	/* The array access can fail (e.g., device space beyond end of RAM). */
    6.61 -	asm (
    6.62 -		"1:	movq %1,%0\n"
    6.63 -		"2:\n"
    6.64 -		".section .fixup,\"ax\"\n"
    6.65 -		"3:	movq %2,%0\n"
    6.66 -		"	jmp  2b\n"
    6.67 -		".previous\n"
    6.68 -		".section __ex_table,\"a\"\n"
    6.69 -		"	.align 8\n"
    6.70 -		"	.quad 1b,3b\n"
    6.71 -		".previous"
    6.72 -		: "=r" (pfn)
    6.73 -		: "m" (machine_to_phys_mapping[mfn]), "m" (end_pfn) );
    6.74 -
    6.75 -	return pfn;
    6.76 -}
    6.77 -
    6.78 -/*
    6.79 - * We detect special mappings in one of two ways:
    6.80 - *  1. If the MFN is an I/O page then Xen will set the m2p entry
    6.81 - *     to be outside our maximum possible pseudophys range.
    6.82 - *  2. If the MFN belongs to a different domain then we will certainly
    6.83 - *     not have MFN in our p2m table. Conversely, if the page is ours,
    6.84 - *     then we'll have p2m(m2p(MFN))==MFN.
    6.85 - * If we detect a special mapping then it doesn't have a 'struct page'.
    6.86 - * We force !pfn_valid() by returning an out-of-range pointer.
    6.87 - *
    6.88 - * NB. These checks require that, for any MFN that is not in our reservation,
    6.89 - * there is no PFN such that p2m(PFN) == MFN. Otherwise we can get confused if
    6.90 - * we are foreign-mapping the MFN, and the other domain as m2p(MFN) == PFN.
    6.91 - * Yikes! Various places must poke in INVALID_P2M_ENTRY for safety.
    6.92 - *
    6.93 - * NB2. When deliberately mapping foreign pages into the p2m table, you *must*
    6.94 - *      use FOREIGN_FRAME(). This will cause pte_pfn() to choke on it, as we
    6.95 - *      require. In all the cases we care about, the FOREIGN_FRAME bit is
    6.96 - *      masked (e.g., pfn_to_mfn()) so behaviour there is correct.
    6.97 - */
    6.98 -static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
    6.99 -{
   6.100 -	unsigned long pfn = mfn_to_pfn(mfn);
   6.101 -	if ((pfn < end_pfn)
   6.102 -	    && !xen_feature(XENFEAT_auto_translated_physmap)
   6.103 -	    && (phys_to_machine_mapping[pfn] != mfn))
   6.104 -		return end_pfn; /* force !pfn_valid() */
   6.105 -	return pfn;
   6.106 -}
   6.107 -
   6.108 -
   6.109 -static inline void set_phys_to_machine(unsigned long pfn, unsigned long mfn)
   6.110 -{
   6.111 -	if (xen_feature(XENFEAT_auto_translated_physmap)) {
   6.112 -		BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY);
   6.113 -		return;
   6.114 -	}
   6.115 -	phys_to_machine_mapping[pfn] = mfn;
   6.116 -}
   6.117 -
   6.118 -/* Definitions for machine and pseudophysical addresses. */
   6.119 -typedef unsigned long paddr_t;
   6.120 -typedef unsigned long maddr_t;
   6.121 -
   6.122 -static inline maddr_t phys_to_machine(paddr_t phys)
   6.123 -{
   6.124 -	maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT);
   6.125 -	machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
   6.126 -	return machine;
   6.127 -}
   6.128 -
   6.129 -static inline paddr_t machine_to_phys(maddr_t machine)
   6.130 -{
   6.131 -	paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT);
   6.132 -	phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
   6.133 -	return phys;
   6.134 -}
   6.135 -
   6.136  /*
   6.137   * These are used to make use of C type-checking..
   6.138   */
   6.139 @@ -228,8 +117,6 @@ static inline unsigned long pgd_val(pgd_
   6.140  
   6.141  #define pgprot_val(x)	((x).pgprot)
   6.142  
   6.143 -#define __pte_ma(x)     ((pte_t) { (x) } )
   6.144 -
   6.145  static inline pte_t __pte(unsigned long x)
   6.146  {
   6.147  	if (x & 1) x = phys_to_machine(x);
   6.148 @@ -310,11 +197,6 @@ static inline pgd_t __pgd(unsigned long 
   6.149  #define virt_addr_valid(kaddr)	pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
   6.150  #define pfn_to_kaddr(pfn)      __va((pfn) << PAGE_SHIFT)
   6.151  
   6.152 -/* VIRT <-> MACHINE conversion */
   6.153 -#define virt_to_machine(v)	(phys_to_machine(__pa(v)))
   6.154 -#define virt_to_mfn(v)		(pfn_to_mfn(__pa(v) >> PAGE_SHIFT))
   6.155 -#define mfn_to_virt(m)		(__va(mfn_to_pfn(m) << PAGE_SHIFT))
   6.156 -
   6.157  #define VM_DATA_DEFAULT_FLAGS \
   6.158  	(((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \
   6.159  	 VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
     7.1 --- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/pgtable.h	Mon Aug 14 11:35:57 2006 +0100
     7.2 +++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/pgtable.h	Mon Aug 14 13:54:10 2006 +0100
     7.3 @@ -312,7 +312,6 @@ static inline pte_t pfn_pte(unsigned lon
     7.4  	return pte;
     7.5  }
     7.6  
     7.7 -#define pfn_pte_ma(pfn, prot)	__pte_ma((((pfn) << PAGE_SHIFT) | pgprot_val(prot)) & __supported_pte_mask)
     7.8  /*
     7.9   * The following only work if pte_present() is true.
    7.10   * Undefined behaviour if not..