29b5727ef39b81621374256f44758ed2ab5a9764
[linux-2.6.git] / include / asm-ppc64 / pgalloc.h
1 #ifndef _PPC64_PGALLOC_H
2 #define _PPC64_PGALLOC_H
3
4 #include <linux/mm.h>
5 #include <linux/slab.h>
6 #include <linux/cpumask.h>
7 #include <linux/percpu.h>
8 #include <asm/processor.h>
9 #include <asm/tlb.h>
10
11 extern kmem_cache_t *zero_cache;
12
13 /* Dummy functions since we don't support execshield on ppc */
14 #define arch_add_exec_range(mm, limit) do { ; } while (0)
15 #define arch_flush_exec_range(mm)      do { ; } while (0)
16 #define arch_remove_exec_range(mm, limit) do { ; } while (0)
17
18 /*
19  * This program is free software; you can redistribute it and/or
20  * modify it under the terms of the GNU General Public License
21  * as published by the Free Software Foundation; either version
22  * 2 of the License, or (at your option) any later version.
23  */
24
25 static inline pgd_t *
26 pgd_alloc(struct mm_struct *mm)
27 {
28         return kmem_cache_alloc(zero_cache, GFP_KERNEL);
29 }
30
31 static inline void
32 pgd_free(pgd_t *pgd)
33 {
34         kmem_cache_free(zero_cache, pgd);
35 }
36
37 #define pgd_populate(MM, PGD, PMD)      pgd_set(PGD, PMD)
38
39 static inline pmd_t *
40 pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
41 {
42         return kmem_cache_alloc(zero_cache, GFP_KERNEL|__GFP_REPEAT);
43 }
44
45 static inline void
46 pmd_free(pmd_t *pmd)
47 {
48         kmem_cache_free(zero_cache, pmd);
49 }
50
51 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, pte)
52 #define pmd_populate(mm, pmd, pte_page) \
53         pmd_populate_kernel(mm, pmd, page_address(pte_page))
54
55 static inline pte_t *
56 pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
57 {
58         pte_t *pte;
59         pte = kmem_cache_alloc(zero_cache, GFP_KERNEL|__GFP_REPEAT);
60         if (pte) {
61                 struct page *ptepage = virt_to_page(pte);
62                 ptepage->mapping = (void *) mm;
63                 ptepage->index = address & PMD_MASK;
64         }
65         return pte;
66 }
67
68 static inline struct page *
69 pte_alloc_one(struct mm_struct *mm, unsigned long address)
70 {
71         pte_t *pte;
72         pte = kmem_cache_alloc(zero_cache, GFP_KERNEL|__GFP_REPEAT);
73         if (pte) {
74                 struct page *ptepage = virt_to_page(pte);
75                 ptepage->mapping = (void *) mm;
76                 ptepage->index = address & PMD_MASK;
77                 return ptepage;
78         }
79         return NULL;
80 }
81                 
82 static inline void pte_free_kernel(pte_t *pte)
83 {
84         virt_to_page(pte)->mapping = NULL;
85         kmem_cache_free(zero_cache, pte);
86 }
87
88 static inline void pte_free(struct page *ptepage)
89 {
90         ptepage->mapping = NULL;
91         kmem_cache_free(zero_cache, page_address(ptepage));
92 }
93
94 struct pte_freelist_batch
95 {
96         struct rcu_head rcu;
97         unsigned int    index;
98         struct page *   pages[0];
99 };
100
101 #define PTE_FREELIST_SIZE       ((PAGE_SIZE - sizeof(struct pte_freelist_batch)) / \
102                                   sizeof(struct page *))
103
104 extern void pte_free_now(struct page *ptepage);
105 extern void pte_free_submit(struct pte_freelist_batch *batch);
106
107 DECLARE_PER_CPU(struct pte_freelist_batch *, pte_freelist_cur);
108
109 static inline void __pte_free_tlb(struct mmu_gather *tlb, struct page *ptepage)
110 {
111         /* This is safe as we are holding page_table_lock */
112         cpumask_t local_cpumask = cpumask_of_cpu(smp_processor_id());
113         struct pte_freelist_batch **batchp = &__get_cpu_var(pte_freelist_cur);
114
115         if (atomic_read(&tlb->mm->mm_users) < 2 ||
116             cpus_equal(tlb->mm->cpu_vm_mask, local_cpumask)) {
117                 pte_free(ptepage);
118                 return;
119         }
120
121         if (*batchp == NULL) {
122                 *batchp = (struct pte_freelist_batch *)__get_free_page(GFP_ATOMIC);
123                 if (*batchp == NULL) {
124                         pte_free_now(ptepage);
125                         return;
126                 }
127                 (*batchp)->index = 0;
128         }
129         (*batchp)->pages[(*batchp)->index++] = ptepage;
130         if ((*batchp)->index == PTE_FREELIST_SIZE) {
131                 pte_free_submit(*batchp);
132                 *batchp = NULL;
133         }
134 }
135
136 #define __pmd_free_tlb(tlb, pmd)        __pte_free_tlb(tlb, virt_to_page(pmd))
137
138 #define check_pgt_cache()       do { } while (0)
139
140 #endif /* _PPC64_PGALLOC_H */