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.
11 #include <linux/slab.h>
12 #include <linux/cpumask.h>
13 #include <linux/percpu.h>
15 extern struct kmem_cache *pgtable_cache[];
17 #ifdef CONFIG_PPC_64K_PAGES
18 #define PTE_CACHE_NUM 0
19 #define PMD_CACHE_NUM 1
20 #define PGD_CACHE_NUM 2
21 #define HUGEPTE_CACHE_NUM 3
23 #define PTE_CACHE_NUM 0
24 #define PMD_CACHE_NUM 1
25 #define PUD_CACHE_NUM 1
26 #define PGD_CACHE_NUM 0
27 #define HUGEPTE_CACHE_NUM 2
30 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
32 return kmem_cache_alloc(pgtable_cache[PGD_CACHE_NUM], GFP_KERNEL);
35 static inline void pgd_free(pgd_t *pgd)
37 kmem_cache_free(pgtable_cache[PGD_CACHE_NUM], pgd);
40 #ifndef CONFIG_PPC_64K_PAGES
42 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
44 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
46 return kmem_cache_alloc(pgtable_cache[PUD_CACHE_NUM],
47 GFP_KERNEL|__GFP_REPEAT);
50 static inline void pud_free(pud_t *pud)
52 kmem_cache_free(pgtable_cache[PUD_CACHE_NUM], pud);
55 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
57 pud_set(pud, (unsigned long)pmd);
60 #define pmd_populate(mm, pmd, pte_page) \
61 pmd_populate_kernel(mm, pmd, page_address(pte_page))
62 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
65 #else /* CONFIG_PPC_64K_PAGES */
67 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
69 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
72 pmd_set(pmd, (unsigned long)pte);
75 #define pmd_populate(mm, pmd, pte_page) \
76 pmd_populate_kernel(mm, pmd, page_address(pte_page))
78 #endif /* CONFIG_PPC_64K_PAGES */
80 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
82 return kmem_cache_alloc(pgtable_cache[PMD_CACHE_NUM],
83 GFP_KERNEL|__GFP_REPEAT);
86 static inline void pmd_free(pmd_t *pmd)
88 kmem_cache_free(pgtable_cache[PMD_CACHE_NUM], pmd);
91 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
92 unsigned long address)
94 return kmem_cache_alloc(pgtable_cache[PTE_CACHE_NUM],
95 GFP_KERNEL|__GFP_REPEAT);
98 static inline struct page *pte_alloc_one(struct mm_struct *mm,
99 unsigned long address)
101 return virt_to_page(pte_alloc_one_kernel(mm, address));
104 static inline void pte_free_kernel(pte_t *pte)
106 kmem_cache_free(pgtable_cache[PTE_CACHE_NUM], pte);
109 static inline void pte_free(struct page *ptepage)
111 pte_free_kernel(page_address(ptepage));
114 #define PGF_CACHENUM_MASK 0x3
116 typedef struct pgtable_free {
120 static inline pgtable_free_t pgtable_free_cache(void *p, int cachenum,
123 BUG_ON(cachenum > PGF_CACHENUM_MASK);
125 return (pgtable_free_t){.val = ((unsigned long) p & ~mask) | cachenum};
128 static inline void pgtable_free(pgtable_free_t pgf)
130 void *p = (void *)(pgf.val & ~PGF_CACHENUM_MASK);
131 int cachenum = pgf.val & PGF_CACHENUM_MASK;
133 kmem_cache_free(pgtable_cache[cachenum], p);
136 extern void pgtable_free_tlb(struct mmu_gather *tlb, pgtable_free_t pgf);
138 #define __pte_free_tlb(tlb, ptepage) \
139 pgtable_free_tlb(tlb, pgtable_free_cache(page_address(ptepage), \
140 PTE_CACHE_NUM, PTE_TABLE_SIZE-1))
141 #define __pmd_free_tlb(tlb, pmd) \
142 pgtable_free_tlb(tlb, pgtable_free_cache(pmd, \
143 PMD_CACHE_NUM, PMD_TABLE_SIZE-1))
144 #ifndef CONFIG_PPC_64K_PAGES
145 #define __pud_free_tlb(tlb, pud) \
146 pgtable_free_tlb(tlb, pgtable_free_cache(pud, \
147 PUD_CACHE_NUM, PUD_TABLE_SIZE-1))
148 #endif /* CONFIG_PPC_64K_PAGES */
150 #define check_pgt_cache() do { } while (0)
152 #endif /* _ASM_POWERPC_PGALLOC_64_H */