]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
ARC: Add support for ioremap_prot API
authorGilad Ben-Yossef <gilad@benyossef.com>
Tue, 22 Jan 2013 11:18:45 +0000 (16:48 +0530)
committerVineet Gupta <vgupta@synopsys.com>
Fri, 15 Feb 2013 17:46:11 +0000 (23:16 +0530)
Implement ioremap_prot() to allow mapping IO memory with variable
protection
via TLB.

Implementing this allows the /dev/mem driver to use its generic access()
VMA callback, which in turn allows ptrace to examine data in memory
mapped regions mapped via /dev/mem, such as Arc DCCM.

The end result is that it is possible to examine values of variables
placed into DCCM in user space programs via GDB.

CC: Alexey Brodkin <Alexey.Brodkin@synopsys.com>
CC: Noam Camus <noamc@ezchip.com>
Acked-by: Vineet Gupta <vgupta@synopsys.com>
Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com>
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
arch/arc/Kconfig
arch/arc/include/asm/io.h
arch/arc/include/asm/page.h
arch/arc/mm/ioremap.c

index cd4ad61c4c14bf7343fead74f23b38f5faddc62f..2dab40dd8161d39ec0767efd764292b8826f1c01 100644 (file)
@@ -25,6 +25,7 @@ config ARC
        select HAVE_ARCH_KGDB
        select HAVE_ARCH_TRACEHOOK
        select HAVE_GENERIC_HARDIRQS
+       select HAVE_IOREMAP_PROT
        select HAVE_IRQ_WORK
        select HAVE_KPROBES
        select HAVE_KRETPROBES
index d20051bbbf020f4cd422ee90c94bd954efdc7d07..473424d7528bd344985f3616e641f9823db24aa9 100644 (file)
@@ -16,6 +16,8 @@
 #define PCI_IOBASE ((void __iomem *)0)
 
 extern void __iomem *ioremap(unsigned long physaddr, unsigned long size);
+extern void __iomem *ioremap_prot(phys_addr_t offset, unsigned long size,
+                                 unsigned long flags);
 extern void iounmap(const void __iomem *addr);
 
 #define ioremap_nocache(phy, sz)       ioremap(phy, sz)
index dfe1f8a95f1d8ddd8eaf1a9a32dba7d02f4f12a7..bdf54610455134d1af10a2adad2952f1928b788c 100644 (file)
@@ -48,6 +48,8 @@ typedef unsigned long pgtable_t;
 #define __pgd(x)        ((pgd_t) { (x) })
 #define __pgprot(x)     ((pgprot_t) { (x) })
 
+#define pte_pgprot(x) __pgprot(pte_val(x))
+
 #else /* !STRICT_MM_TYPECHECKS */
 
 typedef unsigned long pte_t;
@@ -60,6 +62,7 @@ typedef unsigned long pgtable_t;
 #define pgprot_val(x)  (x)
 #define __pte(x)       (x)
 #define __pgprot(x)    (x)
+#define pte_pgprot(x)  (x)
 
 #endif
 
index 52518b6d0f289ee2e8a9ce2d9b3969752aef4719..3e5c92c79936f302fec7df189dea3796ba7b37c4 100644 (file)
 
 void __iomem *ioremap(unsigned long paddr, unsigned long size)
 {
-       unsigned long vaddr;
-       struct vm_struct *area;
-       unsigned long off, end;
-       const pgprot_t prot = PAGE_KERNEL_NO_CACHE;
+       unsigned long end;
 
        /* Don't allow wraparound or zero size */
        end = paddr + size - 1;
        if (!size || (end < paddr))
                return NULL;
 
-       /* If the region is h/w uncached, nothing special needed */
+       /* If the region is h/w uncached, avoid MMU mappings */
        if (paddr >= ARC_UNCACHED_ADDR_SPACE)
                return (void __iomem *)paddr;
 
+       return ioremap_prot(paddr, size, PAGE_KERNEL_NO_CACHE);
+}
+EXPORT_SYMBOL(ioremap);
+
+/*
+ * ioremap with access flags
+ * Cache semantics wise it is same as ioremap - "forced" uncached.
+ * However unline vanilla ioremap which bypasses ARC MMU for addresses in
+ * ARC hardware uncached region, this one still goes thru the MMU as caller
+ * might need finer access control (R/W/X)
+ */
+void __iomem *ioremap_prot(phys_addr_t paddr, unsigned long size,
+                          unsigned long flags)
+{
+       void __iomem *vaddr;
+       struct vm_struct *area;
+       unsigned long off, end;
+       pgprot_t prot = __pgprot(flags);
+
+       /* Don't allow wraparound, zero size */
+       end = paddr + size - 1;
+       if ((!size) || (end < paddr))
+               return NULL;
+
        /* An early platform driver might end up here */
        if (!slab_is_available())
                return NULL;
 
-       /* Mappings have to be page-aligned, page-sized */
+       /* force uncached */
+       prot = pgprot_noncached(prot);
+
+       /* Mappings have to be page-aligned */
        off = paddr & ~PAGE_MASK;
        paddr &= PAGE_MASK;
        size = PAGE_ALIGN(end + 1) - paddr;
@@ -45,17 +69,17 @@ void __iomem *ioremap(unsigned long paddr, unsigned long size)
        area = get_vm_area(size, VM_IOREMAP);
        if (!area)
                return NULL;
-
        area->phys_addr = paddr;
-       vaddr = (unsigned long)area->addr;
-       if (ioremap_page_range(vaddr, vaddr + size, paddr, prot)) {
-               vfree(area->addr);
+       vaddr = (void __iomem *)area->addr;
+       if (ioremap_page_range((unsigned long)vaddr,
+                              (unsigned long)vaddr + size, paddr, prot)) {
+               vunmap((void __force *)vaddr);
                return NULL;
        }
-
        return (void __iomem *)(off + (char __iomem *)vaddr);
 }
-EXPORT_SYMBOL(ioremap);
+EXPORT_SYMBOL(ioremap_prot);
+
 
 void iounmap(const void __iomem *addr)
 {