blob: 0f988b3e484bfe59d3c1e7b46ef98337bc8a4945 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __ASM_SH_TLB_H
2#define __ASM_SH_TLB_H
3
Paul Mundt959f7d52007-11-10 20:35:53 +09004#ifdef CONFIG_SUPERH64
David Howellsa1ce3922012-10-02 18:01:25 +01005# include <asm/tlb_64.h>
Paul Mundt959f7d52007-11-10 20:35:53 +09006#endif
7
8#ifndef __ASSEMBLY__
Paul Mundtc2035182009-03-17 21:19:49 +09009#include <linux/pagemap.h>
Paul Mundt959f7d52007-11-10 20:35:53 +090010
Paul Mundtc2035182009-03-17 21:19:49 +090011#ifdef CONFIG_MMU
Nobuhiro Iwamatsu194cd8d2011-05-31 13:27:41 +090012#include <linux/swap.h>
Paul Mundtc2035182009-03-17 21:19:49 +090013#include <asm/pgalloc.h>
14#include <asm/tlbflush.h>
Matt Fleming24ef7fc2009-11-19 21:11:05 +000015#include <asm/mmu_context.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17/*
Paul Mundtc2035182009-03-17 21:19:49 +090018 * TLB handling. This allows us to remove pages from the page
19 * tables, and efficiently handle the TLB issues.
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 */
Paul Mundtc2035182009-03-17 21:19:49 +090021struct mmu_gather {
22 struct mm_struct *mm;
23 unsigned int fullmm;
24 unsigned long start, end;
25};
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Paul Mundtc2035182009-03-17 21:19:49 +090027static inline void init_tlb_gather(struct mmu_gather *tlb)
28{
29 tlb->start = TASK_SIZE;
30 tlb->end = 0;
31
32 if (tlb->fullmm) {
33 tlb->start = 0;
34 tlb->end = TASK_SIZE;
35 }
36}
37
Peter Zijlstra1e56a562011-05-24 17:11:54 -070038static inline void
Linus Torvalds2b047252013-08-15 11:42:25 -070039tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned long start, unsigned long end)
Paul Mundtc2035182009-03-17 21:19:49 +090040{
Paul Mundtc2035182009-03-17 21:19:49 +090041 tlb->mm = mm;
Linus Torvalds2b047252013-08-15 11:42:25 -070042 tlb->start = start;
43 tlb->end = end;
44 tlb->fullmm = !(start | (end+1));
Paul Mundtc2035182009-03-17 21:19:49 +090045
46 init_tlb_gather(tlb);
Paul Mundtc2035182009-03-17 21:19:49 +090047}
48
49static inline void
50tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)
51{
52 if (tlb->fullmm)
53 flush_tlb_mm(tlb->mm);
54
55 /* keep the page table cache within bounds */
56 check_pgt_cache();
Paul Mundtc2035182009-03-17 21:19:49 +090057}
58
59static inline void
60tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep, unsigned long address)
61{
62 if (tlb->start > address)
63 tlb->start = address;
64 if (tlb->end < address + PAGE_SIZE)
65 tlb->end = address + PAGE_SIZE;
66}
67
Aneesh Kumar K.Vb528e4b2016-12-12 16:42:37 -080068#define tlb_remove_huge_tlb_entry(h, tlb, ptep, address) \
69 tlb_remove_tlb_entry(tlb, ptep, address)
70
Paul Mundtc2035182009-03-17 21:19:49 +090071/*
72 * In the case of tlb vma handling, we can optimise these away in the
73 * case where we're doing a full MM flush. When we're doing a munmap,
74 * the vmas are adjusted to only cover the region to be torn down.
75 */
76static inline void
77tlb_start_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
78{
79 if (!tlb->fullmm)
80 flush_cache_range(vma, vma->vm_start, vma->vm_end);
81}
82
83static inline void
84tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
85{
86 if (!tlb->fullmm && tlb->end) {
87 flush_tlb_range(vma, tlb->start, tlb->end);
88 init_tlb_gather(tlb);
89 }
90}
91
Linus Torvalds1cf35d42014-04-25 16:05:40 -070092static inline void tlb_flush_mmu_tlbonly(struct mmu_gather *tlb)
93{
94}
95
96static inline void tlb_flush_mmu_free(struct mmu_gather *tlb)
97{
98}
99
Peter Zijlstra1e56a562011-05-24 17:11:54 -0700100static inline void tlb_flush_mmu(struct mmu_gather *tlb)
101{
102}
103
104static inline int __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
105{
106 free_page_and_swap_cache(page);
Aneesh Kumar K.Ve9d55e12016-07-26 15:24:09 -0700107 return false; /* avoid calling tlb_flush_mmu */
Peter Zijlstra1e56a562011-05-24 17:11:54 -0700108}
109
110static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
111{
112 __tlb_remove_page(tlb, page);
113}
114
Aneesh Kumar K.Ve77b0852016-07-26 15:24:12 -0700115static inline bool __tlb_remove_page_size(struct mmu_gather *tlb,
116 struct page *page, int page_size)
117{
118 return __tlb_remove_page(tlb, page);
119}
120
Aneesh Kumar K.Ve9d55e12016-07-26 15:24:09 -0700121static inline bool __tlb_remove_pte_page(struct mmu_gather *tlb,
122 struct page *page)
123{
124 return __tlb_remove_page(tlb, page);
125}
126
Aneesh Kumar K.Ve77b0852016-07-26 15:24:12 -0700127static inline void tlb_remove_page_size(struct mmu_gather *tlb,
128 struct page *page, int page_size)
129{
130 return tlb_remove_page(tlb, page);
131}
132
Aneesh Kumar K.V07e32662016-12-12 16:42:40 -0800133#define tlb_remove_check_page_size_change tlb_remove_check_page_size_change
134static inline void tlb_remove_check_page_size_change(struct mmu_gather *tlb,
135 unsigned int page_size)
136{
137}
138
Benjamin Herrenschmidt9e1b32c2009-07-22 15:44:28 +1000139#define pte_free_tlb(tlb, ptep, addr) pte_free((tlb)->mm, ptep)
140#define pmd_free_tlb(tlb, pmdp, addr) pmd_free((tlb)->mm, pmdp)
141#define pud_free_tlb(tlb, pudp, addr) pud_free((tlb)->mm, pudp)
Paul Mundtc2035182009-03-17 21:19:49 +0900142
143#define tlb_migrate_finish(mm) do { } while (0)
144
Paul Mundtbb29c672010-01-19 15:20:35 +0900145#if defined(CONFIG_CPU_SH4) || defined(CONFIG_SUPERH64)
Matt Fleming8eda5512009-11-17 21:05:31 +0000146extern void tlb_wire_entry(struct vm_area_struct *, unsigned long, pte_t);
147extern void tlb_unwire_entry(void);
148#else
149static inline void tlb_wire_entry(struct vm_area_struct *vma ,
150 unsigned long addr, pte_t pte)
151{
152 BUG();
153}
154
155static inline void tlb_unwire_entry(void)
156{
157 BUG();
158}
Paul Mundtbb29c672010-01-19 15:20:35 +0900159#endif
Matt Fleming8eda5512009-11-17 21:05:31 +0000160
Paul Mundtc2035182009-03-17 21:19:49 +0900161#else /* CONFIG_MMU */
162
163#define tlb_start_vma(tlb, vma) do { } while (0)
164#define tlb_end_vma(tlb, vma) do { } while (0)
165#define __tlb_remove_tlb_entry(tlb, pte, address) do { } while (0)
166#define tlb_flush(tlb) do { } while (0)
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168#include <asm-generic/tlb.h>
Paul Mundt959f7d52007-11-10 20:35:53 +0900169
Paul Mundtc2035182009-03-17 21:19:49 +0900170#endif /* CONFIG_MMU */
Paul Mundt959f7d52007-11-10 20:35:53 +0900171#endif /* __ASSEMBLY__ */
172#endif /* __ASM_SH_TLB_H */