1 #ifndef _ASM_POWERPC_PGALLOC_64_H
2 #define _ASM_POWERPC_PGALLOC_64_H
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
10 #include <linux/slab.h>
11 #include <linux/cpumask.h>
12 #include <linux/percpu.h>
14 #ifndef CONFIG_PPC_SUBPAGE_PROT
15 static inline void subpage_prot_free(pgd_t
*pgd
) {}
18 extern struct kmem_cache
*pgtable_cache
[];
20 #define PGD_CACHE_NUM 0
21 #define PUD_CACHE_NUM 1
22 #define PMD_CACHE_NUM 1
23 #define HUGEPTE_CACHE_NUM 2
24 #define PTE_NONCACHE_NUM 7 /* from GFP rather than kmem_cache */
26 static inline pgd_t
*pgd_alloc(struct mm_struct
*mm
)
28 return kmem_cache_alloc(pgtable_cache
[PGD_CACHE_NUM
], GFP_KERNEL
);
31 static inline void pgd_free(struct mm_struct
*mm
, pgd_t
*pgd
)
33 subpage_prot_free(pgd
);
34 kmem_cache_free(pgtable_cache
[PGD_CACHE_NUM
], pgd
);
37 #ifndef CONFIG_PPC_64K_PAGES
39 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
41 static inline pud_t
*pud_alloc_one(struct mm_struct
*mm
, unsigned long addr
)
43 return kmem_cache_alloc(pgtable_cache
[PUD_CACHE_NUM
],
44 GFP_KERNEL
|__GFP_REPEAT
);
47 static inline void pud_free(struct mm_struct
*mm
, pud_t
*pud
)
49 kmem_cache_free(pgtable_cache
[PUD_CACHE_NUM
], pud
);
52 static inline void pud_populate(struct mm_struct
*mm
, pud_t
*pud
, pmd_t
*pmd
)
54 pud_set(pud
, (unsigned long)pmd
);
57 #define pmd_populate(mm, pmd, pte_page) \
58 pmd_populate_kernel(mm, pmd, page_address(pte_page))
59 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
60 #define pmd_pgtable(pmd) pmd_page(pmd)
63 #else /* CONFIG_PPC_64K_PAGES */
65 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
67 static inline void pmd_populate_kernel(struct mm_struct
*mm
, pmd_t
*pmd
,
70 pmd_set(pmd
, (unsigned long)pte
);
73 #define pmd_populate(mm, pmd, pte_page) \
74 pmd_populate_kernel(mm, pmd, page_address(pte_page))
75 #define pmd_pgtable(pmd) pmd_page(pmd)
77 #endif /* CONFIG_PPC_64K_PAGES */
79 static inline pmd_t
*pmd_alloc_one(struct mm_struct
*mm
, unsigned long addr
)
81 return kmem_cache_alloc(pgtable_cache
[PMD_CACHE_NUM
],
82 GFP_KERNEL
|__GFP_REPEAT
);
85 static inline void pmd_free(struct mm_struct
*mm
, pmd_t
*pmd
)
87 kmem_cache_free(pgtable_cache
[PMD_CACHE_NUM
], pmd
);
90 static inline pte_t
*pte_alloc_one_kernel(struct mm_struct
*mm
,
91 unsigned long address
)
93 return (pte_t
*)__get_free_page(GFP_KERNEL
| __GFP_REPEAT
| __GFP_ZERO
);
96 static inline pgtable_t
pte_alloc_one(struct mm_struct
*mm
,
97 unsigned long address
)
102 pte
= pte_alloc_one_kernel(mm
, address
);
105 page
= virt_to_page(pte
);
106 pgtable_page_ctor(page
);
110 static inline void pgtable_free(pgtable_free_t pgf
)
112 void *p
= (void *)(pgf
.val
& ~PGF_CACHENUM_MASK
);
113 int cachenum
= pgf
.val
& PGF_CACHENUM_MASK
;
115 if (cachenum
== PTE_NONCACHE_NUM
)
116 free_page((unsigned long)p
);
118 kmem_cache_free(pgtable_cache
[cachenum
], p
);
121 #define __pmd_free_tlb(tlb, pmd) \
122 pgtable_free_tlb(tlb, pgtable_free_cache(pmd, \
123 PMD_CACHE_NUM, PMD_TABLE_SIZE-1))
124 #ifndef CONFIG_PPC_64K_PAGES
125 #define __pud_free_tlb(tlb, pud) \
126 pgtable_free_tlb(tlb, pgtable_free_cache(pud, \
127 PUD_CACHE_NUM, PUD_TABLE_SIZE-1))
128 #endif /* CONFIG_PPC_64K_PAGES */
130 #define check_pgt_cache() do { } while (0)
132 #endif /* _ASM_POWERPC_PGALLOC_64_H */