/* Disable Branch Return Cache */
 #define R10K_DIAG_D_BRC                (_ULCAST_(1) << 22)
 
+/* Flush ITLB */
+#define LOONGSON_DIAG_ITLB     (_ULCAST_(1) << 2)
+/* Flush DTLB */
+#define LOONGSON_DIAG_DTLB     (_ULCAST_(1) << 3)
+/* Flush VTLB */
+#define LOONGSON_DIAG_VTLB     (_ULCAST_(1) << 12)
+/* Flush FTLB */
+#define LOONGSON_DIAG_FTLB     (_ULCAST_(1) << 13)
+
 /*
  * Coprocessor 1 (FPU) register names
  */
 
                                           << MIPS_CONF7_FTLBP_SHIFT));
                break;
        case CPU_LOONGSON3:
+               /* Flush ITLB, DTLB, VTLB and FTLB */
+               write_c0_diag(LOONGSON_DIAG_ITLB | LOONGSON_DIAG_DTLB |
+                             LOONGSON_DIAG_VTLB | LOONGSON_DIAG_FTLB);
                /* Loongson-3 cores use Config6 to enable the FTLB */
                config = read_c0_config6();
                if (enable)
 
 extern void build_tlb_refill_handler(void);
 
 /*
- * LOONGSON2/3 has a 4 entry itlb which is a subset of dtlb,
- * unfortunately, itlb is not totally transparent to software.
+ * LOONGSON-2 has a 4 entry itlb which is a subset of jtlb, LOONGSON-3 has
+ * a 4 entry itlb and a 4 entry dtlb which are subsets of jtlb. Unfortunately,
+ * itlb/dtlb are not totally transparent to software.
  */
-static inline void flush_itlb(void)
+static inline void flush_micro_tlb(void)
 {
        switch (current_cpu_type()) {
        case CPU_LOONGSON2:
+               write_c0_diag(LOONGSON_DIAG_ITLB);
+               break;
        case CPU_LOONGSON3:
-               write_c0_diag(4);
+               write_c0_diag(LOONGSON_DIAG_ITLB | LOONGSON_DIAG_DTLB);
                break;
        default:
                break;
        }
 }
 
-static inline void flush_itlb_vm(struct vm_area_struct *vma)
+static inline void flush_micro_tlb_vm(struct vm_area_struct *vma)
 {
        if (vma->vm_flags & VM_EXEC)
-               flush_itlb();
+               flush_micro_tlb();
 }
 
 void local_flush_tlb_all(void)
        tlbw_use_hazard();
        write_c0_entryhi(old_ctx);
        htw_start();
-       flush_itlb();
+       flush_micro_tlb();
        local_irq_restore(flags);
 }
 EXPORT_SYMBOL(local_flush_tlb_all);
                } else {
                        drop_mmu_context(mm, cpu);
                }
-               flush_itlb();
+               flush_micro_tlb();
                local_irq_restore(flags);
        }
 }
        } else {
                local_flush_tlb_all();
        }
-       flush_itlb();
+       flush_micro_tlb();
        local_irq_restore(flags);
 }
 
        finish:
                write_c0_entryhi(oldpid);
                htw_start();
-               flush_itlb_vm(vma);
+               flush_micro_tlb_vm(vma);
                local_irq_restore(flags);
        }
 }
        }
        write_c0_entryhi(oldpid);
        htw_start();
-       flush_itlb();
+       flush_micro_tlb();
        local_irq_restore(flags);
 }
 
        }
        tlbw_use_hazard();
        htw_start();
-       flush_itlb_vm(vma);
+       flush_micro_tlb_vm(vma);
        local_irq_restore(flags);
 }