direct-io.hg

changeset 12513:395aa5609e6d

[LINUX] Make xen /dev/mem aware of IA64 to use X.

The original /dev/mem (linux/drivers/char/mem.c) is aware of IA64
specific issues. On the other hand paravirtualized /dev/mem
(linux-2.6-xen-sparse/drivers/xen/char/mem.c) is simplifed not to be
aware of IA64. This patch makes it IA64-aware to use X on domain0/IA64.
With this patch and ia64-specific patches, X server can boot on domain0/IA64.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author kfraser@localhost.localdomain
date Wed Nov 22 10:23:14 2006 +0000 (2006-11-22)
parents a3c6479c87ef
children fe5ed694b0c2
files linux-2.6-xen-sparse/drivers/xen/char/mem.c linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/io.h linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/io.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/char/mem.c	Wed Nov 22 10:11:36 2006 +0000
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/char/mem.c	Wed Nov 22 10:23:14 2006 +0000
     1.3 @@ -28,13 +28,12 @@
     1.4  #include <asm/io.h>
     1.5  #include <asm/hypervisor.h>
     1.6  
     1.7 -static inline int uncached_access(struct file *file)
     1.8 +#ifndef ARCH_HAS_VALID_PHYS_ADDR_RANGE
     1.9 +static inline int valid_phys_addr_range(unsigned long addr, size_t *count)
    1.10  {
    1.11 -	if (file->f_flags & O_SYNC)
    1.12 -		return 1;
    1.13 -	/* Xen sets correct MTRR type on non-RAM for us. */
    1.14 -	return 0;
    1.15 +	return 1;
    1.16  }
    1.17 +#endif
    1.18  
    1.19  /*
    1.20   * This funcion reads the *physical* memory. The f_pos points directly to the 
    1.21 @@ -47,6 +46,9 @@ static ssize_t read_mem(struct file * fi
    1.22  	ssize_t read = 0, sz;
    1.23  	void __iomem *v;
    1.24  
    1.25 +	if (!valid_phys_addr_range(p, &count))
    1.26 +		return -EFAULT;
    1.27 +
    1.28  	while (count > 0) {
    1.29  		/*
    1.30  		 * Handle first page in case it's not aligned
    1.31 @@ -58,13 +60,15 @@ static ssize_t read_mem(struct file * fi
    1.32  
    1.33  		sz = min_t(unsigned long, sz, count);
    1.34  
    1.35 -		if ((v = ioremap(p, sz)) == NULL) {
    1.36 +		v = xlate_dev_mem_ptr(p, sz);
    1.37 +		if (IS_ERR(v) || v == NULL) {
    1.38  			/*
    1.39 -			 * Some programs (e.g., dmidecode) groove off into weird RAM
    1.40 -			 * areas where no tables can possibly exist (because Xen will
    1.41 -			 * have stomped on them!). These programs get rather upset if
    1.42 -			 * we let them know that Xen failed their access, so we fake
    1.43 -			 * out a read of all zeroes. :-)
    1.44 +			 * Some programs (e.g., dmidecode) groove off into
    1.45 +			 * weird RAM areas where no tables can possibly exist
    1.46 +			 * (because Xen will have stomped on them!). These
    1.47 +			 * programs get rather upset if we let them know that
    1.48 +			 * Xen failed their access, so we fake out a read of
    1.49 +			 * all zeroes.
    1.50  			 */
    1.51  			if (clear_user(buf, count))
    1.52  				return -EFAULT;
    1.53 @@ -73,7 +77,7 @@ static ssize_t read_mem(struct file * fi
    1.54  		}
    1.55  
    1.56  		ignored = copy_to_user(buf, v, sz);
    1.57 -		iounmap(v);
    1.58 +		xlate_dev_mem_ptr_unmap(v);
    1.59  		if (ignored)
    1.60  			return -EFAULT;
    1.61  		buf += sz;
    1.62 @@ -93,6 +97,9 @@ static ssize_t write_mem(struct file * f
    1.63  	ssize_t written = 0, sz;
    1.64  	void __iomem *v;
    1.65  
    1.66 +	if (!valid_phys_addr_range(p, &count))
    1.67 +		return -EFAULT;
    1.68 +
    1.69  	while (count > 0) {
    1.70  		/*
    1.71  		 * Handle first page in case it's not aligned
    1.72 @@ -104,11 +111,17 @@ static ssize_t write_mem(struct file * f
    1.73  
    1.74  		sz = min_t(unsigned long, sz, count);
    1.75  
    1.76 -		if ((v = ioremap(p, sz)) == NULL)
    1.77 +		v = xlate_dev_mem_ptr(p, sz);
    1.78 +		if (v == NULL)
    1.79  			break;
    1.80 +		if (IS_ERR(v)) {
    1.81 +			if (written == 0)
    1.82 +				return PTR_ERR(v);
    1.83 +			break;
    1.84 +		}
    1.85  
    1.86  		ignored = copy_from_user(v, buf, sz);
    1.87 -		iounmap(v);
    1.88 +		xlate_dev_mem_ptr_unmap(v);
    1.89  		if (ignored) {
    1.90  			written += sz - ignored;
    1.91  			if (written)
    1.92 @@ -125,6 +138,15 @@ static ssize_t write_mem(struct file * f
    1.93  	return written;
    1.94  }
    1.95  
    1.96 +#ifndef ARCH_HAS_DEV_MEM_MMAP_MEM
    1.97 +static inline int uncached_access(struct file *file)
    1.98 +{
    1.99 +	if (file->f_flags & O_SYNC)
   1.100 +		return 1;
   1.101 +	/* Xen sets correct MTRR type on non-RAM for us. */
   1.102 +	return 0;
   1.103 +}
   1.104 +
   1.105  static int mmap_mem(struct file * file, struct vm_area_struct * vma)
   1.106  {
   1.107  	size_t size = vma->vm_end - vma->vm_start;
   1.108 @@ -136,6 +158,7 @@ static int mmap_mem(struct file * file, 
   1.109  	return direct_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
   1.110  				      size, vma->vm_page_prot, DOMID_IO);
   1.111  }
   1.112 +#endif
   1.113  
   1.114  /*
   1.115   * The memory devices use the full 32/64 bits of the offset, and so we cannot
     2.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/io.h	Wed Nov 22 10:11:36 2006 +0000
     2.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/io.h	Wed Nov 22 10:23:14 2006 +0000
     2.3 @@ -54,7 +54,8 @@
     2.4   * Convert a physical pointer to a virtual kernel pointer for /dev/mem
     2.5   * access
     2.6   */
     2.7 -#define xlate_dev_mem_ptr(p)	__va(p)
     2.8 +#define xlate_dev_mem_ptr(p, sz)	ioremap(p, sz)
     2.9 +#define xlate_dev_mem_ptr_unmap(p)	iounmap(p)
    2.10  
    2.11  /*
    2.12   * Convert a virtual cached pointer to an uncached pointer
     3.1 --- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/io.h	Wed Nov 22 10:11:36 2006 +0000
     3.2 +++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/io.h	Wed Nov 22 10:23:14 2006 +0000
     3.3 @@ -346,7 +346,8 @@ extern int iommu_bio_merge;
     3.4   * Convert a physical pointer to a virtual kernel pointer for /dev/mem
     3.5   * access
     3.6   */
     3.7 -#define xlate_dev_mem_ptr(p)	__va(p)
     3.8 +#define xlate_dev_mem_ptr(p, sz)	ioremap(p, sz)
     3.9 +#define xlate_dev_mem_ptr_unmap(p)	iounmap(p)
    3.10  
    3.11  /*
    3.12   * Convert a virtual cached pointer to an uncached pointer