ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / asm-sh / pgalloc.h
1 #ifndef __ASM_SH_PGALLOC_H
2 #define __ASM_SH_PGALLOC_H
3
4 #include <asm/processor.h>
5 #include <linux/threads.h>
6 #include <linux/slab.h>
7 #include <linux/mm.h>
8
9 #define pgd_quicklist ((unsigned long *)0)
10 #define pmd_quicklist ((unsigned long *)0)
11 #define pte_quicklist ((unsigned long *)0)
12 #define pgtable_cache_size 0L
13
14 #define pmd_populate_kernel(mm, pmd, pte) \
15                 set_pmd(pmd, __pmd(_PAGE_TABLE + __pa(pte)))
16
17 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
18                                 struct page *pte)
19 {
20         set_pmd(pmd, __pmd(_PAGE_TABLE + page_to_phys(pte)));
21 }
22
23 /*
24  * Allocate and free page tables.
25  */
26 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
27 {
28         unsigned int pgd_size = (USER_PTRS_PER_PGD * sizeof(pgd_t));
29         pgd_t *pgd = (pgd_t *)kmalloc(pgd_size, GFP_KERNEL);
30
31         if (pgd)
32                 memset(pgd, 0, pgd_size);
33
34         return pgd;
35 }
36
37 static inline void pgd_free(pgd_t *pgd)
38 {
39         kfree(pgd);
40 }
41
42 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
43                                           unsigned long address)
44 {
45         pte_t *pte;
46
47         pte = (pte_t *) __get_free_page(GFP_KERNEL | __GFP_REPEAT);
48         if (pte)
49                 clear_page(pte);
50
51         return pte;
52 }
53
54 static inline struct page *pte_alloc_one(struct mm_struct *mm,
55                                          unsigned long address)
56 {
57         struct page *pte;
58
59         pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT, 0);
60         if (pte)
61                 clear_page(page_address(pte));
62
63         return pte;
64 }
65
66 static inline void pte_free_kernel(pte_t *pte)
67 {
68         free_page((unsigned long)pte);
69 }
70
71 static inline void pte_free(struct page *pte)
72 {
73         __free_page(pte);
74 }
75
76 #define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
77
78 /*
79  * allocating and freeing a pmd is trivial: the 1-entry pmd is
80  * inside the pgd, so has no extra memory associated with it.
81  */
82
83 #define pmd_alloc_one(mm, addr)         ({ BUG(); ((pmd_t *)2); })
84 #define pmd_free(x)                     do { } while (0)
85 #define __pmd_free_tlb(tlb,x)           do { } while (0)
86 #define pgd_populate(mm, pmd, pte)      BUG()
87
88 #if defined(CONFIG_CPU_SH4)
89 #define PG_mapped       PG_arch_1
90
91 /*
92  * For SH-4, we have our own implementation for ptep_get_and_clear
93  */
94 static inline pte_t ptep_get_and_clear(pte_t *ptep)
95 {
96         pte_t pte = *ptep;
97
98         pte_clear(ptep);
99         if (!pte_not_present(pte)) {
100                 unsigned long pfn = pte_pfn(pte);
101                 if (pfn_valid(pfn)) {
102                         struct page *page = pfn_to_page(pfn);
103                         struct address_space *mapping = page_mapping(page);
104                         if (!mapping || !mapping_writably_mapped(mapping))
105                                 __clear_bit(PG_mapped, &page->flags);
106                 }
107         }
108         return pte;
109 }
110 #else
111 static inline pte_t ptep_get_and_clear(pte_t *ptep)
112 {
113         pte_t pte = *ptep;
114         pte_clear(ptep);
115         return pte;
116 }
117 #endif
118
119 /*
120  * Following functions are same as generic ones.
121  */
122 static inline int ptep_test_and_clear_young(pte_t *ptep)
123 {
124         pte_t pte = *ptep;
125         if (!pte_young(pte))
126                 return 0;
127         set_pte(ptep, pte_mkold(pte));
128         return 1;
129 }
130
131 static inline int ptep_test_and_clear_dirty(pte_t *ptep)
132 {
133         pte_t pte = *ptep;
134         if (!pte_dirty(pte))
135                 return 0;
136         set_pte(ptep, pte_mkclean(pte));
137         return 1;
138 }
139
140 static inline void ptep_set_wrprotect(pte_t *ptep)
141 {
142         pte_t old_pte = *ptep;
143         set_pte(ptep, pte_wrprotect(old_pte));
144 }
145
146 static inline void ptep_mkdirty(pte_t *ptep)
147 {
148         pte_t old_pte = *ptep;
149         set_pte(ptep, pte_mkdirty(old_pte));
150 }
151
152 #define check_pgt_cache()       do { } while (0)
153
154 #endif /* __ASM_SH_PGALLOC_H */