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