ia64/xen-unstable

changeset 2587:0f3e0ef73bd5

bitkeeper revision 1.1159.98.2 (415e927er1yu43w4cm3_dj36NPzRJA)

A less invasive patch to the /dev/mem char-device driver.
author kaf24@freefall.cl.cam.ac.uk
date Sat Oct 02 11:35:26 2004 +0000 (2004-10-02)
parents 23bc5e8a9321
children 1e99cd1cb3a3
files linux-2.6.8.1-xen-sparse/drivers/char/mem.c
line diff
     1.1 --- a/linux-2.6.8.1-xen-sparse/drivers/char/mem.c	Sat Oct 02 09:46:57 2004 +0000
     1.2 +++ b/linux-2.6.8.1-xen-sparse/drivers/char/mem.c	Sat Oct 02 11:35:26 2004 +0000
     1.3 @@ -6,20 +6,6 @@
     1.4   *  Added devfs support. 
     1.5   *    Jan-11-1998, C. Scott Ananian <cananian@alumni.princeton.edu>
     1.6   *  Shared /dev/zero mmaping support, Feb 2000, Kanoj Sarcar <kanoj@sgi.com>
     1.7 - *
     1.8 - *  MODIFIED FOR XEN by Keir Fraser, 10th July 2003.
     1.9 - *  Linux running on Xen has strange semantics for /dev/mem and /dev/kmem!!
    1.10 - *   1. mmap will not work on /dev/kmem
    1.11 - *   2. mmap on /dev/mem interprets the 'file offset' as a machine address
    1.12 - *      rather than a physical address.
    1.13 - *  I don't believe anyone sane mmaps /dev/kmem, but /dev/mem is mmapped
    1.14 - *  to get at memory-mapped I/O spaces (eg. the VESA X server does this).
    1.15 - *  For this to work at all we need to expect machine addresses.
    1.16 - *  Reading/writing of /dev/kmem expects kernel virtual addresses, as usual.
    1.17 - *  Reading/writing of /dev/mem expects 'physical addresses' as usual -- this
    1.18 - *  is because /dev/mem can only read/write existing kernel mappings, which
    1.19 - *  will be normal RAM, and we should present pseudo-physical layout for all
    1.20 - *  except I/O (which is the sticky case that mmap is hacked to deal with).
    1.21   */
    1.22  
    1.23  #include <linux/config.h>
    1.24 @@ -208,9 +194,9 @@ static ssize_t write_mem(struct file * f
    1.25  	return do_write_mem(__va(p), p, buf, count, ppos);
    1.26  }
    1.27  
    1.28 -#if !defined(CONFIG_XEN)
    1.29  static int mmap_mem(struct file * file, struct vm_area_struct * vma)
    1.30  {
    1.31 +#if !defined(CONFIG_XEN)
    1.32  	unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
    1.33  	int uncached;
    1.34  
    1.35 @@ -233,30 +219,25 @@ static int mmap_mem(struct file * file, 
    1.36  			     vma->vm_page_prot))
    1.37  		return -EAGAIN;
    1.38  	return 0;
    1.39 -}
    1.40  #elif !defined(CONFIG_XEN_PRIVILEGED_GUEST)
    1.41 -static int mmap_mem(struct file * file, struct vm_area_struct * vma)
    1.42 -{
    1.43  	return -ENXIO;
    1.44 -}
    1.45  #else
    1.46 -static int mmap_mem(struct file * file, struct vm_area_struct * vma)
    1.47 -{
    1.48  	unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
    1.49  
    1.50  	if (!(start_info.flags & SIF_PRIVILEGED))
    1.51  		return -ENXIO;
    1.52  
    1.53 -	/* DONTCOPY is essential for Xen as copy_page_range is broken. */
    1.54 -	vma->vm_flags |= VM_RESERVED | VM_IO | VM_DONTCOPY;
    1.55 +	/* Currently we're not smart about setting PTE cacheability. */
    1.56 +	vma->vm_flags |= VM_RESERVED | VM_IO;
    1.57  	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
    1.58 +
    1.59  	if (direct_remap_area_pages(vma->vm_mm, vma->vm_start, offset, 
    1.60  				vma->vm_end-vma->vm_start, vma->vm_page_prot,
    1.61  				DOMID_IO))
    1.62  		return -EAGAIN;
    1.63  	return 0;
    1.64 +#endif
    1.65  }
    1.66 -#endif /* CONFIG_XEN */
    1.67  
    1.68  extern long vread(char *buf, char *addr, unsigned long count);
    1.69  extern long vwrite(char *buf, char *addr, unsigned long count);
    1.70 @@ -634,9 +615,7 @@ static struct file_operations kmem_fops 
    1.71  	.llseek		= memory_lseek,
    1.72  	.read		= read_kmem,
    1.73  	.write		= write_kmem,
    1.74 -#if !defined(CONFIG_XEN)
    1.75  	.mmap		= mmap_kmem,
    1.76 -#endif
    1.77  	.open		= open_kmem,
    1.78  };
    1.79