RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / arch / um / kernel / tt / tlb.c
blob7caa24fe05dfaf376b8cbf77a22cf1acdac10ce5
1 /*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Copyright 2003 PathScale, Inc.
4 * Licensed under the GPL
5 */
7 #include "linux/stddef.h"
8 #include "linux/kernel.h"
9 #include "linux/sched.h"
10 #include "linux/mm.h"
11 #include "asm/page.h"
12 #include "asm/pgtable.h"
13 #include "asm/uaccess.h"
14 #include "asm/tlbflush.h"
15 #include "mem_user.h"
16 #include "os.h"
17 #include "tlb.h"
19 static int do_ops(union mm_context *mmu, struct host_vm_op *ops, int last,
20 int finished, void **flush)
22 struct host_vm_op *op;
23 int i, ret=0;
25 for(i = 0; i <= last && !ret; i++){
26 op = &ops[i];
27 switch(op->type){
28 case MMAP:
29 ret = os_map_memory((void *) op->u.mmap.addr,
30 op->u.mmap.fd, op->u.mmap.offset,
31 op->u.mmap.len, op->u.mmap.r,
32 op->u.mmap.w, op->u.mmap.x);
33 break;
34 case MUNMAP:
35 ret = os_unmap_memory((void *) op->u.munmap.addr,
36 op->u.munmap.len);
37 break;
38 case MPROTECT:
39 ret = protect_memory(op->u.mprotect.addr,
40 op->u.munmap.len,
41 op->u.mprotect.r,
42 op->u.mprotect.w,
43 op->u.mprotect.x, 1);
44 protect_memory(op->u.mprotect.addr, op->u.munmap.len,
45 op->u.mprotect.r, op->u.mprotect.w,
46 op->u.mprotect.x, 1);
47 break;
48 default:
49 printk("Unknown op type %d in do_ops\n", op->type);
50 break;
54 return ret;
57 static void fix_range(struct mm_struct *mm, unsigned long start_addr,
58 unsigned long end_addr, int force)
60 if((current->thread.mode.tt.extern_pid != -1) &&
61 (current->thread.mode.tt.extern_pid != os_getpid()))
62 panic("fix_range fixing wrong address space, current = 0x%p",
63 current);
65 fix_range_common(mm, start_addr, end_addr, force, do_ops);
68 atomic_t vmchange_seq = ATOMIC_INIT(1);
70 void flush_tlb_kernel_range_tt(unsigned long start, unsigned long end)
72 if(flush_tlb_kernel_range_common(start, end))
73 atomic_inc(&vmchange_seq);
76 void flush_tlb_kernel_vm_tt(void)
78 flush_tlb_kernel_range(start_vm, end_vm);
81 void __flush_tlb_one_tt(unsigned long addr)
83 flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
86 void flush_tlb_range_tt(struct vm_area_struct *vma, unsigned long start,
87 unsigned long end)
89 if(vma->vm_mm != current->mm) return;
91 /* Assumes that the range start ... end is entirely within
92 * either process memory or kernel vm
94 if((start >= start_vm) && (start < end_vm)){
95 if(flush_tlb_kernel_range_common(start, end))
96 atomic_inc(&vmchange_seq);
98 else fix_range(vma->vm_mm, start, end, 0);
101 void flush_tlb_mm_tt(struct mm_struct *mm)
103 unsigned long seq;
105 if(mm != current->mm) return;
107 fix_range(mm, 0, STACK_TOP, 0);
109 seq = atomic_read(&vmchange_seq);
110 if(current->thread.mode.tt.vm_seq == seq)
111 return;
112 current->thread.mode.tt.vm_seq = seq;
113 flush_tlb_kernel_range_common(start_vm, end_vm);
116 void force_flush_all_tt(void)
118 fix_range(current->mm, 0, STACK_TOP, 1);
119 flush_tlb_kernel_range_common(start_vm, end_vm);