]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
arch:unicore32:mm: add devmem_is_allowed() to support STRICT_DEVMEM
authorChen Gang <gang.chen.5i5j@gmail.com>
Tue, 15 Apr 2014 01:21:30 +0000 (09:21 +0800)
committerGuan Xuetao <gxt@mprc.pku.edu.cn>
Fri, 20 Jun 2014 00:22:40 +0000 (08:22 +0800)
unicore32 supports STRICT_DEVMEM, so it needs devmem_is_allowed(), like
some of other architectures have done (e.g. arm, powerpc, x86 ...).

The related error with allmodconfig:

    CC      drivers/char/mem.o
  drivers/char/mem.c: In function â\80\98range_is_allowedâ\80\99:
  drivers/char/mem.c:69: error: implicit declaration of function â\80\98devmem_is_allowedâ\80\99
  make[2]: *** [drivers/char/mem.o] Error 1
  make[1]: *** [drivers/char] Error 2
  make: *** [drivers] Error 2

Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
Acked-by: Xuetao Guan <gxt@mprc.pku.edu.cn>
Signed-off-by: Xuetao Guan <gxt@mprc.pku.edu.cn>
arch/unicore32/include/asm/io.h

index d6920301465a195a660d92b42be25a41358be948..cb1d8fd2b16b22554b32625fadbc31d7bcd6c207 100644 (file)
@@ -48,5 +48,28 @@ extern void __uc32_iounmap(volatile void __iomem *addr);
 #define PIO_MASK               (unsigned int)(IO_SPACE_LIMIT)
 #define PIO_RESERVED           (PIO_OFFSET + PIO_MASK + 1)
 
+#ifdef CONFIG_STRICT_DEVMEM
+
+#include <linux/ioport.h>
+#include <linux/mm.h>
+
+/*
+ * devmem_is_allowed() checks to see if /dev/mem access to a certain
+ * address is valid. The argument is a physical page number.
+ * We mimic x86 here by disallowing access to system RAM as well as
+ * device-exclusive MMIO regions. This effectively disable read()/write()
+ * on /dev/mem.
+ */
+static inline int devmem_is_allowed(unsigned long pfn)
+{
+       if (iomem_is_exclusive(pfn << PAGE_SHIFT))
+               return 0;
+       if (!page_is_ram(pfn))
+               return 1;
+       return 0;
+}
+
+#endif /* CONFIG_STRICT_DEVMEM */
+
 #endif /* __KERNEL__ */
 #endif /* __UNICORE_IO_H__ */