2 * Copyright (C) 2004-2006 Atmel Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 #ifndef __ASM_AVR32_PGALLOC_H
9 #define __ASM_AVR32_PGALLOC_H
11 #include <linux/quicklist.h>
13 #include <asm/pgtable.h>
15 #define QUICK_PGD 0 /* Preserve kernel mappings over free */
17 static inline void pmd_populate_kernel(struct mm_struct *mm,
18 pmd_t *pmd, pte_t *pte)
20 set_pmd(pmd, __pmd((unsigned long)pte));
23 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
26 set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
28 #define pmd_pgtable(pmd) pmd_page(pmd)
30 static inline void pgd_ctor(void *x)
34 memcpy(pgd + USER_PTRS_PER_PGD,
35 swapper_pg_dir + USER_PTRS_PER_PGD,
36 (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
40 * Allocate and free page tables
42 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
44 return quicklist_alloc(QUICK_PGD, GFP_KERNEL | __GFP_REPEAT, pgd_ctor);
47 static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
49 quicklist_free(QUICK_PGD, NULL, pgd);
52 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
53 unsigned long address)
57 pte = (pte_t *)get_zeroed_page(GFP_KERNEL | __GFP_REPEAT);
62 static inline struct page *pte_alloc_one(struct mm_struct *mm,
63 unsigned long address)
67 pte = alloc_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
70 pgtable_page_ctor(pte);
74 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
76 free_page((unsigned long)pte);
79 static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
81 pgtable_page_dtor(pte);
85 #define __pte_free_tlb(tlb,pte) \
87 pgtable_page_dtor(pte); \
88 tlb_remove_page((tlb), pte); \
91 static inline void check_pgt_cache(void)
93 quicklist_trim(QUICK_PGD, NULL, 25, 16);
96 #endif /* __ASM_AVR32_PGALLOC_H */