]> Pileus Git - ~andy/linux/commitdiff
arm64: allow ioremap_cache() to use existing RAM mappings
authorMark Salter <msalter@redhat.com>
Thu, 24 Oct 2013 14:54:17 +0000 (15:54 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Wed, 30 Oct 2013 12:10:37 +0000 (12:10 +0000)
Some drivers (ACPI notably) use ioremap_cache() to map an area which could
either be outside of kernel RAM or in an already mapped reserved area of
RAM. To avoid aliases with different caching attributes, ioremap() does
not allow RAM to be remapped. But for ioremap_cache(), the existing kernel
mapping may be used.

Signed-off-by: Mark Salter <msalter@redhat.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/include/asm/io.h
arch/arm64/mm/ioremap.c

index 1d12f89140ba0a24bf1975b5425490b7dffb1fc9..b56e5b5df881e514ffeb21b227ebbd8b54fe3d29 100644 (file)
@@ -224,6 +224,7 @@ extern void __memset_io(volatile void __iomem *, int, size_t);
  */
 extern void __iomem *__ioremap(phys_addr_t phys_addr, size_t size, pgprot_t prot);
 extern void __iounmap(volatile void __iomem *addr);
+extern void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size);
 
 #define PROT_DEFAULT           (PTE_TYPE_PAGE | PTE_AF | PTE_DIRTY)
 #define PROT_DEVICE_nGnRE      (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_ATTRINDX(MT_DEVICE_nGnRE))
@@ -233,7 +234,6 @@ extern void __iounmap(volatile void __iomem *addr);
 #define ioremap(addr, size)            __ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE))
 #define ioremap_nocache(addr, size)    __ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE))
 #define ioremap_wc(addr, size)         __ioremap((addr), (size), __pgprot(PROT_NORMAL_NC))
-#define ioremap_cached(addr, size)     __ioremap((addr), (size), __pgprot(PROT_NORMAL))
 #define iounmap                                __iounmap
 
 #define PROT_SECT_DEFAULT      (PMD_TYPE_SECT | PMD_SECT_AF)
index 1725cd6db37a8f5e6a76f84192ef704838efb446..2bb1d586664cc98ce88a0e19db8cb55c6b8b1c53 100644 (file)
@@ -77,8 +77,24 @@ EXPORT_SYMBOL(__ioremap);
 
 void __iounmap(volatile void __iomem *io_addr)
 {
-       void *addr = (void *)(PAGE_MASK & (unsigned long)io_addr);
+       unsigned long addr = (unsigned long)io_addr & PAGE_MASK;
 
-       vunmap(addr);
+       /*
+        * We could get an address outside vmalloc range in case
+        * of ioremap_cache() reusing a RAM mapping.
+        */
+       if (VMALLOC_START <= addr && addr < VMALLOC_END)
+               vunmap((void *)addr);
 }
 EXPORT_SYMBOL(__iounmap);
+
+void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size)
+{
+       /* For normal memory we already have a cacheable mapping. */
+       if (pfn_valid(__phys_to_pfn(phys_addr)))
+               return (void __iomem *)__phys_to_virt(phys_addr);
+
+       return __ioremap_caller(phys_addr, size, __pgprot(PROT_NORMAL),
+                               __builtin_return_address(0));
+}
+EXPORT_SYMBOL(ioremap_cache);