avr32: Cover the kernel page tables in the user PGDs
[linux-2.6] / 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/mm.h>
12
13 static inline void pmd_populate_kernel(struct mm_struct *mm,
14                                        pmd_t *pmd, pte_t *pte)
15 {
16         set_pmd(pmd, __pmd((unsigned long)pte));
17 }
18
19 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
20                                     pgtable_t pte)
21 {
22         set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
23 }
24 #define pmd_pgtable(pmd) pmd_page(pmd)
25
26 /*
27  * Allocate and free page tables
28  */
29 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
30 {
31         pgd_t *pgd;
32
33         pgd = (pgd_t *)get_zeroed_page(GFP_KERNEL | __GFP_REPEAT);
34         if (likely(pgd))
35                 memcpy(pgd + USER_PTRS_PER_PGD,
36                         swapper_pg_dir + USER_PTRS_PER_PGD,
37                         (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
38
39         return pgd;
40 }
41
42 static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
43 {
44         free_page((unsigned long)pgd);
45 }
46
47 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
48                                           unsigned long address)
49 {
50         pte_t *pte;
51
52         pte = (pte_t *)get_zeroed_page(GFP_KERNEL | __GFP_REPEAT);
53
54         return pte;
55 }
56
57 static inline struct page *pte_alloc_one(struct mm_struct *mm,
58                                          unsigned long address)
59 {
60         struct page *pte;
61
62         pte = alloc_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
63         if (!pte)
64                 return NULL;
65         pgtable_page_ctor(pte);
66         return pte;
67 }
68
69 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
70 {
71         free_page((unsigned long)pte);
72 }
73
74 static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
75 {
76         pgtable_page_dtor(pte);
77         __free_page(pte);
78 }
79
80 #define __pte_free_tlb(tlb,pte)                         \
81 do {                                                    \
82         pgtable_page_dtor(pte);                         \
83         tlb_remove_page((tlb), pte);                    \
84 } while (0)
85
86 #define check_pgt_cache() do { } while(0)
87
88 #endif /* __ASM_AVR32_PGALLOC_H */