Merge branch 'master' into for-linus
[sfrench/cifs-2.6.git] / arch / powerpc / include / asm / pgalloc.h
1 #ifndef _ASM_POWERPC_PGALLOC_H
2 #define _ASM_POWERPC_PGALLOC_H
3 #ifdef __KERNEL__
4
5 #include <linux/mm.h>
6
7 #ifdef CONFIG_PPC_BOOK3E
8 extern void tlb_flush_pgtable(struct mmu_gather *tlb, unsigned long address);
9 #else /* CONFIG_PPC_BOOK3E */
10 static inline void tlb_flush_pgtable(struct mmu_gather *tlb,
11                                      unsigned long address)
12 {
13 }
14 #endif /* !CONFIG_PPC_BOOK3E */
15
16 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
17 {
18         free_page((unsigned long)pte);
19 }
20
21 static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)
22 {
23         pgtable_page_dtor(ptepage);
24         __free_page(ptepage);
25 }
26
27 typedef struct pgtable_free {
28         unsigned long val;
29 } pgtable_free_t;
30
31 /* This needs to be big enough to allow for MMU_PAGE_COUNT + 2 to be stored
32  * and small enough to fit in the low bits of any naturally aligned page
33  * table cache entry. Arbitrarily set to 0x1f, that should give us some
34  * room to grow
35  */
36 #define PGF_CACHENUM_MASK       0x1f
37
38 static inline pgtable_free_t pgtable_free_cache(void *p, int cachenum,
39                                                 unsigned long mask)
40 {
41         BUG_ON(cachenum > PGF_CACHENUM_MASK);
42
43         return (pgtable_free_t){.val = ((unsigned long) p & ~mask) | cachenum};
44 }
45
46 #ifdef CONFIG_PPC64
47 #include <asm/pgalloc-64.h>
48 #else
49 #include <asm/pgalloc-32.h>
50 #endif
51
52 #ifdef CONFIG_SMP
53 extern void pgtable_free_tlb(struct mmu_gather *tlb, pgtable_free_t pgf);
54 extern void pte_free_finish(void);
55 #else /* CONFIG_SMP */
56 static inline void pgtable_free_tlb(struct mmu_gather *tlb, pgtable_free_t pgf)
57 {
58         pgtable_free(pgf);
59 }
60 static inline void pte_free_finish(void) { }
61 #endif /* !CONFIG_SMP */
62
63 static inline void __pte_free_tlb(struct mmu_gather *tlb, struct page *ptepage,
64                                   unsigned long address)
65 {
66         pgtable_free_t pgf = pgtable_free_cache(page_address(ptepage),
67                                                 PTE_NONCACHE_NUM,
68                                                 PTE_TABLE_SIZE-1);
69         tlb_flush_pgtable(tlb, address);
70         pgtable_page_dtor(ptepage);
71         pgtable_free_tlb(tlb, pgf);
72 }
73
74 #endif /* __KERNEL__ */
75 #endif /* _ASM_POWERPC_PGALLOC_H */