David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 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 | |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 10 | #include <linux/slab.h> |
| 11 | #include <linux/cpumask.h> |
| 12 | #include <linux/percpu.h> |
| 13 | |
David Gibson | a0668cd | 2009-10-28 16:27:18 +0000 | [diff] [blame^] | 14 | /* |
| 15 | * Functions that deal with pagetables that could be at any level of |
| 16 | * the table need to be passed an "index_size" so they know how to |
| 17 | * handle allocation. For PTE pages (which are linked to a struct |
| 18 | * page for now, and drawn from the main get_free_pages() pool), the |
| 19 | * allocation size will be (2^index_size * sizeof(pointer)) and |
| 20 | * allocations are drawn from the kmem_cache in PGT_CACHE(index_size). |
| 21 | * |
| 22 | * The maximum index size needs to be big enough to allow any |
| 23 | * pagetable sizes we need, but small enough to fit in the low bits of |
| 24 | * any page table pointer. In other words all pagetables, even tiny |
| 25 | * ones, must be aligned to allow at least enough low 0 bits to |
| 26 | * contain this value. This value is also used as a mask, so it must |
| 27 | * be one less than a power of two. |
| 28 | */ |
| 29 | #define MAX_PGTABLE_INDEX_SIZE 0xf |
| 30 | |
Paul Mackerras | fa28237 | 2008-01-24 08:35:13 +1100 | [diff] [blame] | 31 | #ifndef CONFIG_PPC_SUBPAGE_PROT |
| 32 | static inline void subpage_prot_free(pgd_t *pgd) {} |
| 33 | #endif |
| 34 | |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 35 | extern struct kmem_cache *pgtable_cache[]; |
David Gibson | a0668cd | 2009-10-28 16:27:18 +0000 | [diff] [blame^] | 36 | #define PGT_CACHE(shift) (pgtable_cache[(shift)-1]) |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 37 | |
| 38 | static inline pgd_t *pgd_alloc(struct mm_struct *mm) |
| 39 | { |
David Gibson | a0668cd | 2009-10-28 16:27:18 +0000 | [diff] [blame^] | 40 | return kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE), GFP_KERNEL); |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 41 | } |
| 42 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 43 | static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd) |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 44 | { |
Paul Mackerras | fa28237 | 2008-01-24 08:35:13 +1100 | [diff] [blame] | 45 | subpage_prot_free(pgd); |
David Gibson | a0668cd | 2009-10-28 16:27:18 +0000 | [diff] [blame^] | 46 | kmem_cache_free(PGT_CACHE(PGD_INDEX_SIZE), pgd); |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | #ifndef CONFIG_PPC_64K_PAGES |
| 50 | |
| 51 | #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD) |
| 52 | |
| 53 | static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr) |
| 54 | { |
David Gibson | a0668cd | 2009-10-28 16:27:18 +0000 | [diff] [blame^] | 55 | return kmem_cache_alloc(PGT_CACHE(PUD_INDEX_SIZE), |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 56 | GFP_KERNEL|__GFP_REPEAT); |
| 57 | } |
| 58 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 59 | static inline void pud_free(struct mm_struct *mm, pud_t *pud) |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 60 | { |
David Gibson | a0668cd | 2009-10-28 16:27:18 +0000 | [diff] [blame^] | 61 | kmem_cache_free(PGT_CACHE(PUD_INDEX_SIZE), pud); |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd) |
| 65 | { |
| 66 | pud_set(pud, (unsigned long)pmd); |
| 67 | } |
| 68 | |
| 69 | #define pmd_populate(mm, pmd, pte_page) \ |
| 70 | pmd_populate_kernel(mm, pmd, page_address(pte_page)) |
| 71 | #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte)) |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 72 | #define pmd_pgtable(pmd) pmd_page(pmd) |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 73 | |
| 74 | |
| 75 | #else /* CONFIG_PPC_64K_PAGES */ |
| 76 | |
| 77 | #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd) |
| 78 | |
| 79 | static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, |
| 80 | pte_t *pte) |
| 81 | { |
| 82 | pmd_set(pmd, (unsigned long)pte); |
| 83 | } |
| 84 | |
| 85 | #define pmd_populate(mm, pmd, pte_page) \ |
| 86 | pmd_populate_kernel(mm, pmd, page_address(pte_page)) |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 87 | #define pmd_pgtable(pmd) pmd_page(pmd) |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 88 | |
| 89 | #endif /* CONFIG_PPC_64K_PAGES */ |
| 90 | |
| 91 | static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr) |
| 92 | { |
David Gibson | a0668cd | 2009-10-28 16:27:18 +0000 | [diff] [blame^] | 93 | return kmem_cache_alloc(PGT_CACHE(PMD_INDEX_SIZE), |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 94 | GFP_KERNEL|__GFP_REPEAT); |
| 95 | } |
| 96 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 97 | static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd) |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 98 | { |
David Gibson | a0668cd | 2009-10-28 16:27:18 +0000 | [diff] [blame^] | 99 | kmem_cache_free(PGT_CACHE(PMD_INDEX_SIZE), pmd); |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, |
| 103 | unsigned long address) |
| 104 | { |
Hugh Dickins | 517e226 | 2007-05-09 14:38:48 +1000 | [diff] [blame] | 105 | return (pte_t *)__get_free_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO); |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 106 | } |
| 107 | |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 108 | static inline pgtable_t pte_alloc_one(struct mm_struct *mm, |
| 109 | unsigned long address) |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 110 | { |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 111 | struct page *page; |
| 112 | pte_t *pte; |
| 113 | |
| 114 | pte = pte_alloc_one_kernel(mm, address); |
| 115 | if (!pte) |
| 116 | return NULL; |
| 117 | page = virt_to_page(pte); |
| 118 | pgtable_page_ctor(page); |
| 119 | return page; |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 120 | } |
| 121 | |
David Gibson | a0668cd | 2009-10-28 16:27:18 +0000 | [diff] [blame^] | 122 | static inline void pgtable_free(void *table, unsigned index_size) |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 123 | { |
David Gibson | a0668cd | 2009-10-28 16:27:18 +0000 | [diff] [blame^] | 124 | if (!index_size) |
| 125 | free_page((unsigned long)table); |
| 126 | else { |
| 127 | BUG_ON(index_size > MAX_PGTABLE_INDEX_SIZE); |
| 128 | kmem_cache_free(PGT_CACHE(index_size), table); |
| 129 | } |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 130 | } |
| 131 | |
David Gibson | a0668cd | 2009-10-28 16:27:18 +0000 | [diff] [blame^] | 132 | #define __pmd_free_tlb(tlb, pmd, addr) \ |
| 133 | pgtable_free_tlb(tlb, pmd, PMD_INDEX_SIZE) |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 134 | #ifndef CONFIG_PPC_64K_PAGES |
Benjamin Herrenschmidt | 9e1b32c | 2009-07-22 15:44:28 +1000 | [diff] [blame] | 135 | #define __pud_free_tlb(tlb, pud, addr) \ |
David Gibson | a0668cd | 2009-10-28 16:27:18 +0000 | [diff] [blame^] | 136 | pgtable_free_tlb(tlb, pud, PUD_INDEX_SIZE) |
| 137 | |
David Gibson | f88df14 | 2007-04-30 16:30:56 +1000 | [diff] [blame] | 138 | #endif /* CONFIG_PPC_64K_PAGES */ |
| 139 | |
| 140 | #define check_pgt_cache() do { } while (0) |
| 141 | |
| 142 | #endif /* _ASM_POWERPC_PGALLOC_64_H */ |