VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / include / asm-parisc / cacheflush.h
1 #ifndef _PARISC_CACHEFLUSH_H
2 #define _PARISC_CACHEFLUSH_H
3
4 #include <linux/config.h>
5 #include <linux/mm.h>
6
7 /* The usual comment is "Caches aren't brain-dead on the <architecture>".
8  * Unfortunately, that doesn't apply to PA-RISC. */
9
10 /* Cache flush operations */
11
12 #ifdef CONFIG_SMP
13 #define flush_cache_mm(mm) flush_cache_all()
14 #else
15 #define flush_cache_mm(mm) flush_cache_all_local()
16 #endif
17
18 #define flush_kernel_dcache_range(start,size) \
19         flush_kernel_dcache_range_asm((start), (start)+(size));
20
21 extern void flush_cache_all_local(void);
22
23 static inline void cacheflush_h_tmp_function(void *dummy)
24 {
25         flush_cache_all_local();
26 }
27
28 static inline void flush_cache_all(void)
29 {
30         on_each_cpu(cacheflush_h_tmp_function, NULL, 1, 1);
31 }
32
33 #define flush_cache_vmap(start, end)            flush_cache_all()
34 #define flush_cache_vunmap(start, end)          flush_cache_all()
35
36 /* The following value needs to be tuned and probably scaled with the
37  * cache size.
38  */
39
40 #define FLUSH_THRESHOLD 0x80000
41
42 static inline void
43 flush_user_dcache_range(unsigned long start, unsigned long end)
44 {
45 #ifdef CONFIG_SMP
46         flush_user_dcache_range_asm(start,end);
47 #else
48         if ((end - start) < FLUSH_THRESHOLD)
49                 flush_user_dcache_range_asm(start,end);
50         else
51                 flush_data_cache();
52 #endif
53 }
54
55 static inline void
56 flush_user_icache_range(unsigned long start, unsigned long end)
57 {
58 #ifdef CONFIG_SMP
59         flush_user_icache_range_asm(start,end);
60 #else
61         if ((end - start) < FLUSH_THRESHOLD)
62                 flush_user_icache_range_asm(start,end);
63         else
64                 flush_instruction_cache();
65 #endif
66 }
67
68 extern void flush_dcache_page(struct page *page);
69
70 #define flush_dcache_mmap_lock(mapping) \
71         spin_lock_irq(&(mapping)->tree_lock)
72 #define flush_dcache_mmap_unlock(mapping) \
73         spin_unlock_irq(&(mapping)->tree_lock)
74
75 #define flush_icache_page(vma,page)     do { flush_kernel_dcache_page(page_address(page)); flush_kernel_icache_page(page_address(page)); } while (0)
76
77 #define flush_icache_range(s,e)         do { flush_kernel_dcache_range_asm(s,e); flush_kernel_icache_range_asm(s,e); } while (0)
78
79 #define copy_to_user_page(vma, page, vaddr, dst, src, len) \
80 do { memcpy(dst, src, len); \
81      flush_kernel_dcache_range_asm((unsigned long)dst, (unsigned long)dst + len); \
82 } while (0)
83 #define copy_from_user_page(vma, page, vaddr, dst, src, len) \
84         memcpy(dst, src, len)
85
86 static inline void flush_cache_range(struct vm_area_struct *vma,
87                 unsigned long start, unsigned long end)
88 {
89         int sr3;
90
91         if (!vma->vm_mm->context) {
92                 BUG();
93                 return;
94         }
95
96         sr3 = mfsp(3);
97         if (vma->vm_mm->context == sr3) {
98                 flush_user_dcache_range(start,end);
99                 flush_user_icache_range(start,end);
100         } else {
101                 flush_cache_all();
102         }
103 }
104
105 /* Simple function to work out if we have an existing address translation
106  * for a user space vma. */
107 static inline pte_t *__translation_exists(struct mm_struct *mm,
108                                           unsigned long addr)
109 {
110         pgd_t *pgd = pgd_offset(mm, addr);
111         pmd_t *pmd;
112         pte_t *pte;
113
114         if(pgd_none(*pgd))
115                 return NULL;
116
117         pmd = pmd_offset(pgd, addr);
118         if(pmd_none(*pmd) || pmd_bad(*pmd))
119                 return NULL;
120
121         pte = pte_offset_map(pmd, addr);
122
123         /* The PA flush mappings show up as pte_none, but they're
124          * valid none the less */
125         if(pte_none(*pte) && ((pte_val(*pte) & _PAGE_FLUSH) == 0))
126                 return NULL;
127         return pte;
128 }
129 #define translation_exists(vma, addr)   __translation_exists((vma)->vm_mm, addr)
130
131
132 /* Private function to flush a page from the cache of a non-current
133  * process.  cr25 contains the Page Directory of the current user
134  * process; we're going to hijack both it and the user space %sr3 to
135  * temporarily make the non-current process current.  We have to do
136  * this because cache flushing may cause a non-access tlb miss which
137  * the handlers have to fill in from the pgd of the non-current
138  * process. */
139 static inline void
140 flush_user_cache_page_non_current(struct vm_area_struct *vma,
141                                   unsigned long vmaddr)
142 {
143         /* save the current process space and pgd */
144         unsigned long space = mfsp(3), pgd = mfctl(25);
145
146         /* we don't mind taking interrups since they may not
147          * do anything with user space, but we can't
148          * be preempted here */
149         preempt_disable();
150
151         /* make us current */
152         mtctl(__pa(vma->vm_mm->pgd), 25);
153         mtsp(vma->vm_mm->context, 3);
154
155         flush_user_dcache_page(vmaddr);
156         if(vma->vm_flags & VM_EXEC)
157                 flush_user_icache_page(vmaddr);
158
159         /* put the old current process back */
160         mtsp(space, 3);
161         mtctl(pgd, 25);
162         preempt_enable();
163 }
164
165 static inline void
166 __flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr)
167 {
168         if (likely(vma->vm_mm->context == mfsp(3))) {
169                 flush_user_dcache_page(vmaddr);
170                 if (vma->vm_flags & VM_EXEC)
171                         flush_user_icache_page(vmaddr);
172         } else {
173                 flush_user_cache_page_non_current(vma, vmaddr);
174         }
175 }
176
177 static inline void
178 flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr)
179 {
180         BUG_ON(!vma->vm_mm->context);
181
182         if(likely(translation_exists(vma, vmaddr)))
183                 __flush_cache_page(vma, vmaddr);
184
185 }
186 #endif
187