From 1162b0701b14ba112d4e3fe5c27c694caf983539 Mon Sep 17 00:00:00 2001 From: Vineet Gupta Date: Fri, 18 Jan 2013 15:12:20 +0530 Subject: ARC: I/O and DMA Mappings Signed-off-by: Vineet Gupta --- arch/arc/include/asm/io.h | 103 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 arch/arc/include/asm/io.h (limited to 'arch/arc/include/asm/io.h') diff --git a/arch/arc/include/asm/io.h b/arch/arc/include/asm/io.h new file mode 100644 index 000000000000..d20051bbbf02 --- /dev/null +++ b/arch/arc/include/asm/io.h @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef _ASM_ARC_IO_H +#define _ASM_ARC_IO_H + +#include +#include +#include + +#define PCI_IOBASE ((void __iomem *)0) + +extern void __iomem *ioremap(unsigned long physaddr, unsigned long size); +extern void iounmap(const void __iomem *addr); + +#define ioremap_nocache(phy, sz) ioremap(phy, sz) +#define ioremap_wc(phy, sz) ioremap(phy, sz) + +/* Change struct page to physical address */ +#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT) + +#define __raw_readb __raw_readb +static inline u8 __raw_readb(const volatile void __iomem *addr) +{ + u8 b; + + __asm__ __volatile__( + " ldb%U1 %0, %1 \n" + : "=r" (b) + : "m" (*(volatile u8 __force *)addr) + : "memory"); + + return b; +} + +#define __raw_readw __raw_readw +static inline u16 __raw_readw(const volatile void __iomem *addr) +{ + u16 s; + + __asm__ __volatile__( + " ldw%U1 %0, %1 \n" + : "=r" (s) + : "m" (*(volatile u16 __force *)addr) + : "memory"); + + return s; +} + +#define __raw_readl __raw_readl +static inline u32 __raw_readl(const volatile void __iomem *addr) +{ + u32 w; + + __asm__ __volatile__( + " ld%U1 %0, %1 \n" + : "=r" (w) + : "m" (*(volatile u32 __force *)addr) + : "memory"); + + return w; +} + +#define __raw_writeb __raw_writeb +static inline void __raw_writeb(u8 b, volatile void __iomem *addr) +{ + __asm__ __volatile__( + " stb%U1 %0, %1 \n" + : + : "r" (b), "m" (*(volatile u8 __force *)addr) + : "memory"); +} + +#define __raw_writew __raw_writew +static inline void __raw_writew(u16 s, volatile void __iomem *addr) +{ + __asm__ __volatile__( + " stw%U1 %0, %1 \n" + : + : "r" (s), "m" (*(volatile u16 __force *)addr) + : "memory"); + +} + +#define __raw_writel __raw_writel +static inline void __raw_writel(u32 w, volatile void __iomem *addr) +{ + __asm__ __volatile__( + " st%U1 %0, %1 \n" + : + : "r" (w), "m" (*(volatile u32 __force *)addr) + : "memory"); + +} + +#include + +#endif /* _ASM_ARC_IO_H */ -- cgit v1.2.3 From 4368902bb90f0e208387f336c3fce0e6b2a110fc Mon Sep 17 00:00:00 2001 From: Gilad Ben-Yossef Date: Tue, 22 Jan 2013 16:48:45 +0530 Subject: ARC: Add support for ioremap_prot API 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 CC: Noam Camus Acked-by: Vineet Gupta Signed-off-by: Gilad Ben-Yossef Signed-off-by: Vineet Gupta --- arch/arc/Kconfig | 1 + arch/arc/include/asm/io.h | 2 ++ arch/arc/include/asm/page.h | 3 +++ arch/arc/mm/ioremap.c | 48 +++++++++++++++++++++++++++++++++------------ 4 files changed, 42 insertions(+), 12 deletions(-) (limited to 'arch/arc/include/asm/io.h') diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig index cd4ad61c4c14..2dab40dd8161 100644 --- a/arch/arc/Kconfig +++ b/arch/arc/Kconfig @@ -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 diff --git a/arch/arc/include/asm/io.h b/arch/arc/include/asm/io.h index d20051bbbf02..473424d7528b 100644 --- a/arch/arc/include/asm/io.h +++ b/arch/arc/include/asm/io.h @@ -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) diff --git a/arch/arc/include/asm/page.h b/arch/arc/include/asm/page.h index dfe1f8a95f1d..bdf546104551 100644 --- a/arch/arc/include/asm/page.h +++ b/arch/arc/include/asm/page.h @@ -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 diff --git a/arch/arc/mm/ioremap.c b/arch/arc/mm/ioremap.c index 52518b6d0f28..3e5c92c79936 100644 --- a/arch/arc/mm/ioremap.c +++ b/arch/arc/mm/ioremap.c @@ -16,25 +16,49 @@ 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) { -- cgit v1.2.3