gpio/basic_mmio: add missing include of spinlock_types.h
[pandora-kernel.git] / arch / s390 / include / asm / tlb.h
1 #ifndef _S390_TLB_H
2 #define _S390_TLB_H
3
4 /*
5  * TLB flushing on s390 is complicated. The following requirement
6  * from the principles of operation is the most arduous:
7  *
8  * "A valid table entry must not be changed while it is attached
9  * to any CPU and may be used for translation by that CPU except to
10  * (1) invalidate the entry by using INVALIDATE PAGE TABLE ENTRY,
11  * or INVALIDATE DAT TABLE ENTRY, (2) alter bits 56-63 of a page
12  * table entry, or (3) make a change by means of a COMPARE AND SWAP
13  * AND PURGE instruction that purges the TLB."
14  *
15  * The modification of a pte of an active mm struct therefore is
16  * a two step process: i) invalidate the pte, ii) store the new pte.
17  * This is true for the page protection bit as well.
18  * The only possible optimization is to flush at the beginning of
19  * a tlb_gather_mmu cycle if the mm_struct is currently not in use.
20  *
21  * Pages used for the page tables is a different story. FIXME: more
22  */
23
24 #include <linux/mm.h>
25 #include <linux/pagemap.h>
26 #include <linux/swap.h>
27 #include <asm/processor.h>
28 #include <asm/pgalloc.h>
29 #include <asm/smp.h>
30 #include <asm/tlbflush.h>
31
32 struct mmu_gather {
33         struct mm_struct *mm;
34         unsigned int fullmm;
35         unsigned int nr_ptes;
36         unsigned int nr_pxds;
37         unsigned int max;
38         void **array;
39         void *local[8];
40 };
41
42 static inline void __tlb_alloc_page(struct mmu_gather *tlb)
43 {
44         unsigned long addr = __get_free_pages(GFP_NOWAIT | __GFP_NOWARN, 0);
45
46         if (addr) {
47                 tlb->array = (void *) addr;
48                 tlb->max = PAGE_SIZE / sizeof(void *);
49         }
50 }
51
52 static inline void tlb_gather_mmu(struct mmu_gather *tlb,
53                                   struct mm_struct *mm,
54                                   unsigned int full_mm_flush)
55 {
56         tlb->mm = mm;
57         tlb->max = ARRAY_SIZE(tlb->local);
58         tlb->array = tlb->local;
59         tlb->fullmm = full_mm_flush;
60         if (tlb->fullmm)
61                 __tlb_flush_mm(mm);
62         else
63                 __tlb_alloc_page(tlb);
64         tlb->nr_ptes = 0;
65         tlb->nr_pxds = tlb->max;
66 }
67
68 static inline void tlb_flush_mmu(struct mmu_gather *tlb)
69 {
70         if (!tlb->fullmm && (tlb->nr_ptes > 0 || tlb->nr_pxds < tlb->max))
71                 __tlb_flush_mm(tlb->mm);
72         while (tlb->nr_ptes > 0)
73                 page_table_free_rcu(tlb->mm, tlb->array[--tlb->nr_ptes]);
74         while (tlb->nr_pxds < tlb->max)
75                 crst_table_free_rcu(tlb->mm, tlb->array[tlb->nr_pxds++]);
76 }
77
78 static inline void tlb_finish_mmu(struct mmu_gather *tlb,
79                                   unsigned long start, unsigned long end)
80 {
81         tlb_flush_mmu(tlb);
82
83         rcu_table_freelist_finish();
84
85         /* keep the page table cache within bounds */
86         check_pgt_cache();
87
88         if (tlb->array != tlb->local)
89                 free_pages((unsigned long) tlb->array, 0);
90 }
91
92 /*
93  * Release the page cache reference for a pte removed by
94  * tlb_ptep_clear_flush. In both flush modes the tlb for a page cache page
95  * has already been freed, so just do free_page_and_swap_cache.
96  */
97 static inline int __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
98 {
99         free_page_and_swap_cache(page);
100         return 1; /* avoid calling tlb_flush_mmu */
101 }
102
103 static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
104 {
105         free_page_and_swap_cache(page);
106 }
107
108 /*
109  * pte_free_tlb frees a pte table and clears the CRSTE for the
110  * page table from the tlb.
111  */
112 static inline void pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
113                                 unsigned long address)
114 {
115         if (!tlb->fullmm) {
116                 tlb->array[tlb->nr_ptes++] = pte;
117                 if (tlb->nr_ptes >= tlb->nr_pxds)
118                         tlb_flush_mmu(tlb);
119         } else
120                 page_table_free(tlb->mm, (unsigned long *) pte);
121 }
122
123 /*
124  * pmd_free_tlb frees a pmd table and clears the CRSTE for the
125  * segment table entry from the tlb.
126  * If the mm uses a two level page table the single pmd is freed
127  * as the pgd. pmd_free_tlb checks the asce_limit against 2GB
128  * to avoid the double free of the pmd in this case.
129  */
130 static inline void pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
131                                 unsigned long address)
132 {
133 #ifdef __s390x__
134         if (tlb->mm->context.asce_limit <= (1UL << 31))
135                 return;
136         if (!tlb->fullmm) {
137                 tlb->array[--tlb->nr_pxds] = pmd;
138                 if (tlb->nr_ptes >= tlb->nr_pxds)
139                         tlb_flush_mmu(tlb);
140         } else
141                 crst_table_free(tlb->mm, (unsigned long *) pmd);
142 #endif
143 }
144
145 /*
146  * pud_free_tlb frees a pud table and clears the CRSTE for the
147  * region third table entry from the tlb.
148  * If the mm uses a three level page table the single pud is freed
149  * as the pgd. pud_free_tlb checks the asce_limit against 4TB
150  * to avoid the double free of the pud in this case.
151  */
152 static inline void pud_free_tlb(struct mmu_gather *tlb, pud_t *pud,
153                                 unsigned long address)
154 {
155 #ifdef __s390x__
156         if (tlb->mm->context.asce_limit <= (1UL << 42))
157                 return;
158         if (!tlb->fullmm) {
159                 tlb->array[--tlb->nr_pxds] = pud;
160                 if (tlb->nr_ptes >= tlb->nr_pxds)
161                         tlb_flush_mmu(tlb);
162         } else
163                 crst_table_free(tlb->mm, (unsigned long *) pud);
164 #endif
165 }
166
167 #define tlb_start_vma(tlb, vma)                 do { } while (0)
168 #define tlb_end_vma(tlb, vma)                   do { } while (0)
169 #define tlb_remove_tlb_entry(tlb, ptep, addr)   do { } while (0)
170 #define tlb_migrate_finish(mm)                  do { } while (0)
171
172 #endif /* _S390_TLB_H */