patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / include / asm-generic / pgtable.h
1 #ifndef _ASM_GENERIC_PGTABLE_H
2 #define _ASM_GENERIC_PGTABLE_H
3
4 #ifndef __HAVE_ARCH_PTEP_ESTABLISH
5 /*
6  * Establish a new mapping:
7  *  - flush the old one
8  *  - update the page tables
9  *  - inform the TLB about the new one
10  *
11  * We hold the mm semaphore for reading and vma->vm_mm->page_table_lock.
12  *
13  * Note: the old pte is known to not be writable, so we don't need to
14  * worry about dirty bits etc getting lost.
15  */
16 #define ptep_establish(__vma, __address, __ptep, __entry)               \
17 do {                                                                    \
18         set_pte(__ptep, __entry);                                       \
19         flush_tlb_page(__vma, __address);                               \
20 } while (0)
21 #endif
22
23 #ifndef __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
24 /*
25  * Largely same as above, but only sets the access flags (dirty,
26  * accessed, and writable). Furthermore, we know it always gets set
27  * to a "more permissive" setting, which allows most architectures
28  * to optimize this.
29  */
30 #define ptep_set_access_flags(__vma, __address, __ptep, __entry, __dirty) \
31 do {                                                                      \
32         set_pte(__ptep, __entry);                                         \
33         flush_tlb_page(__vma, __address);                                 \
34 } while (0)
35 #endif
36
37 #ifndef __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
38 static inline int ptep_test_and_clear_young(pte_t *ptep)
39 {
40         pte_t pte = *ptep;
41         if (!pte_young(pte))
42                 return 0;
43         set_pte(ptep, pte_mkold(pte));
44         return 1;
45 }
46 #endif
47
48 #ifndef __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH
49 #define ptep_clear_flush_young(__vma, __address, __ptep)                \
50 ({                                                                      \
51         int __young = ptep_test_and_clear_young(__ptep);                \
52         if (__young)                                                    \
53                 flush_tlb_page(__vma, __address);                       \
54         __young;                                                        \
55 })
56 #endif
57
58 #ifndef __HAVE_ARCH_PTEP_TEST_AND_CLEAR_DIRTY
59 static inline int ptep_test_and_clear_dirty(pte_t *ptep)
60 {
61         pte_t pte = *ptep;
62         if (!pte_dirty(pte))
63                 return 0;
64         set_pte(ptep, pte_mkclean(pte));
65         return 1;
66 }
67 #endif
68
69 #ifndef __HAVE_ARCH_PTEP_CLEAR_DIRTY_FLUSH
70 #define ptep_clear_flush_dirty(__vma, __address, __ptep)                \
71 ({                                                                      \
72         int __dirty = ptep_test_and_clear_dirty(__ptep);                \
73         if (__dirty)                                                    \
74                 flush_tlb_page(__vma, __address);                       \
75         __dirty;                                                        \
76 })
77 #endif
78
79 #ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR
80 static inline pte_t ptep_get_and_clear(pte_t *ptep)
81 {
82         pte_t pte = *ptep;
83         pte_clear(ptep);
84         return pte;
85 }
86 #endif
87
88 #ifndef __HAVE_ARCH_PTEP_CLEAR_FLUSH
89 #define ptep_clear_flush(__vma, __address, __ptep)                      \
90 ({                                                                      \
91         pte_t __pte = ptep_get_and_clear(__ptep);                       \
92         flush_tlb_page(__vma, __address);                               \
93         __pte;                                                          \
94 })
95 #endif
96
97 #ifndef __HAVE_ARCH_PTEP_SET_WRPROTECT
98 static inline void ptep_set_wrprotect(pte_t *ptep)
99 {
100         pte_t old_pte = *ptep;
101         set_pte(ptep, pte_wrprotect(old_pte));
102 }
103 #endif
104
105 #ifndef __HAVE_ARCH_PTEP_MKDIRTY
106 static inline void ptep_mkdirty(pte_t *ptep)
107 {
108         pte_t old_pte = *ptep;
109         set_pte(ptep, pte_mkdirty(old_pte));
110 }
111 #endif
112
113 #ifndef __HAVE_ARCH_PTE_SAME
114 #define pte_same(A,B)   (pte_val(A) == pte_val(B))
115 #endif
116
117 #ifndef __HAVE_ARCH_PAGE_TEST_AND_CLEAR_DIRTY
118 #define page_test_and_clear_dirty(page) (0)
119 #endif
120
121 #ifndef __HAVE_ARCH_PAGE_TEST_AND_CLEAR_YOUNG
122 #define page_test_and_clear_young(page) (0)
123 #endif
124
125 #endif /* _ASM_GENERIC_PGTABLE_H */