1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * linux/arch/unicore32/include/asm/tlbflush.h
5 * Code specific to PKUnity SoC and UniCore ISA
7 * Copyright (C) 2001-2010 GUAN Xue-tao
9 #ifndef __UNICORE_TLBFLUSH_H__
10 #define __UNICORE_TLBFLUSH_H__
14 #include <linux/sched.h>
16 extern void __cpu_flush_user_tlb_range(unsigned long, unsigned long,
17 struct vm_area_struct
*);
18 extern void __cpu_flush_kern_tlb_range(unsigned long, unsigned long);
24 * The arch/unicore/mm/tlb-*.S files implement these methods.
26 * The TLB specific code is expected to perform whatever tests it
27 * needs to determine if it should invalidate the TLB for each
28 * call. Start addresses are inclusive and end addresses are
29 * exclusive; it is safe to round these addresses down.
33 * Invalidate the entire TLB.
37 * Invalidate all TLB entries in a particular address
39 * - mm - mm_struct describing address space
41 * flush_tlb_range(mm,start,end)
43 * Invalidate a range of TLB entries in the specified
45 * - mm - mm_struct describing address space
46 * - start - start address (may not be aligned)
47 * - end - end address (exclusive, may not be aligned)
49 * flush_tlb_page(vaddr,vma)
51 * Invalidate the specified page in the specified address range.
52 * - vaddr - virtual address (may not be aligned)
53 * - vma - vma_struct describing address range
55 * flush_kern_tlb_page(kaddr)
57 * Invalidate the TLB entry for the specified page. The address
58 * will be in the kernels virtual memory space. Current uses
59 * only require the D-TLB to be invalidated.
60 * - kaddr - Kernel virtual memory address
63 static inline void local_flush_tlb_all(void)
67 /* TLB invalidate all */
68 asm("movc p0.c6, %0, #6; nop; nop; nop; nop; nop; nop; nop; nop"
69 : : "r" (zero
) : "cc");
72 static inline void local_flush_tlb_mm(struct mm_struct
*mm
)
76 if (cpumask_test_cpu(get_cpu(), mm_cpumask(mm
))) {
77 /* TLB invalidate all */
78 asm("movc p0.c6, %0, #6; nop; nop; nop; nop; nop; nop; nop; nop"
79 : : "r" (zero
) : "cc");
85 local_flush_tlb_page(struct vm_area_struct
*vma
, unsigned long uaddr
)
87 if (cpumask_test_cpu(smp_processor_id(), mm_cpumask(vma
->vm_mm
))) {
88 #ifndef CONFIG_CPU_TLB_SINGLE_ENTRY_DISABLE
89 /* iTLB invalidate page */
90 asm("movc p0.c6, %0, #5; nop; nop; nop; nop; nop; nop; nop; nop"
91 : : "r" (uaddr
& PAGE_MASK
) : "cc");
92 /* dTLB invalidate page */
93 asm("movc p0.c6, %0, #3; nop; nop; nop; nop; nop; nop; nop; nop"
94 : : "r" (uaddr
& PAGE_MASK
) : "cc");
96 /* TLB invalidate all */
97 asm("movc p0.c6, %0, #6; nop; nop; nop; nop; nop; nop; nop; nop"
98 : : "r" (uaddr
& PAGE_MASK
) : "cc");
103 static inline void local_flush_tlb_kernel_page(unsigned long kaddr
)
105 #ifndef CONFIG_CPU_TLB_SINGLE_ENTRY_DISABLE
106 /* iTLB invalidate page */
107 asm("movc p0.c6, %0, #5; nop; nop; nop; nop; nop; nop; nop; nop"
108 : : "r" (kaddr
& PAGE_MASK
) : "cc");
109 /* dTLB invalidate page */
110 asm("movc p0.c6, %0, #3; nop; nop; nop; nop; nop; nop; nop; nop"
111 : : "r" (kaddr
& PAGE_MASK
) : "cc");
113 /* TLB invalidate all */
114 asm("movc p0.c6, %0, #6; nop; nop; nop; nop; nop; nop; nop; nop"
115 : : "r" (kaddr
& PAGE_MASK
) : "cc");
122 * Flush a PMD entry (word aligned, or double-word aligned) to
123 * RAM if the TLB for the CPU we are running on requires this.
124 * This is typically used when we are creating PMD entries.
128 * Clean (but don't drain the write buffer) if the CPU requires
129 * these operations. This is typically used when we are removing
132 static inline void flush_pmd_entry(pmd_t
*pmd
)
134 #ifndef CONFIG_CPU_DCACHE_LINE_DISABLE
135 /* flush dcache line, see dcacheline_flush in proc-macros.S */
136 asm("mov r1, %0 << #20\n"
138 "add r2, r2, r1 >> #20\n"
139 "ldw r1, [r2+], #0x0000\n"
140 "ldw r1, [r2+], #0x1000\n"
141 "ldw r1, [r2+], #0x2000\n"
142 "ldw r1, [r2+], #0x3000\n"
143 : : "r" (pmd
) : "r1", "r2");
145 /* flush dcache all */
146 asm("movc p0.c5, %0, #14; nop; nop; nop; nop; nop; nop; nop; nop"
147 : : "r" (pmd
) : "cc");
151 static inline void clean_pmd_entry(pmd_t
*pmd
)
153 #ifndef CONFIG_CPU_DCACHE_LINE_DISABLE
154 /* clean dcache line */
155 asm("movc p0.c5, %0, #11; nop; nop; nop; nop; nop; nop; nop; nop"
156 : : "r" (__pa(pmd
) & ~(L1_CACHE_BYTES
- 1)) : "cc");
158 /* clean dcache all */
159 asm("movc p0.c5, %0, #10; nop; nop; nop; nop; nop; nop; nop; nop"
160 : : "r" (pmd
) : "cc");
165 * Convert calls to our calling convention.
167 #define local_flush_tlb_range(vma, start, end) \
168 __cpu_flush_user_tlb_range(start, end, vma)
169 #define local_flush_tlb_kernel_range(s, e) \
170 __cpu_flush_kern_tlb_range(s, e)
172 #define flush_tlb_all local_flush_tlb_all
173 #define flush_tlb_mm local_flush_tlb_mm
174 #define flush_tlb_page local_flush_tlb_page
175 #define flush_tlb_kernel_page local_flush_tlb_kernel_page
176 #define flush_tlb_range local_flush_tlb_range
177 #define flush_tlb_kernel_range local_flush_tlb_kernel_range
180 * if PG_dcache_clean is not set for the page, we need to ensure that any
181 * cache entries for the kernels virtual memory range are written
184 extern void update_mmu_cache(struct vm_area_struct
*vma
,
185 unsigned long addr
, pte_t
*ptep
);
187 extern void do_bad_area(unsigned long addr
, unsigned int fsr
,
188 struct pt_regs
*regs
);