2 * include/asm-s390/pgalloc.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>
19 #include <linux/gfp.h>
22 #define check_pgt_cache() do {} while (0)
25 * Allocate and free page tables. The xxx_kernel() versions are
26 * used to allocate a kernel page table - this turns on ASN bits
30 static inline pgd_t
*pgd_alloc(struct mm_struct
*mm
)
36 pgd
= (pgd_t
*) __get_free_pages(GFP_KERNEL
,1);
38 for (i
= 0; i
< USER_PTRS_PER_PGD
; i
++)
39 pmd_clear(pmd_offset(pgd
+ i
, i
*PGDIR_SIZE
));
41 pgd
= (pgd_t
*) __get_free_pages(GFP_KERNEL
,2);
43 for (i
= 0; i
< PTRS_PER_PGD
; i
++)
45 #endif /* __s390x__ */
49 static inline void pgd_free(pgd_t
*pgd
)
52 free_pages((unsigned long) pgd
, 1);
54 free_pages((unsigned long) pgd
, 2);
55 #endif /* __s390x__ */
60 * page middle directory allocation/free routines.
61 * We use pmd cache only on s390x, so these are dummy routines. This
62 * code never triggers because the pgd will always be present.
64 #define pmd_alloc_one(mm,address) ({ BUG(); ((pmd_t *)2); })
65 #define pmd_free(x) do { } while (0)
66 #define __pmd_free_tlb(tlb,x) do { } while (0)
67 #define pgd_populate(mm, pmd, pte) BUG()
69 static inline pmd_t
* pmd_alloc_one(struct mm_struct
*mm
, unsigned long vmaddr
)
74 pmd
= (pmd_t
*) __get_free_pages(GFP_KERNEL
, 2);
76 for (i
=0; i
< PTRS_PER_PMD
; i
++)
82 static inline void pmd_free (pmd_t
*pmd
)
84 free_pages((unsigned long) pmd
, 2);
87 #define __pmd_free_tlb(tlb,pmd) pmd_free(pmd)
89 static inline void pgd_populate(struct mm_struct
*mm
, pgd_t
*pgd
, pmd_t
*pmd
)
91 pgd_val(*pgd
) = _PGD_ENTRY
| __pa(pmd
);
94 #endif /* __s390x__ */
97 pmd_populate_kernel(struct mm_struct
*mm
, pmd_t
*pmd
, pte_t
*pte
)
100 pmd_val(pmd
[0]) = _PAGE_TABLE
+ __pa(pte
);
101 pmd_val(pmd
[1]) = _PAGE_TABLE
+ __pa(pte
+256);
102 pmd_val(pmd
[2]) = _PAGE_TABLE
+ __pa(pte
+512);
103 pmd_val(pmd
[3]) = _PAGE_TABLE
+ __pa(pte
+768);
104 #else /* __s390x__ */
105 pmd_val(*pmd
) = _PMD_ENTRY
+ __pa(pte
);
106 pmd_val1(*pmd
) = _PMD_ENTRY
+ __pa(pte
+256);
107 #endif /* __s390x__ */
111 pmd_populate(struct mm_struct
*mm
, pmd_t
*pmd
, struct page
*page
)
113 pmd_populate_kernel(mm
, pmd
, (pte_t
*)((page
-mem_map
) << PAGE_SHIFT
));
117 * page table entry allocation/free routines.
119 static inline pte_t
*
120 pte_alloc_one_kernel(struct mm_struct
*mm
, unsigned long vmaddr
)
125 pte
= (pte_t
*)__get_free_page(GFP_KERNEL
|__GFP_REPEAT
);
127 for (i
=0; i
< PTRS_PER_PTE
; i
++)
133 static inline struct page
*
134 pte_alloc_one(struct mm_struct
*mm
, unsigned long vmaddr
)
136 return virt_to_page(pte_alloc_one_kernel(mm
, vmaddr
));
139 static inline void pte_free_kernel(pte_t
*pte
)
141 free_page((unsigned long) pte
);
144 static inline void pte_free(struct page
*pte
)
149 #define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
152 * This establishes kernel virtual mappings (e.g., as a result of a
153 * vmalloc call). Since s390-esame uses a separate kernel page table,
154 * there is nothing to do here... :)
156 #define set_pgdir(addr,entry) do { } while(0)
158 static inline pte_t
ptep_invalidate(struct vm_area_struct
*vma
,
159 unsigned long address
, pte_t
*ptep
)
163 if (!(pte_val(pte
) & _PAGE_INVALID
)) {
164 /* S390 has 1mb segments, we are emulating 4MB segments */
165 pte_t
*pto
= (pte_t
*) (((unsigned long) ptep
) & 0x7ffffc00);
166 __asm__
__volatile__ ("ipte %0,%1" : : "a" (pto
), "a" (address
));
168 #else /* __s390x__ */
169 if (!(pte_val(pte
) & _PAGE_INVALID
))
170 __asm__
__volatile__ ("ipte %0,%1" : : "a" (ptep
), "a" (address
));
171 #endif /* __s390x__ */
176 static inline void ptep_establish(struct vm_area_struct
*vma
,
177 unsigned long address
, pte_t
*ptep
, pte_t entry
)
179 ptep_invalidate(vma
, address
, ptep
);
180 set_pte(ptep
, entry
);
183 #endif /* _S390_PGALLOC_H */