2 * Based on arch/arm/include/asm/pgalloc.h
4 * Copyright (C) 2000-2001 Russell King
5 * Copyright (C) 2012 ARM Ltd.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef __ASM_PGALLOC_H
20 #define __ASM_PGALLOC_H
22 #include <asm/pgtable-hwdef.h>
23 #include <asm/processor.h>
24 #include <asm/cacheflush.h>
25 #include <asm/tlbflush.h>
27 #define check_pgt_cache() do { } while (0)
29 #define PGALLOC_GFP (GFP_KERNEL | __GFP_NOTRACK | __GFP_REPEAT | __GFP_ZERO)
30 #define PGD_SIZE (PTRS_PER_PGD * sizeof(pgd_t))
32 #if CONFIG_PGTABLE_LEVELS > 2
34 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
36 return (pmd_t *)__get_free_page(PGALLOC_GFP);
39 static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
41 BUG_ON((unsigned long)pmd & (PAGE_SIZE-1));
42 free_page((unsigned long)pmd);
45 static inline void __pud_populate(pud_t *pud, phys_addr_t pmd, pudval_t prot)
47 set_pud(pud, __pud(pmd | prot));
50 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
52 __pud_populate(pud, __pa(pmd), PMD_TYPE_TABLE);
55 static inline void __pud_populate(pud_t *pud, phys_addr_t pmd, pudval_t prot)
59 #endif /* CONFIG_PGTABLE_LEVELS > 2 */
61 #if CONFIG_PGTABLE_LEVELS > 3
63 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
65 return (pud_t *)__get_free_page(PGALLOC_GFP);
68 static inline void pud_free(struct mm_struct *mm, pud_t *pud)
70 BUG_ON((unsigned long)pud & (PAGE_SIZE-1));
71 free_page((unsigned long)pud);
74 static inline void __pgd_populate(pgd_t *pgdp, phys_addr_t pud, pgdval_t prot)
76 set_pgd(pgdp, __pgd(pud | prot));
79 static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
81 __pgd_populate(pgd, __pa(pud), PUD_TYPE_TABLE);
84 static inline void __pgd_populate(pgd_t *pgdp, phys_addr_t pud, pgdval_t prot)
88 #endif /* CONFIG_PGTABLE_LEVELS > 3 */
90 extern pgd_t *pgd_alloc(struct mm_struct *mm);
91 extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
94 pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
96 return (pte_t *)__get_free_page(PGALLOC_GFP);
99 static inline pgtable_t
100 pte_alloc_one(struct mm_struct *mm, unsigned long addr)
104 pte = alloc_pages(PGALLOC_GFP, 0);
107 if (!pgtable_page_ctor(pte)) {
117 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
120 free_page((unsigned long)pte);
123 static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
125 pgtable_page_dtor(pte);
129 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
132 set_pmd(pmdp, __pmd(pte | prot));
136 * Populate the pmdp entry with a pointer to the pte. This pmd is part
137 * of the mm address space.
140 pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
143 * The pmd must be loaded with the physical address of the PTE table
145 __pmd_populate(pmdp, __pa(ptep), PMD_TYPE_TABLE);
149 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
151 __pmd_populate(pmdp, page_to_phys(ptep), PMD_TYPE_TABLE);
153 #define pmd_pgtable(pmd) pmd_page(pmd)