x86: fix /dev/mem compatibility under PAT
authorVenkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Thu, 10 Jul 2008 08:09:59 +0000 (10:09 +0200)
committerIngo Molnar <mingo@elte.hu>
Thu, 10 Jul 2008 08:09:59 +0000 (10:09 +0200)
Add ioremap_default(), which gives a sane mapping without worrying about
type conflicts.

Use it in /dev/mem read in place of ioremap(), as with ioremap(),
any mapping of the region (other than UC_MINUS) will cause a conflict
and failure of /dev/mem read.

Should address the vbetest failure reported at:

  http://bugzilla.kernel.org/show_bug.cgi?id=11057

Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
arch/x86/mm/ioremap.c

index 2b2bb3f9b683156b7ef25aac9ccfeca69e90d364..d1b867101e5f01e74d296e52cdbd0d4801dd43e5 100644 (file)
@@ -300,6 +300,29 @@ void __iomem *ioremap_cache(resource_size_t phys_addr, unsigned long size)
 }
 EXPORT_SYMBOL(ioremap_cache);
 
+static void __iomem *ioremap_default(resource_size_t phys_addr,
+                                       unsigned long size)
+{
+       unsigned long flags;
+       void *ret;
+       int err;
+
+       /*
+        * - WB for WB-able memory and no other conflicting mappings
+        * - UC_MINUS for non-WB-able memory with no other conflicting mappings
+        * - Inherit from confliting mappings otherwise
+        */
+       err = reserve_memtype(phys_addr, phys_addr + size, -1, &flags);
+       if (err < 0)
+               return NULL;
+
+       ret = (void *) __ioremap_caller(phys_addr, size, flags,
+                                       __builtin_return_address(0));
+
+       free_memtype(phys_addr, phys_addr + size);
+       return (void __iomem *)ret;
+}
+
 /**
  * iounmap - Free a IO remapping
  * @addr: virtual address from ioremap_*
@@ -365,7 +388,7 @@ void *xlate_dev_mem_ptr(unsigned long phys)
        if (page_is_ram(start >> PAGE_SHIFT))
                return __va(phys);
 
-       addr = (void *)ioremap(start, PAGE_SIZE);
+       addr = (void *)ioremap_default(start, PAGE_SIZE);
        if (addr)
                addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));