ARM: Provide definitions and helpers for decoding the FSR register
[firefly-linux-kernel-4.4.55.git] / arch / arm / mm / fault.c
index 6fdcbb709827f695ee8a7047708ffaa89a504c0e..1bb38712c86b630542b2ef39199844a2a17b1ebb 100644 (file)
@@ -16,6 +16,8 @@
 #include <linux/kprobes.h>
 #include <linux/uaccess.h>
 #include <linux/page-flags.h>
+#include <linux/sched.h>
+#include <linux/highmem.h>
 
 #include <asm/system.h>
 #include <asm/pgtable.h>
 
 #include "fault.h"
 
+/*
+ * Fault status register encodings
+ */
+#define FSR_WRITE              (1 << 11)
+#define FSR_FS4                        (1 << 10)
+#define FSR_FS3_0              (15)
+
+static inline int fsr_fs(unsigned int fsr)
+{
+       return (fsr & FSR_FS3_0) | (fsr & FSR_FS4) >> 6;
+}
+
+#ifdef CONFIG_MMU
 
 #ifdef CONFIG_KPROBES
 static inline int notify_page_fault(struct pt_regs *regs, unsigned int fsr)
@@ -97,6 +112,10 @@ void show_pte(struct mm_struct *mm, unsigned long addr)
 
        printk("\n");
 }
+#else                                  /* CONFIG_MMU */
+void show_pte(struct mm_struct *mm, unsigned long addr)
+{ }
+#endif                                 /* CONFIG_MMU */
 
 /*
  * Oops.  The kernel tried to access some page that wasn't present.
@@ -171,6 +190,7 @@ void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
                __do_kernel_fault(mm, addr, fsr, regs);
 }
 
+#ifdef CONFIG_MMU
 #define VM_FAULT_BADMAP                0x010000
 #define VM_FAULT_BADACCESS     0x020000
 
@@ -193,7 +213,7 @@ __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
         * memory access, so we can handle it.
         */
 good_area:
-       if (fsr & (1 << 11)) /* write? */
+       if (fsr & FSR_WRITE)
                mask = VM_WRITE;
        else
                mask = VM_READ|VM_EXEC|VM_WRITE;
@@ -208,7 +228,7 @@ good_area:
         * than endlessly redo the fault.
         */
 survive:
-       fault = handle_mm_fault(mm, vma, addr & PAGE_MASK, (fsr & (1 << 11)) ? FAULT_FLAG_WRITE : 0);
+       fault = handle_mm_fault(mm, vma, addr & PAGE_MASK, (fsr & FSR_WRITE) ? FAULT_FLAG_WRITE : 0);
        if (unlikely(fault & VM_FAULT_ERROR)) {
                if (fault & VM_FAULT_OOM)
                        goto out_of_memory;
@@ -322,6 +342,13 @@ no_context:
        __do_kernel_fault(mm, addr, fsr, regs);
        return 0;
 }
+#else                                  /* CONFIG_MMU */
+static int
+do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
+{
+       return 0;
+}
+#endif                                 /* CONFIG_MMU */
 
 /*
  * First Level Translation Fault Handler
@@ -340,6 +367,7 @@ no_context:
  * interrupt or a critical region, and should only copy the information
  * from the master page table, nothing more.
  */
+#ifdef CONFIG_MMU
 static int __kprobes
 do_translation_fault(unsigned long addr, unsigned int fsr,
                     struct pt_regs *regs)
@@ -378,6 +406,14 @@ bad_area:
        do_bad_area(addr, fsr, regs);
        return 0;
 }
+#else                                  /* CONFIG_MMU */
+static int
+do_translation_fault(unsigned long addr, unsigned int fsr,
+                    struct pt_regs *regs)
+{
+       return 0;
+}
+#endif                                 /* CONFIG_MMU */
 
 /*
  * Some section permission faults need to be handled gracefully.
@@ -465,7 +501,7 @@ hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *)
 asmlinkage void __exception
 do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
 {
-       const struct fsr_info *inf = fsr_info + (fsr & 15) + ((fsr & (1 << 10)) >> 6);
+       const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
        struct siginfo info;
 
        if (!inf->fn(addr, fsr, regs))