1
2#ifndef _ASM_POWERPC_BOOK3S_32_PGALLOC_H
3#define _ASM_POWERPC_BOOK3S_32_PGALLOC_H
4
5#include <linux/threads.h>
6#include <linux/slab.h>
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#define MAX_PGTABLE_INDEX_SIZE 0xf
24
25extern void __bad_pte(pmd_t *pmd);
26
27extern struct kmem_cache *pgtable_cache[];
28#define PGT_CACHE(shift) ({ \
29 BUG_ON(!(shift)); \
30 pgtable_cache[(shift) - 1]; \
31 })
32
33static inline pgd_t *pgd_alloc(struct mm_struct *mm)
34{
35 return kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
36 pgtable_gfp_flags(mm, GFP_KERNEL));
37}
38
39static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
40{
41 kmem_cache_free(PGT_CACHE(PGD_INDEX_SIZE), pgd);
42}
43
44
45
46
47
48
49#define pmd_free(mm, x) do { } while (0)
50#define __pmd_free_tlb(tlb,x,a) do { } while (0)
51
52
53#ifndef CONFIG_BOOKE
54
55static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp,
56 pte_t *pte)
57{
58 *pmdp = __pmd(__pa(pte) | _PMD_PRESENT);
59}
60
61static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmdp,
62 pgtable_t pte_page)
63{
64 *pmdp = __pmd((page_to_pfn(pte_page) << PAGE_SHIFT) | _PMD_PRESENT);
65}
66
67#define pmd_pgtable(pmd) pmd_page(pmd)
68#else
69
70static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp,
71 pte_t *pte)
72{
73 *pmdp = __pmd((unsigned long)pte | _PMD_PRESENT);
74}
75
76static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmdp,
77 pgtable_t pte_page)
78{
79 *pmdp = __pmd((unsigned long)lowmem_page_address(pte_page) | _PMD_PRESENT);
80}
81
82#define pmd_pgtable(pmd) pmd_page(pmd)
83#endif
84
85extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr);
86extern pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long addr);
87
88static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
89{
90 free_page((unsigned long)pte);
91}
92
93static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)
94{
95 pgtable_page_dtor(ptepage);
96 __free_page(ptepage);
97}
98
99static inline void pgtable_free(void *table, unsigned index_size)
100{
101 if (!index_size) {
102 pgtable_page_dtor(virt_to_page(table));
103 free_page((unsigned long)table);
104 } else {
105 BUG_ON(index_size > MAX_PGTABLE_INDEX_SIZE);
106 kmem_cache_free(PGT_CACHE(index_size), table);
107 }
108}
109
110#define check_pgt_cache() do { } while (0)
111#define get_hugepd_cache_index(x) (x)
112
113static inline void pgtable_free_tlb(struct mmu_gather *tlb,
114 void *table, int shift)
115{
116 unsigned long pgf = (unsigned long)table;
117 BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE);
118 pgf |= shift;
119 tlb_remove_table(tlb, (void *)pgf);
120}
121
122static inline void __tlb_remove_table(void *_table)
123{
124 void *table = (void *)((unsigned long)_table & ~MAX_PGTABLE_INDEX_SIZE);
125 unsigned shift = (unsigned long)_table & MAX_PGTABLE_INDEX_SIZE;
126
127 pgtable_free(table, shift);
128}
129
130static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table,
131 unsigned long address)
132{
133 pgtable_free_tlb(tlb, page_address(table), 0);
134}
135#endif
136