# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Node ID 395aa5609e6d10b226b91e673afcfade2f4e3f6f
# Parent a3c6479c87ef06c7bc8a743ef8360211dcda2532
[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@xxxxxxxxxxxxx>
---
linux-2.6-xen-sparse/drivers/xen/char/mem.c | 57 +++++++++-----
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/io.h | 3
linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/io.h | 3
3 files changed, 44 insertions(+), 19 deletions(-)
diff -r a3c6479c87ef -r 395aa5609e6d linux-2.6-xen-sparse/drivers/xen/char/mem.c
--- a/linux-2.6-xen-sparse/drivers/xen/char/mem.c Wed Nov 22 10:11:36
2006 +0000
+++ b/linux-2.6-xen-sparse/drivers/xen/char/mem.c Wed Nov 22 10:23:14
2006 +0000
@@ -28,13 +28,12 @@
#include <asm/io.h>
#include <asm/hypervisor.h>
-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,13 +60,15 @@ static ssize_t read_mem(struct file * fi
sz = min_t(unsigned long, sz, count);
- if ((v = ioremap(p, sz)) == NULL) {
+ 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
- * have stomped on them!). These programs get rather
upset if
- * we let them know that Xen failed their access, so we
fake
- * out a read of all zeroes. :-)
+ * Some programs (e.g., dmidecode) groove off into
+ * weird RAM areas where no tables can possibly exist
+ * (because Xen will have stomped on them!). These
+ * programs get rather upset if we let them know that
+ * Xen failed their access, so we fake out a read of
+ * all zeroes.
*/
if (clear_user(buf, count))
return -EFAULT;
@@ -73,7 +77,7 @@ static ssize_t read_mem(struct file * fi
}
ignored = copy_to_user(buf, v, sz);
- iounmap(v);
+ xlate_dev_mem_ptr_unmap(v);
if (ignored)
return -EFAULT;
buf += sz;
@@ -92,6 +96,9 @@ static ssize_t write_mem(struct file * f
unsigned long p = *ppos, ignored;
ssize_t written = 0, sz;
void __iomem *v;
+
+ if (!valid_phys_addr_range(p, &count))
+ return -EFAULT;
while (count > 0) {
/*
@@ -104,11 +111,17 @@ static ssize_t write_mem(struct file * f
sz = min_t(unsigned long, sz, count);
- if ((v = ioremap(p, sz)) == NULL)
- break;
+ 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 +138,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 +158,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 a3c6479c87ef -r 395aa5609e6d
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 Wed Nov 22
10:11:36 2006 +0000
+++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/io.h Wed Nov 22
10:23:14 2006 +0000
@@ -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 a3c6479c87ef -r 395aa5609e6d
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 Wed Nov 22
10:11:36 2006 +0000
+++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/io.h Wed Nov 22
10:23:14 2006 +0000
@@ -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
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|