# HG changeset patch # User yamahata@xxxxxxxxxxxxx # Date 1164001010 -32400 # Node ID 9a66bfb0e7a3a4d6294ff1ab7bdbc8ac9d353c36 # Parent f0ba459065d32b61c9d04ccde5787e48e23be782 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. PATCHNAME: xen_dev_mem_ia64 Signed-off-by: Isaku Yamahata diff -r f0ba459065d3 -r 9a66bfb0e7a3 linux-2.6-xen-sparse/drivers/xen/char/mem.c --- a/linux-2.6-xen-sparse/drivers/xen/char/mem.c Thu Nov 16 18:47:28 2006 -0800 +++ b/linux-2.6-xen-sparse/drivers/xen/char/mem.c Mon Nov 20 14:36:50 2006 +0900 @@ -28,13 +28,12 @@ #include #include -static inline int uncached_access(struct file *file) -{ - if (file->f_flags & O_SYNC) - return 1; - /* Xen sets correct MTRR type on non-RAM for us. */ - return 0; -} +#ifndef ARCH_HAS_VALID_PHYS_ADDR_RANGE +static inline int valid_phys_addr_range(unsigned long addr, size_t *count) +{ + return 1; +} +#endif /* * This funcion reads the *physical* memory. The f_pos points directly to the @@ -46,6 +45,9 @@ static ssize_t read_mem(struct file * fi unsigned long p = *ppos, ignored; ssize_t read = 0, sz; void __iomem *v; + + if (!valid_phys_addr_range(p, &count)) + return -EFAULT; while (count > 0) { /* @@ -58,7 +60,13 @@ static ssize_t read_mem(struct file * fi sz = min_t(unsigned long, sz, count); - if ((v = ioremap(p, sz)) == NULL) { + /* + * On ia64 if a page has been mapped somewhere as + * uncached, then it must also be accessed uncached + * by the kernel or data corruption may occur + */ + v = xlate_dev_mem_ptr(p, sz); + if (IS_ERR(v) || v == NULL) { /* * Some programs (e.g., dmidecode) groove off into weird RAM * areas where no tables can possibly exist (because Xen will @@ -68,12 +76,14 @@ static ssize_t read_mem(struct file * fi */ if (clear_user(buf, count)) return -EFAULT; + if (IS_ERR(v) && read == 0) + return PTR_ERR(v); read += count; break; } ignored = copy_to_user(buf, v, sz); - iounmap(v); + xlate_dev_mem_ptr_unmap(v); if (ignored) return -EFAULT; buf += sz; @@ -93,6 +103,9 @@ static ssize_t write_mem(struct file * f ssize_t written = 0, sz; void __iomem *v; + if (!valid_phys_addr_range(p, &count)) + return -EFAULT; + while (count > 0) { /* * Handle first page in case it's not aligned @@ -104,11 +117,22 @@ static ssize_t write_mem(struct file * f sz = min_t(unsigned long, sz, count); - if ((v = ioremap(p, sz)) == NULL) - break; + /* + * On ia64 if a page has been mapped somewhere as + * uncached, then it must also be accessed uncached + * by the kernel or data corruption may occur + */ + v = xlate_dev_mem_ptr(p, sz); + if (v == NULL) + break; + if (IS_ERR(v)) { + if (written == 0) + return PTR_ERR(v); + break; + } ignored = copy_from_user(v, buf, sz); - iounmap(v); + xlate_dev_mem_ptr_unmap(v); if (ignored) { written += sz - ignored; if (written) @@ -125,6 +149,15 @@ static ssize_t write_mem(struct file * f return written; } +#ifndef ARCH_HAS_DEV_MEM_MMAP_MEM +static inline int uncached_access(struct file *file) +{ + if (file->f_flags & O_SYNC) + return 1; + /* Xen sets correct MTRR type on non-RAM for us. */ + return 0; +} + static int mmap_mem(struct file * file, struct vm_area_struct * vma) { size_t size = vma->vm_end - vma->vm_start; @@ -136,6 +169,7 @@ static int mmap_mem(struct file * file, return direct_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, size, vma->vm_page_prot, DOMID_IO); } +#endif /* * The memory devices use the full 32/64 bits of the offset, and so we cannot diff -r f0ba459065d3 -r 9a66bfb0e7a3 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/io.h --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/io.h Thu Nov 16 18:47:28 2006 -0800 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/io.h Mon Nov 20 14:36:50 2006 +0900 @@ -54,7 +54,8 @@ * Convert a physical pointer to a virtual kernel pointer for /dev/mem * access */ -#define xlate_dev_mem_ptr(p) __va(p) +#define xlate_dev_mem_ptr(p, sz) ioremap(p, sz) +#define xlate_dev_mem_ptr_unmap(p) iounmap(p) /* * Convert a virtual cached pointer to an uncached pointer diff -r f0ba459065d3 -r 9a66bfb0e7a3 linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/io.h --- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/io.h Thu Nov 16 18:47:28 2006 -0800 +++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/io.h Mon Nov 20 14:36:50 2006 +0900 @@ -346,7 +346,8 @@ extern int iommu_bio_merge; * Convert a physical pointer to a virtual kernel pointer for /dev/mem * access */ -#define xlate_dev_mem_ptr(p) __va(p) +#define xlate_dev_mem_ptr(p, sz) ioremap(p, sz) +#define xlate_dev_mem_ptr_unmap(p) iounmap(p) /* * Convert a virtual cached pointer to an uncached pointer