2 * include/asm-s390/bugs.h
5 * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Hartmut Penner (hp@de.ibm.com)
7 * Martin Schwidefsky (schwidefsky@de.ibm.com)
9 * Derived from "include/asm-i386/pgalloc.h"
10 * Copyright (C) 1994 Linus Torvalds
13 #ifndef _S390_PGALLOC_H
14 #define _S390_PGALLOC_H
16 #include <linux/config.h>
17 #include <asm/processor.h>
18 #include <linux/threads.h>
20 #define pgd_quicklist (S390_lowcore.cpu_data.pgd_quick)
21 #define pmd_quicklist ((unsigned long *)0)
22 #define pte_quicklist (S390_lowcore.cpu_data.pte_quick)
23 #define pgtable_cache_size (S390_lowcore.cpu_data.pgtable_cache_sz)
26 * Allocate and free page tables. The xxx_kernel() versions are
27 * used to allocate a kernel page table - this turns on ASN bits
31 extern __inline__ pgd_t* get_pgd_slow(void)
36 ret = (pgd_t *) __get_free_pages(GFP_KERNEL,1);
38 for (i = 0; i < USER_PTRS_PER_PGD; i++)
39 pmd_clear(pmd_offset(ret + i, i*PGDIR_SIZE));
43 extern __inline__ pgd_t* get_pgd_fast(void)
45 unsigned long *ret = pgd_quicklist;
48 pgd_quicklist = (unsigned long *)(*ret);
50 pgtable_cache_size -= 2;
55 extern __inline__ pgd_t *pgd_alloc(struct mm_struct *mm)
65 extern __inline__ void free_pgd_fast(pgd_t *pgd)
67 *(unsigned long *)pgd = (unsigned long) pgd_quicklist;
68 pgd_quicklist = (unsigned long *) pgd;
69 pgtable_cache_size += 2;
72 extern __inline__ void free_pgd_slow(pgd_t *pgd)
74 free_pages((unsigned long) pgd, 1);
77 #define pgd_free(pgd) free_pgd_fast(pgd)
80 * page middle directory allocation/free routines.
81 * We don't use pmd cache, so these are dummy routines. This
82 * code never triggers because the pgd will always be present.
84 #define pmd_alloc_one_fast(mm, address) ({ BUG(); ((pmd_t *)1); })
85 #define pmd_alloc_one(mm,address) ({ BUG(); ((pmd_t *)2); })
86 #define pmd_free(x) do { } while (0)
87 #define pmd_free_slow(x) do { } while (0)
88 #define pmd_free_fast(x) do { } while (0)
89 #define pgd_populate(mm, pmd, pte) BUG()
91 extern inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
93 pmd_val(pmd[0]) = _PAGE_TABLE + __pa(pte);
94 pmd_val(pmd[1]) = _PAGE_TABLE + __pa(pte+256);
95 pmd_val(pmd[2]) = _PAGE_TABLE + __pa(pte+512);
96 pmd_val(pmd[3]) = _PAGE_TABLE + __pa(pte+768);
100 * page table entry allocation/free routines.
102 extern inline pte_t * pte_alloc_one(struct mm_struct *mm, unsigned long vmaddr)
107 pte = (pte_t *) __get_free_page(GFP_KERNEL);
109 for (i=0; i < PTRS_PER_PTE; i++)
115 extern __inline__ pte_t *
116 pte_alloc_one_fast(struct mm_struct *mm, unsigned long address)
118 unsigned long *ret = (unsigned long *) pte_quicklist;
121 pte_quicklist = (unsigned long *)(*ret);
123 pgtable_cache_size--;
128 extern __inline__ void pte_free_fast(pte_t *pte)
130 *(unsigned long *)pte = (unsigned long) pte_quicklist;
131 pte_quicklist = (unsigned long *) pte;
132 pgtable_cache_size++;
135 extern __inline__ void pte_free_slow(pte_t *pte)
137 free_page((unsigned long) pte);
140 #define pte_free(pte) pte_free_fast(pte)
142 extern int do_check_pgt_cache(int, int);
145 * This establishes kernel virtual mappings (e.g., as a result of a
146 * vmalloc call). Since s390-esame uses a separate kernel page table,
147 * there is nothing to do here... :)
149 #define set_pgdir(addr,entry) do { } while(0)
154 * - flush_tlb() flushes the current mm struct TLBs
155 * - flush_tlb_all() flushes all processes TLBs
156 * called only from vmalloc/vfree
157 * - flush_tlb_mm(mm) flushes the specified mm context TLB's
158 * - flush_tlb_page(vma, vmaddr) flushes one page
159 * - flush_tlb_range(mm, start, end) flushes a range of pages
160 * - flush_tlb_pgtables(mm, start, end) flushes a range of page tables
164 * S/390 has three ways of flushing TLBs
165 * 'ptlb' does a flush of the local processor
166 * 'csp' flushes the TLBs on all PUs of a SMP
167 * 'ipte' invalidates a pte in a page table and flushes that out of
168 * the TLBs of all PUs of a SMP
171 #define local_flush_tlb() \
172 do { __asm__ __volatile__("ptlb": : :"memory"); } while (0)
178 * We always need to flush, since s390 does not flush tlb
179 * on each context switch
182 static inline void flush_tlb(void)
186 static inline void flush_tlb_all(void)
190 static inline void flush_tlb_mm(struct mm_struct *mm)
194 static inline void flush_tlb_page(struct vm_area_struct *vma,
199 static inline void flush_tlb_range(struct mm_struct *mm,
200 unsigned long start, unsigned long end)
209 extern void smp_ptlb_all(void);
210 static inline void global_flush_tlb_csp(void)
215 adr = (int*) (((int)(((int*) &dummy)+1) & 0xfffffffc)|1);
216 __asm__ __volatile__("lr 2,%0\n\t"
220 : "d" (cs1), "d" (dum), "d" (adr)
223 static inline void global_flush_tlb(void)
226 global_flush_tlb_csp();
232 * We only have to do global flush of tlb if process run since last
233 * flush on any other pu than current.
234 * If we have threads (mm->count > 1) we always do a global flush,
235 * since the process runs on more than one processor at the same time.
238 static inline void __flush_tlb_mm(struct mm_struct * mm)
240 if ((smp_num_cpus > 1) &&
241 ((atomic_read(&mm->mm_count) != 1) ||
242 (mm->cpu_vm_mask != (1UL << smp_processor_id())))) {
243 mm->cpu_vm_mask = (1UL << smp_processor_id());
250 static inline void flush_tlb(void)
252 __flush_tlb_mm(current->mm);
254 static inline void flush_tlb_all(void)
258 static inline void flush_tlb_mm(struct mm_struct *mm)
262 static inline void flush_tlb_page(struct vm_area_struct *vma,
265 __flush_tlb_mm(vma->vm_mm);
267 static inline void flush_tlb_range(struct mm_struct *mm,
268 unsigned long start, unsigned long end)
275 extern inline void flush_tlb_pgtables(struct mm_struct *mm,
276 unsigned long start, unsigned long end)
278 /* S/390 does not keep any page table caches in TLB */
282 static inline int ptep_test_and_clear_and_flush_young(struct vm_area_struct *vma,
283 unsigned long address, pte_t *ptep)
285 /* No need to flush TLB; bits are in storage key */
286 return ptep_test_and_clear_young(ptep);
289 static inline int ptep_test_and_clear_and_flush_dirty(struct vm_area_struct *vma,
290 unsigned long address, pte_t *ptep)
292 /* No need to flush TLB; bits are in storage key */
293 return ptep_test_and_clear_dirty(ptep);
296 static inline pte_t ptep_invalidate(struct vm_area_struct *vma,
297 unsigned long address, pte_t *ptep)
300 if (!(pte_val(pte) & _PAGE_INVALID)) {
301 /* S390 has 1mb segments, we are emulating 4MB segments */
302 pte_t *pto = (pte_t *) (((unsigned long) ptep) & 0x7ffffc00);
303 __asm__ __volatile__ ("ipte %0,%1" : : "a" (pto), "a" (address));
309 static inline void ptep_establish(struct vm_area_struct *vma,
310 unsigned long address, pte_t *ptep, pte_t entry)
312 ptep_invalidate(vma, address, ptep);
313 set_pte(ptep, entry);
316 #endif /* _S390_PGALLOC_H */