1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
4 #include <linux/init.h>
6 #include <linux/module.h>
7 #include <linux/sched.h>
9 #include <asm/mmu_context.h>
10 #include <asm/setup.h>
13 * One C-SKY MMU TLB entry contain two PFN/page entry, ie:
16 #define TLB_ENTRY_SIZE (PAGE_SIZE * 2)
17 #define TLB_ENTRY_SIZE_MASK (PAGE_MASK << 1)
19 void flush_tlb_all(void)
24 void flush_tlb_mm(struct mm_struct
*mm
)
26 #ifdef CONFIG_CPU_HAS_TLBI
27 asm volatile("tlbi.asids %0"::"r"(cpu_asid(mm
)));
34 * MMU operation regs only could invalid tlb entry in jtlb and we
35 * need change asid field to invalid I-utlb & D-utlb.
37 #ifndef CONFIG_CPU_HAS_TLBI
38 #define restore_asid_inv_utlb(oldpid, newpid) \
40 if (oldpid == newpid) \
41 write_mmu_entryhi(oldpid + 1); \
42 write_mmu_entryhi(oldpid); \
46 void flush_tlb_range(struct vm_area_struct
*vma
, unsigned long start
,
49 unsigned long newpid
= cpu_asid(vma
->vm_mm
);
51 start
&= TLB_ENTRY_SIZE_MASK
;
52 end
+= TLB_ENTRY_SIZE
- 1;
53 end
&= TLB_ENTRY_SIZE_MASK
;
55 #ifdef CONFIG_CPU_HAS_TLBI
57 asm volatile("tlbi.vas %0"::"r"(start
| newpid
));
63 unsigned long flags
, oldpid
;
65 local_irq_save(flags
);
66 oldpid
= read_mmu_entryhi() & ASID_MASK
;
70 write_mmu_entryhi(start
| newpid
);
73 idx
= read_mmu_index();
75 tlb_invalid_indexed();
77 restore_asid_inv_utlb(oldpid
, newpid
);
78 local_irq_restore(flags
);
83 void flush_tlb_kernel_range(unsigned long start
, unsigned long end
)
85 start
&= TLB_ENTRY_SIZE_MASK
;
86 end
+= TLB_ENTRY_SIZE
- 1;
87 end
&= TLB_ENTRY_SIZE_MASK
;
89 #ifdef CONFIG_CPU_HAS_TLBI
91 asm volatile("tlbi.vaas %0"::"r"(start
));
97 unsigned long flags
, oldpid
;
99 local_irq_save(flags
);
100 oldpid
= read_mmu_entryhi() & ASID_MASK
;
101 while (start
< end
) {
104 write_mmu_entryhi(start
| oldpid
);
105 start
+= 2*PAGE_SIZE
;
107 idx
= read_mmu_index();
109 tlb_invalid_indexed();
111 restore_asid_inv_utlb(oldpid
, oldpid
);
112 local_irq_restore(flags
);
117 void flush_tlb_page(struct vm_area_struct
*vma
, unsigned long addr
)
119 int newpid
= cpu_asid(vma
->vm_mm
);
121 addr
&= TLB_ENTRY_SIZE_MASK
;
123 #ifdef CONFIG_CPU_HAS_TLBI
124 asm volatile("tlbi.vas %0"::"r"(addr
| newpid
));
131 local_irq_save(flags
);
132 oldpid
= read_mmu_entryhi() & ASID_MASK
;
133 write_mmu_entryhi(addr
| newpid
);
135 idx
= read_mmu_index();
137 tlb_invalid_indexed();
139 restore_asid_inv_utlb(oldpid
, newpid
);
140 local_irq_restore(flags
);
145 void flush_tlb_one(unsigned long addr
)
147 addr
&= TLB_ENTRY_SIZE_MASK
;
149 #ifdef CONFIG_CPU_HAS_TLBI
150 asm volatile("tlbi.vaas %0"::"r"(addr
));
157 local_irq_save(flags
);
158 oldpid
= read_mmu_entryhi() & ASID_MASK
;
159 write_mmu_entryhi(addr
| oldpid
);
161 idx
= read_mmu_index();
163 tlb_invalid_indexed();
165 restore_asid_inv_utlb(oldpid
, oldpid
);
166 local_irq_restore(flags
);
170 EXPORT_SYMBOL(flush_tlb_one
);