aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-powerpc/pgalloc-64.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/asm-powerpc/pgalloc-64.h')
-rw-r--r--include/asm-powerpc/pgalloc-64.h152
1 files changed, 152 insertions, 0 deletions
diff --git a/include/asm-powerpc/pgalloc-64.h b/include/asm-powerpc/pgalloc-64.h
new file mode 100644
index 000000000000..30b50cf56e2c
--- /dev/null
+++ b/include/asm-powerpc/pgalloc-64.h
@@ -0,0 +1,152 @@
1#ifndef _ASM_POWERPC_PGALLOC_64_H
2#define _ASM_POWERPC_PGALLOC_64_H
3/*
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.
8 */
9
10#include <linux/mm.h>
11#include <linux/slab.h>
12#include <linux/cpumask.h>
13#include <linux/percpu.h>
14
15extern struct kmem_cache *pgtable_cache[];
16
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
22#else
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
28#endif
29
30static inline pgd_t *pgd_alloc(struct mm_struct *mm)
31{
32 return kmem_cache_alloc(pgtable_cache[PGD_CACHE_NUM], GFP_KERNEL);
33}
34
35static inline void pgd_free(pgd_t *pgd)
36{
37 kmem_cache_free(pgtable_cache[PGD_CACHE_NUM], pgd);
38}
39
40#ifndef CONFIG_PPC_64K_PAGES
41
42#define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
43
44static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
45{
46 return kmem_cache_alloc(pgtable_cache[PUD_CACHE_NUM],
47 GFP_KERNEL|__GFP_REPEAT);
48}
49
50static inline void pud_free(pud_t *pud)
51{
52 kmem_cache_free(pgtable_cache[PUD_CACHE_NUM], pud);
53}
54
55static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
56{
57 pud_set(pud, (unsigned long)pmd);
58}
59
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))
63
64
65#else /* CONFIG_PPC_64K_PAGES */
66
67#define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
68
69static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
70 pte_t *pte)
71{
72 pmd_set(pmd, (unsigned long)pte);
73}
74
75#define pmd_populate(mm, pmd, pte_page) \
76 pmd_populate_kernel(mm, pmd, page_address(pte_page))
77
78#endif /* CONFIG_PPC_64K_PAGES */
79
80static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
81{
82 return kmem_cache_alloc(pgtable_cache[PMD_CACHE_NUM],
83 GFP_KERNEL|__GFP_REPEAT);
84}
85
86static inline void pmd_free(pmd_t *pmd)
87{
88 kmem_cache_free(pgtable_cache[PMD_CACHE_NUM], pmd);
89}
90
91static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
92 unsigned long address)
93{
94 return kmem_cache_alloc(pgtable_cache[PTE_CACHE_NUM],
95 GFP_KERNEL|__GFP_REPEAT);
96}
97
98static inline struct page *pte_alloc_one(struct mm_struct *mm,
99 unsigned long address)
100{
101 return virt_to_page(pte_alloc_one_kernel(mm, address));
102}
103
104static inline void pte_free_kernel(pte_t *pte)
105{
106 kmem_cache_free(pgtable_cache[PTE_CACHE_NUM], pte);
107}
108
109static inline void pte_free(struct page *ptepage)
110{
111 pte_free_kernel(page_address(ptepage));
112}
113
114#define PGF_CACHENUM_MASK 0x3
115
116typedef struct pgtable_free {
117 unsigned long val;
118} pgtable_free_t;
119
120static inline pgtable_free_t pgtable_free_cache(void *p, int cachenum,
121 unsigned long mask)
122{
123 BUG_ON(cachenum > PGF_CACHENUM_MASK);
124
125 return (pgtable_free_t){.val = ((unsigned long) p & ~mask) | cachenum};
126}
127
128static inline void pgtable_free(pgtable_free_t pgf)
129{
130 void *p = (void *)(pgf.val & ~PGF_CACHENUM_MASK);
131 int cachenum = pgf.val & PGF_CACHENUM_MASK;
132
133 kmem_cache_free(pgtable_cache[cachenum], p);
134}
135
136extern void pgtable_free_tlb(struct mmu_gather *tlb, pgtable_free_t pgf);
137
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 */
149
150#define check_pgt_cache() do { } while (0)
151
152#endif /* _ASM_POWERPC_PGALLOC_64_H */