Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / include / asm-blackfin / mmu_context.h
blob0709748c82f0af9544d81e0740794264d01532f2
1 /*
2 * File: include/asm-blackfin/mmu_context.h
3 * Based on:
4 * Author:
6 * Created:
7 * Description:
9 * Modified:
10 * Copyright 2004-2006 Analog Devices Inc.
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #ifndef __BLACKFIN_MMU_CONTEXT_H__
31 #define __BLACKFIN_MMU_CONTEXT_H__
33 #include <linux/gfp.h>
34 #include <linux/sched.h>
35 #include <asm/setup.h>
36 #include <asm/page.h>
37 #include <asm/pgalloc.h>
38 #include <asm/cplbinit.h>
40 extern void *current_l1_stack_save;
41 extern int nr_l1stack_tasks;
42 extern void *l1_stack_base;
43 extern unsigned long l1_stack_len;
45 extern int l1sram_free(const void*);
46 extern void *l1sram_alloc_max(void*);
48 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
52 /* Called when creating a new context during fork() or execve(). */
53 static inline int
54 init_new_context(struct task_struct *tsk, struct mm_struct *mm)
56 #ifdef CONFIG_MPU
57 unsigned long p = __get_free_pages(GFP_KERNEL, page_mask_order);
58 mm->context.page_rwx_mask = (unsigned long *)p;
59 memset(mm->context.page_rwx_mask, 0,
60 page_mask_nelts * 3 * sizeof(long));
61 #endif
62 return 0;
65 static inline void free_l1stack(void)
67 nr_l1stack_tasks--;
68 if (nr_l1stack_tasks == 0)
69 l1sram_free(l1_stack_base);
71 static inline void destroy_context(struct mm_struct *mm)
73 struct sram_list_struct *tmp;
75 if (current_l1_stack_save == mm->context.l1_stack_save)
76 <<<<<<< HEAD:include/asm-blackfin/mmu_context.h
77 current_l1_stack_save = 0;
78 =======
79 current_l1_stack_save = NULL;
80 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:include/asm-blackfin/mmu_context.h
81 if (mm->context.l1_stack_save)
82 free_l1stack();
84 while ((tmp = mm->context.sram_list)) {
85 mm->context.sram_list = tmp->next;
86 sram_free(tmp->addr);
87 kfree(tmp);
89 #ifdef CONFIG_MPU
90 if (current_rwx_mask == mm->context.page_rwx_mask)
91 current_rwx_mask = NULL;
92 free_pages((unsigned long)mm->context.page_rwx_mask, page_mask_order);
93 #endif
96 static inline unsigned long
97 alloc_l1stack(unsigned long length, unsigned long *stack_base)
99 if (nr_l1stack_tasks == 0) {
100 l1_stack_base = l1sram_alloc_max(&l1_stack_len);
101 if (!l1_stack_base)
102 return 0;
105 if (l1_stack_len < length) {
106 if (nr_l1stack_tasks == 0)
107 l1sram_free(l1_stack_base);
108 return 0;
110 *stack_base = (unsigned long)l1_stack_base;
111 nr_l1stack_tasks++;
112 return l1_stack_len;
115 static inline int
116 activate_l1stack(struct mm_struct *mm, unsigned long sp_base)
118 if (current_l1_stack_save)
119 memcpy(current_l1_stack_save, l1_stack_base, l1_stack_len);
120 mm->context.l1_stack_save = current_l1_stack_save = (void*)sp_base;
121 memcpy(l1_stack_base, current_l1_stack_save, l1_stack_len);
122 return 1;
125 #define deactivate_mm(tsk,mm) do { } while (0)
127 #define activate_mm(prev, next) switch_mm(prev, next, NULL)
129 static inline void switch_mm(struct mm_struct *prev_mm, struct mm_struct *next_mm,
130 struct task_struct *tsk)
132 if (prev_mm == next_mm)
133 return;
134 #ifdef CONFIG_MPU
135 if (prev_mm->context.page_rwx_mask == current_rwx_mask) {
136 flush_switched_cplbs();
137 set_mask_dcplbs(next_mm->context.page_rwx_mask);
139 #endif
141 /* L1 stack switching. */
142 if (!next_mm->context.l1_stack_save)
143 return;
144 if (next_mm->context.l1_stack_save == current_l1_stack_save)
145 return;
146 if (current_l1_stack_save) {
147 memcpy(current_l1_stack_save, l1_stack_base, l1_stack_len);
149 current_l1_stack_save = next_mm->context.l1_stack_save;
150 memcpy(l1_stack_base, current_l1_stack_save, l1_stack_len);
153 #ifdef CONFIG_MPU
154 static inline void protect_page(struct mm_struct *mm, unsigned long addr,
155 unsigned long flags)
157 unsigned long *mask = mm->context.page_rwx_mask;
158 unsigned long page = addr >> 12;
159 unsigned long idx = page >> 5;
160 unsigned long bit = 1 << (page & 31);
162 if (flags & VM_MAYREAD)
163 mask[idx] |= bit;
164 else
165 mask[idx] &= ~bit;
166 mask += page_mask_nelts;
167 if (flags & VM_MAYWRITE)
168 mask[idx] |= bit;
169 else
170 mask[idx] &= ~bit;
171 mask += page_mask_nelts;
172 if (flags & VM_MAYEXEC)
173 mask[idx] |= bit;
174 else
175 mask[idx] &= ~bit;
178 static inline void update_protections(struct mm_struct *mm)
180 flush_switched_cplbs();
181 set_mask_dcplbs(mm->context.page_rwx_mask);
183 #endif
185 #endif