blob: 3417dd71ab4326e120d2f243a69b3a5bdce60f99 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * include/asm-s390/pgalloc.h
3 *
4 * S390 version
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)
8 *
9 * Derived from "include/asm-i386/pgalloc.h"
10 * Copyright (C) 1994 Linus Torvalds
11 */
12
13#ifndef _S390_PGALLOC_H
14#define _S390_PGALLOC_H
15
16#include <linux/config.h>
17#include <linux/threads.h>
18#include <linux/gfp.h>
19#include <linux/mm.h>
20
21#define check_pgt_cache() do {} while (0)
22
23extern void diag10(unsigned long addr);
24
25/*
26 * Allocate and free page tables. The xxx_kernel() versions are
27 * used to allocate a kernel page table - this turns on ASN bits
28 * if any.
29 */
30
31static inline pgd_t *pgd_alloc(struct mm_struct *mm)
32{
33 pgd_t *pgd;
34 int i;
35
36#ifndef __s390x__
37 pgd = (pgd_t *) __get_free_pages(GFP_KERNEL,1);
38 if (pgd != NULL)
39 for (i = 0; i < USER_PTRS_PER_PGD; i++)
40 pmd_clear(pmd_offset(pgd + i, i*PGDIR_SIZE));
41#else /* __s390x__ */
42 pgd = (pgd_t *) __get_free_pages(GFP_KERNEL,2);
43 if (pgd != NULL)
44 for (i = 0; i < PTRS_PER_PGD; i++)
45 pgd_clear(pgd + i);
46#endif /* __s390x__ */
47 return pgd;
48}
49
50static inline void pgd_free(pgd_t *pgd)
51{
52#ifndef __s390x__
53 free_pages((unsigned long) pgd, 1);
54#else /* __s390x__ */
55 free_pages((unsigned long) pgd, 2);
56#endif /* __s390x__ */
57}
58
59#ifndef __s390x__
60/*
61 * page middle directory allocation/free routines.
62 * We use pmd cache only on s390x, so these are dummy routines. This
63 * code never triggers because the pgd will always be present.
64 */
65#define pmd_alloc_one(mm,address) ({ BUG(); ((pmd_t *)2); })
66#define pmd_free(x) do { } while (0)
67#define __pmd_free_tlb(tlb,x) do { } while (0)
68#define pgd_populate(mm, pmd, pte) BUG()
69#else /* __s390x__ */
70static inline pmd_t * pmd_alloc_one(struct mm_struct *mm, unsigned long vmaddr)
71{
72 pmd_t *pmd;
73 int i;
74
75 pmd = (pmd_t *) __get_free_pages(GFP_KERNEL, 2);
76 if (pmd != NULL) {
77 for (i=0; i < PTRS_PER_PMD; i++)
78 pmd_clear(pmd+i);
79 }
80 return pmd;
81}
82
83static inline void pmd_free (pmd_t *pmd)
84{
85 free_pages((unsigned long) pmd, 2);
86}
87
88#define __pmd_free_tlb(tlb,pmd) \
89 do { \
90 tlb_flush_mmu(tlb, 0, 0); \
91 pmd_free(pmd); \
92 } while (0)
93
94static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
95{
96 pgd_val(*pgd) = _PGD_ENTRY | __pa(pmd);
97}
98
99#endif /* __s390x__ */
100
101static inline void
102pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
103{
104#ifndef __s390x__
105 pmd_val(pmd[0]) = _PAGE_TABLE + __pa(pte);
106 pmd_val(pmd[1]) = _PAGE_TABLE + __pa(pte+256);
107 pmd_val(pmd[2]) = _PAGE_TABLE + __pa(pte+512);
108 pmd_val(pmd[3]) = _PAGE_TABLE + __pa(pte+768);
109#else /* __s390x__ */
110 pmd_val(*pmd) = _PMD_ENTRY + __pa(pte);
111 pmd_val1(*pmd) = _PMD_ENTRY + __pa(pte+256);
112#endif /* __s390x__ */
113}
114
115static inline void
116pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *page)
117{
118 pmd_populate_kernel(mm, pmd, (pte_t *)((page-mem_map) << PAGE_SHIFT));
119}
120
121/*
122 * page table entry allocation/free routines.
123 */
124static inline pte_t *
125pte_alloc_one_kernel(struct mm_struct *mm, unsigned long vmaddr)
126{
127 pte_t *pte;
128 int i;
129
130 pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
131 if (pte != NULL) {
132 for (i=0; i < PTRS_PER_PTE; i++) {
133 pte_clear(mm, vmaddr, pte+i);
134 vmaddr += PAGE_SIZE;
135 }
136 }
137 return pte;
138}
139
140static inline struct page *
141pte_alloc_one(struct mm_struct *mm, unsigned long vmaddr)
142{
143 pte_t *pte = pte_alloc_one_kernel(mm, vmaddr);
144 if (pte)
145 return virt_to_page(pte);
146 return 0;
147}
148
149static inline void pte_free_kernel(pte_t *pte)
150{
151 free_page((unsigned long) pte);
152}
153
154static inline void pte_free(struct page *pte)
155{
156 __free_page(pte);
157}
158
159#define __pte_free_tlb(tlb,pte) tlb_remove_page(tlb,pte)
160
161/*
162 * This establishes kernel virtual mappings (e.g., as a result of a
163 * vmalloc call). Since s390-esame uses a separate kernel page table,
164 * there is nothing to do here... :)
165 */
166#define set_pgdir(addr,entry) do { } while(0)
167
168#endif /* _S390_PGALLOC_H */