ia64/xen-unstable

changeset 12778:e5e6893ec699

[IA64] paraviatualize /dev/mem to enable X.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author awilliam@xenbuild.aw
date Mon Dec 04 08:44:57 2006 -0700 (2006-12-04)
parents bef3a5ffd78d
children 27c2e9aa83e9
files linux-2.6-xen-sparse/arch/ia64/Kconfig linux-2.6-xen-sparse/arch/ia64/xen/Makefile linux-2.6-xen-sparse/arch/ia64/xen/mem.c linux-2.6-xen-sparse/include/asm-ia64/io.h linux-2.6-xen-sparse/include/asm-ia64/uaccess.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/ia64/Kconfig	Mon Dec 04 08:37:20 2006 -0700
     1.2 +++ b/linux-2.6-xen-sparse/arch/ia64/Kconfig	Mon Dec 04 08:44:57 2006 -0700
     1.3 @@ -533,9 +533,6 @@ config XEN_BALLOON
     1.4  config XEN_SKBUFF
     1.5  	default y
     1.6  
     1.7 -config XEN_DEVMEM
     1.8 -	default n
     1.9 -
    1.10  config XEN_REBOOT
    1.11  	default y
    1.12  
     2.1 --- a/linux-2.6-xen-sparse/arch/ia64/xen/Makefile	Mon Dec 04 08:37:20 2006 -0700
     2.2 +++ b/linux-2.6-xen-sparse/arch/ia64/xen/Makefile	Mon Dec 04 08:44:57 2006 -0700
     2.3 @@ -4,6 +4,6 @@
     2.4  
     2.5  obj-y := hypercall.o xenivt.o xenentry.o xensetup.o xenpal.o xenhpski.o \
     2.6  	 hypervisor.o pci-dma-xen.o util.o xencomm.o xcom_hcall.o \
     2.7 -	 xcom_mini.o xcom_privcmd.o
     2.8 +	 xcom_mini.o xcom_privcmd.o mem.o
     2.9  
    2.10  pci-dma-xen-y := ../../i386/kernel/pci-dma-xen.o
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/linux-2.6-xen-sparse/arch/ia64/xen/mem.c	Mon Dec 04 08:44:57 2006 -0700
     3.3 @@ -0,0 +1,76 @@
     3.4 +/*
     3.5 + *  Originally from linux/drivers/char/mem.c
     3.6 + *
     3.7 + *  Copyright (C) 1991, 1992  Linus Torvalds
     3.8 + *
     3.9 + *  Added devfs support. 
    3.10 + *    Jan-11-1998, C. Scott Ananian <cananian@alumni.princeton.edu>
    3.11 + *  Shared /dev/zero mmaping support, Feb 2000, Kanoj Sarcar <kanoj@sgi.com>
    3.12 + */
    3.13 +/*
    3.14 + * taken from
    3.15 + * linux/drivers/char/mem.c and linux-2.6-xen-sparse/drivers/xen/char/mem.c.
    3.16 + * adjusted for IA64 and made transparent.
    3.17 + * Copyright (c) 2006 Isaku Yamahata <yamahata at valinux co jp>
    3.18 + *                    VA Linux Systems Japan K.K.
    3.19 + */
    3.20 +
    3.21 +#include <linux/config.h>
    3.22 +#include <linux/mm.h>
    3.23 +#include <linux/efi.h>
    3.24 +
    3.25 +/*
    3.26 + * Architectures vary in how they handle caching for addresses
    3.27 + * outside of main memory.
    3.28 + *
    3.29 + */
    3.30 +static inline int uncached_access(struct file *file, unsigned long addr)
    3.31 +{
    3.32 +	/*
    3.33 +	 * On ia64, we ignore O_SYNC because we cannot tolerate memory attribute aliases.
    3.34 +	 */
    3.35 +	return !(efi_mem_attributes(addr) & EFI_MEMORY_WB);
    3.36 +}
    3.37 +
    3.38 +int xen_mmap_mem(struct file * file, struct vm_area_struct * vma)
    3.39 +{
    3.40 +	unsigned long addr = vma->vm_pgoff << PAGE_SHIFT;
    3.41 +	size_t size = vma->vm_end - vma->vm_start;
    3.42 +
    3.43 +
    3.44 +#if 0
    3.45 +	/*
    3.46 +	 *XXX FIXME: linux-2.6.16.29, linux-2.6.17
    3.47 +	 *    valid_mmap_phys_addr_range() in linux/arch/ia64/kernel/efi.c
    3.48 +	 *    fails checks.
    3.49 +	 *    linux-2.6.18.1's returns always 1. 
    3.50 +	 *    Its comments says
    3.51 +	 *
    3.52 +         * MMIO regions are often missing from the EFI memory map.
    3.53 +         * We must allow mmap of them for programs like X, so we
    3.54 +         * currently can't do any useful validation.
    3.55 +         */
    3.56 +	if (!valid_mmap_phys_addr_range(addr, &size))
    3.57 +		return -EINVAL;
    3.58 +	if (size < vma->vm_end - vma->vm_start)
    3.59 +		return -EINVAL;
    3.60 +#endif
    3.61 +
    3.62 +	if (is_running_on_xen()) {
    3.63 +		unsigned long offset = HYPERVISOR_ioremap(addr, size);
    3.64 +		if (IS_ERR_VALUE(offset))
    3.65 +			return offset;
    3.66 +	}
    3.67 +
    3.68 +	if (uncached_access(file, vma->vm_pgoff << PAGE_SHIFT))
    3.69 +		vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
    3.70 +
    3.71 +        /* Remap-pfn-range will mark the range VM_IO and VM_RESERVED */
    3.72 +        if (remap_pfn_range(vma,
    3.73 +                            vma->vm_start,
    3.74 +                            vma->vm_pgoff,
    3.75 +                            size,
    3.76 +                            vma->vm_page_prot))
    3.77 +                return -EAGAIN;
    3.78 +        return 0;
    3.79 +}
     4.1 --- a/linux-2.6-xen-sparse/include/asm-ia64/io.h	Mon Dec 04 08:37:20 2006 -0700
     4.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/io.h	Mon Dec 04 08:44:57 2006 -0700
     4.3 @@ -129,6 +129,11 @@ extern int valid_mmap_phys_addr_range (u
     4.4  	(((bvec_to_bus((vec1)) + (vec1)->bv_len) == bvec_to_bus((vec2))) && \
     4.5  	 ((bvec_to_pseudophys((vec1)) + (vec1)->bv_len) ==		\
     4.6  	  bvec_to_pseudophys((vec2))))
     4.7 +
     4.8 +/* We will be supplying our own /dev/mem implementation */
     4.9 +#define ARCH_HAS_DEV_MEM
    4.10 +#define ARCH_HAS_DEV_MEM_MMAP_MEM
    4.11 +int xen_mmap_mem(struct file * file, struct vm_area_struct * vma);
    4.12  #endif /* CONFIG_XEN */
    4.13  
    4.14  # endif /* KERNEL */
    4.15 @@ -458,6 +463,8 @@ static inline void __iomem *
    4.16  ioremap (unsigned long offset, unsigned long size)
    4.17  {
    4.18  	offset = HYPERVISOR_ioremap(offset, size);
    4.19 +	if (IS_ERR_VALUE(offset))
    4.20 +		return (void __iomem*)offset;
    4.21  	return (void __iomem *) (__IA64_UNCACHED_OFFSET | (offset));
    4.22  }
    4.23  
     5.1 --- a/linux-2.6-xen-sparse/include/asm-ia64/uaccess.h	Mon Dec 04 08:37:20 2006 -0700
     5.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/uaccess.h	Mon Dec 04 08:44:57 2006 -0700
     5.3 @@ -365,6 +365,7 @@ ia64_done_with_exception (struct pt_regs
     5.4  }
     5.5  
     5.6  #define ARCH_HAS_TRANSLATE_MEM_PTR	1
     5.7 +#ifndef CONFIG_XEN
     5.8  static __inline__ char *
     5.9  xlate_dev_mem_ptr (unsigned long p)
    5.10  {
    5.11 @@ -379,6 +380,25 @@ xlate_dev_mem_ptr (unsigned long p)
    5.12  
    5.13  	return ptr;
    5.14  }
    5.15 +#else
    5.16 +static __inline__ char *
    5.17 +xlate_dev_mem_ptr (unsigned long p, ssize_t sz)
    5.18 +{
    5.19 +	unsigned long pfn = p >> PAGE_SHIFT;
    5.20 +
    5.21 +	if (pfn_valid(pfn) && !PageUncached(pfn_to_page(pfn)))
    5.22 +		return __va(p);
    5.23 +
    5.24 +	return ioremap(p, sz);
    5.25 +}
    5.26 +
    5.27 +static __inline__ void
    5.28 +xlate_dev_mem_ptr_unmap (char* v)
    5.29 +{
    5.30 +	if (REGION_NUMBER(v) == RGN_UNCACHED)
    5.31 +		iounmap(v);
    5.32 +}
    5.33 +#endif
    5.34  
    5.35  /*
    5.36   * Convert a virtual cached kernel memory pointer to an uncached pointer