Paul Mackerras | 047ea78 | 2005-11-19 20:17:32 +1100 | [diff] [blame] | 1 | #ifndef _ASM_POWERPC_PGALLOC_H |
| 2 | #define _ASM_POWERPC_PGALLOC_H |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 3 | #ifdef __KERNEL__ |
Paul Mackerras | 047ea78 | 2005-11-19 20:17:32 +1100 | [diff] [blame] | 4 | |
| 5 | #ifndef CONFIG_PPC64 |
| 6 | #include <asm-ppc/pgalloc.h> |
| 7 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
| 9 | #include <linux/mm.h> |
| 10 | #include <linux/slab.h> |
| 11 | #include <linux/cpumask.h> |
| 12 | #include <linux/percpu.h> |
| 13 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 14 | extern struct kmem_cache *pgtable_cache[]; |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 15 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 16 | #ifdef CONFIG_PPC_64K_PAGES |
| 17 | #define PTE_CACHE_NUM 0 |
Benjamin Herrenschmidt | 87655ff | 2005-11-10 14:53:16 +1100 | [diff] [blame] | 18 | #define PMD_CACHE_NUM 1 |
| 19 | #define PGD_CACHE_NUM 2 |
David Gibson | f10a04c | 2006-04-28 15:02:51 +1000 | [diff] [blame] | 20 | #define HUGEPTE_CACHE_NUM 3 |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 21 | #else |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 22 | #define PTE_CACHE_NUM 0 |
| 23 | #define PMD_CACHE_NUM 1 |
| 24 | #define PUD_CACHE_NUM 1 |
| 25 | #define PGD_CACHE_NUM 0 |
David Gibson | f10a04c | 2006-04-28 15:02:51 +1000 | [diff] [blame] | 26 | #define HUGEPTE_CACHE_NUM 2 |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 27 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | /* |
| 30 | * This program is free software; you can redistribute it and/or |
| 31 | * modify it under the terms of the GNU General Public License |
| 32 | * as published by the Free Software Foundation; either version |
| 33 | * 2 of the License, or (at your option) any later version. |
| 34 | */ |
| 35 | |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 36 | static inline pgd_t *pgd_alloc(struct mm_struct *mm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 38 | return kmem_cache_alloc(pgtable_cache[PGD_CACHE_NUM], GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | } |
| 40 | |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 41 | static inline void pgd_free(pgd_t *pgd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | { |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 43 | kmem_cache_free(pgtable_cache[PGD_CACHE_NUM], pgd); |
| 44 | } |
| 45 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 46 | #ifndef CONFIG_PPC_64K_PAGES |
| 47 | |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 48 | #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD) |
| 49 | |
| 50 | static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr) |
| 51 | { |
| 52 | return kmem_cache_alloc(pgtable_cache[PUD_CACHE_NUM], |
| 53 | GFP_KERNEL|__GFP_REPEAT); |
| 54 | } |
| 55 | |
| 56 | static inline void pud_free(pud_t *pud) |
| 57 | { |
| 58 | kmem_cache_free(pgtable_cache[PUD_CACHE_NUM], pud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 61 | static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd) |
| 62 | { |
| 63 | pud_set(pud, (unsigned long)pmd); |
| 64 | } |
| 65 | |
| 66 | #define pmd_populate(mm, pmd, pte_page) \ |
| 67 | pmd_populate_kernel(mm, pmd, page_address(pte_page)) |
| 68 | #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte)) |
| 69 | |
| 70 | |
| 71 | #else /* CONFIG_PPC_64K_PAGES */ |
| 72 | |
| 73 | #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd) |
| 74 | |
| 75 | static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, |
| 76 | pte_t *pte) |
| 77 | { |
| 78 | pmd_set(pmd, (unsigned long)pte); |
| 79 | } |
| 80 | |
| 81 | #define pmd_populate(mm, pmd, pte_page) \ |
| 82 | pmd_populate_kernel(mm, pmd, page_address(pte_page)) |
| 83 | |
| 84 | #endif /* CONFIG_PPC_64K_PAGES */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 86 | static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 88 | return kmem_cache_alloc(pgtable_cache[PMD_CACHE_NUM], |
| 89 | GFP_KERNEL|__GFP_REPEAT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 92 | static inline void pmd_free(pmd_t *pmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 94 | kmem_cache_free(pgtable_cache[PMD_CACHE_NUM], pmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 97 | static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, |
| 98 | unsigned long address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 100 | return kmem_cache_alloc(pgtable_cache[PTE_CACHE_NUM], |
| 101 | GFP_KERNEL|__GFP_REPEAT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 104 | static inline struct page *pte_alloc_one(struct mm_struct *mm, |
| 105 | unsigned long address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 107 | return virt_to_page(pte_alloc_one_kernel(mm, address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | static inline void pte_free_kernel(pte_t *pte) |
| 111 | { |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 112 | kmem_cache_free(pgtable_cache[PTE_CACHE_NUM], pte); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static inline void pte_free(struct page *ptepage) |
| 116 | { |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 117 | pte_free_kernel(page_address(ptepage)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Adam Litke | c9169f8 | 2006-08-18 11:22:21 -0700 | [diff] [blame] | 120 | #define PGF_CACHENUM_MASK 0x3 |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 121 | |
| 122 | typedef struct pgtable_free { |
| 123 | unsigned long val; |
| 124 | } pgtable_free_t; |
| 125 | |
| 126 | static inline pgtable_free_t pgtable_free_cache(void *p, int cachenum, |
| 127 | unsigned long mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 129 | BUG_ON(cachenum > PGF_CACHENUM_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 131 | return (pgtable_free_t){.val = ((unsigned long) p & ~mask) | cachenum}; |
| 132 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 134 | static inline void pgtable_free(pgtable_free_t pgf) |
| 135 | { |
| 136 | void *p = (void *)(pgf.val & ~PGF_CACHENUM_MASK); |
| 137 | int cachenum = pgf.val & PGF_CACHENUM_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 139 | kmem_cache_free(pgtable_cache[cachenum], p); |
| 140 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 142 | extern void pgtable_free_tlb(struct mmu_gather *tlb, pgtable_free_t pgf); |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 143 | |
| 144 | #define __pte_free_tlb(tlb, ptepage) \ |
| 145 | pgtable_free_tlb(tlb, pgtable_free_cache(page_address(ptepage), \ |
| 146 | PTE_CACHE_NUM, PTE_TABLE_SIZE-1)) |
| 147 | #define __pmd_free_tlb(tlb, pmd) \ |
| 148 | pgtable_free_tlb(tlb, pgtable_free_cache(pmd, \ |
| 149 | PMD_CACHE_NUM, PMD_TABLE_SIZE-1)) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 150 | #ifndef CONFIG_PPC_64K_PAGES |
David Gibson | 200a455 | 2006-02-17 13:52:56 -0800 | [diff] [blame] | 151 | #define __pud_free_tlb(tlb, pud) \ |
David Gibson | e28f7fa | 2005-08-05 19:39:06 +1000 | [diff] [blame] | 152 | pgtable_free_tlb(tlb, pgtable_free_cache(pud, \ |
| 153 | PUD_CACHE_NUM, PUD_TABLE_SIZE-1)) |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 154 | #endif /* CONFIG_PPC_64K_PAGES */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | #define check_pgt_cache() do { } while (0) |
| 157 | |
Paul Mackerras | 047ea78 | 2005-11-19 20:17:32 +1100 | [diff] [blame] | 158 | #endif /* CONFIG_PPC64 */ |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 159 | #endif /* __KERNEL__ */ |
Paul Mackerras | 047ea78 | 2005-11-19 20:17:32 +1100 | [diff] [blame] | 160 | #endif /* _ASM_POWERPC_PGALLOC_H */ |