]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - include/asm-avr32/pgalloc.h
a291f59659cf10f6c6f7ec8306c75f3470eda19e
[linux-2.6-omap-h63xx.git] / include / asm-avr32 / pgalloc.h
1 /*
2  * Copyright (C) 2004-2006 Atmel Corporation
3  *
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.
7  */
8 #ifndef __ASM_AVR32_PGALLOC_H
9 #define __ASM_AVR32_PGALLOC_H
10
11 #include <linux/quicklist.h>
12 #include <asm/page.h>
13 #include <asm/pgtable.h>
14
15 #define QUICK_PGD       0       /* Preserve kernel mappings over free */
16
17 static inline void pmd_populate_kernel(struct mm_struct *mm,
18                                        pmd_t *pmd, pte_t *pte)
19 {
20         set_pmd(pmd, __pmd((unsigned long)pte));
21 }
22
23 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
24                                     pgtable_t pte)
25 {
26         set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
27 }
28 #define pmd_pgtable(pmd) pmd_page(pmd)
29
30 static inline void pgd_ctor(void *x)
31 {
32         pgd_t *pgd = x;
33
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));
37 }
38
39 /*
40  * Allocate and free page tables
41  */
42 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
43 {
44         return quicklist_alloc(QUICK_PGD, GFP_KERNEL | __GFP_REPEAT, pgd_ctor);
45 }
46
47 static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
48 {
49         quicklist_free(QUICK_PGD, NULL, pgd);
50 }
51
52 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
53                                           unsigned long address)
54 {
55         pte_t *pte;
56
57         pte = (pte_t *)get_zeroed_page(GFP_KERNEL | __GFP_REPEAT);
58
59         return pte;
60 }
61
62 static inline struct page *pte_alloc_one(struct mm_struct *mm,
63                                          unsigned long address)
64 {
65         struct page *pte;
66
67         pte = alloc_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
68         if (!pte)
69                 return NULL;
70         pgtable_page_ctor(pte);
71         return pte;
72 }
73
74 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
75 {
76         free_page((unsigned long)pte);
77 }
78
79 static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
80 {
81         pgtable_page_dtor(pte);
82         __free_page(pte);
83 }
84
85 #define __pte_free_tlb(tlb,pte)                         \
86 do {                                                    \
87         pgtable_page_dtor(pte);                         \
88         tlb_remove_page((tlb), pte);                    \
89 } while (0)
90
91 static inline void check_pgt_cache(void)
92 {
93         quicklist_trim(QUICK_PGD, NULL, 25, 16);
94 }
95
96 #endif /* __ASM_AVR32_PGALLOC_H */