blob: 292725cec2e3db07b5b5ea12885b8af56755f89e [file] [log] [blame]
David Gibsonf88df142007-04-30 16:30:56 +10001#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 Gibsonf88df142007-04-30 16:30:56 +100010#include <linux/slab.h>
11#include <linux/cpumask.h>
12#include <linux/percpu.h>
13
Mark Nelson91eea672010-04-21 16:21:03 +000014struct vmemmap_backing {
15 struct vmemmap_backing *list;
16 unsigned long phys;
17 unsigned long virt_addr;
18};
19
David Gibsona0668cd2009-10-28 16:27:18 +000020/*
21 * Functions that deal with pagetables that could be at any level of
22 * the table need to be passed an "index_size" so they know how to
23 * handle allocation. For PTE pages (which are linked to a struct
24 * page for now, and drawn from the main get_free_pages() pool), the
25 * allocation size will be (2^index_size * sizeof(pointer)) and
26 * allocations are drawn from the kmem_cache in PGT_CACHE(index_size).
27 *
28 * The maximum index size needs to be big enough to allow any
29 * pagetable sizes we need, but small enough to fit in the low bits of
30 * any page table pointer. In other words all pagetables, even tiny
31 * ones, must be aligned to allow at least enough low 0 bits to
32 * contain this value. This value is also used as a mask, so it must
33 * be one less than a power of two.
34 */
35#define MAX_PGTABLE_INDEX_SIZE 0xf
36
David Gibsonf88df142007-04-30 16:30:56 +100037extern struct kmem_cache *pgtable_cache[];
David Gibsona0668cd2009-10-28 16:27:18 +000038#define PGT_CACHE(shift) (pgtable_cache[(shift)-1])
David Gibsonf88df142007-04-30 16:30:56 +100039
40static inline pgd_t *pgd_alloc(struct mm_struct *mm)
41{
David Gibsona0668cd2009-10-28 16:27:18 +000042 return kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE), GFP_KERNEL);
David Gibsonf88df142007-04-30 16:30:56 +100043}
44
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080045static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
David Gibsonf88df142007-04-30 16:30:56 +100046{
David Gibsona0668cd2009-10-28 16:27:18 +000047 kmem_cache_free(PGT_CACHE(PGD_INDEX_SIZE), pgd);
David Gibsonf88df142007-04-30 16:30:56 +100048}
49
50#ifndef CONFIG_PPC_64K_PAGES
51
52#define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
53
54static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
55{
David Gibsona0668cd2009-10-28 16:27:18 +000056 return kmem_cache_alloc(PGT_CACHE(PUD_INDEX_SIZE),
David Gibsonf88df142007-04-30 16:30:56 +100057 GFP_KERNEL|__GFP_REPEAT);
58}
59
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080060static inline void pud_free(struct mm_struct *mm, pud_t *pud)
David Gibsonf88df142007-04-30 16:30:56 +100061{
David Gibsona0668cd2009-10-28 16:27:18 +000062 kmem_cache_free(PGT_CACHE(PUD_INDEX_SIZE), pud);
David Gibsonf88df142007-04-30 16:30:56 +100063}
64
65static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
66{
67 pud_set(pud, (unsigned long)pmd);
68}
69
70#define pmd_populate(mm, pmd, pte_page) \
71 pmd_populate_kernel(mm, pmd, page_address(pte_page))
72#define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080073#define pmd_pgtable(pmd) pmd_page(pmd)
David Gibsonf88df142007-04-30 16:30:56 +100074
75
76#else /* CONFIG_PPC_64K_PAGES */
77
78#define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
79
80static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
81 pte_t *pte)
82{
83 pmd_set(pmd, (unsigned long)pte);
84}
85
86#define pmd_populate(mm, pmd, pte_page) \
87 pmd_populate_kernel(mm, pmd, page_address(pte_page))
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080088#define pmd_pgtable(pmd) pmd_page(pmd)
David Gibsonf88df142007-04-30 16:30:56 +100089
90#endif /* CONFIG_PPC_64K_PAGES */
91
92static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
93{
David Gibsona0668cd2009-10-28 16:27:18 +000094 return kmem_cache_alloc(PGT_CACHE(PMD_INDEX_SIZE),
David Gibsonf88df142007-04-30 16:30:56 +100095 GFP_KERNEL|__GFP_REPEAT);
96}
97
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080098static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
David Gibsonf88df142007-04-30 16:30:56 +100099{
David Gibsona0668cd2009-10-28 16:27:18 +0000100 kmem_cache_free(PGT_CACHE(PMD_INDEX_SIZE), pmd);
David Gibsonf88df142007-04-30 16:30:56 +1000101}
102
103static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
104 unsigned long address)
105{
Hugh Dickins517e2262007-05-09 14:38:48 +1000106 return (pte_t *)__get_free_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
David Gibsonf88df142007-04-30 16:30:56 +1000107}
108
Martin Schwidefsky2f569af2008-02-08 04:22:04 -0800109static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
110 unsigned long address)
David Gibsonf88df142007-04-30 16:30:56 +1000111{
Martin Schwidefsky2f569af2008-02-08 04:22:04 -0800112 struct page *page;
113 pte_t *pte;
114
115 pte = pte_alloc_one_kernel(mm, address);
116 if (!pte)
117 return NULL;
118 page = virt_to_page(pte);
119 pgtable_page_ctor(page);
120 return page;
David Gibsonf88df142007-04-30 16:30:56 +1000121}
122
David Gibsona0668cd2009-10-28 16:27:18 +0000123static inline void pgtable_free(void *table, unsigned index_size)
David Gibsonf88df142007-04-30 16:30:56 +1000124{
David Gibsona0668cd2009-10-28 16:27:18 +0000125 if (!index_size)
126 free_page((unsigned long)table);
127 else {
128 BUG_ON(index_size > MAX_PGTABLE_INDEX_SIZE);
129 kmem_cache_free(PGT_CACHE(index_size), table);
130 }
David Gibsonf88df142007-04-30 16:30:56 +1000131}
132
David Gibsona0668cd2009-10-28 16:27:18 +0000133#define __pmd_free_tlb(tlb, pmd, addr) \
134 pgtable_free_tlb(tlb, pmd, PMD_INDEX_SIZE)
David Gibsonf88df142007-04-30 16:30:56 +1000135#ifndef CONFIG_PPC_64K_PAGES
Benjamin Herrenschmidt9e1b32c2009-07-22 15:44:28 +1000136#define __pud_free_tlb(tlb, pud, addr) \
David Gibsona0668cd2009-10-28 16:27:18 +0000137 pgtable_free_tlb(tlb, pud, PUD_INDEX_SIZE)
138
David Gibsonf88df142007-04-30 16:30:56 +1000139#endif /* CONFIG_PPC_64K_PAGES */
140
141#define check_pgt_cache() do { } while (0)
142
143#endif /* _ASM_POWERPC_PGALLOC_64_H */