Merge master.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-for-linus-2.6
[sfrench/cifs-2.6.git] / arch / um / kernel / skas / tlb.c
1 /* 
2  * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3  * Copyright 2003 PathScale, Inc.
4  * Licensed under the GPL
5  */
6
7 #include "linux/stddef.h"
8 #include "linux/sched.h"
9 #include "linux/config.h"
10 #include "linux/mm.h"
11 #include "asm/page.h"
12 #include "asm/pgtable.h"
13 #include "asm/mmu.h"
14 #include "user_util.h"
15 #include "mem_user.h"
16 #include "mem.h"
17 #include "skas.h"
18 #include "os.h"
19 #include "tlb.h"
20
21 static void do_ops(union mm_context *mmu, struct host_vm_op *ops, int last)
22 {
23         struct host_vm_op *op;
24         int i;
25
26         for(i = 0; i <= last; i++){
27                 op = &ops[i];
28                 switch(op->type){
29                 case MMAP:
30                         map(&mmu->skas.id, op->u.mmap.addr, op->u.mmap.len,
31                             op->u.mmap.r, op->u.mmap.w, op->u.mmap.x,
32                             op->u.mmap.fd, op->u.mmap.offset);
33                         break;
34                 case MUNMAP:
35                         unmap(&mmu->skas.id, (void *) op->u.munmap.addr,
36                               op->u.munmap.len);
37                         break;
38                 case MPROTECT:
39                         protect(&mmu->skas.id, op->u.mprotect.addr,
40                                 op->u.mprotect.len, op->u.mprotect.r,
41                                 op->u.mprotect.w, op->u.mprotect.x);
42                         break;
43                 default:
44                         printk("Unknown op type %d in do_ops\n", op->type);
45                         break;
46                 }
47         }
48 }
49
50 extern int proc_mm;
51
52 static void fix_range(struct mm_struct *mm, unsigned long start_addr,
53                       unsigned long end_addr, int force)
54 {
55         if(!proc_mm && (end_addr > CONFIG_STUB_START))
56                 end_addr = CONFIG_STUB_START;
57
58         fix_range_common(mm, start_addr, end_addr, force, do_ops);
59 }
60
61 void __flush_tlb_one_skas(unsigned long addr)
62 {
63         flush_tlb_kernel_range_common(addr, addr + PAGE_SIZE);
64 }
65
66 void flush_tlb_range_skas(struct vm_area_struct *vma, unsigned long start, 
67                      unsigned long end)
68 {
69         if(vma->vm_mm == NULL)
70                 flush_tlb_kernel_range_common(start, end);
71         else fix_range(vma->vm_mm, start, end, 0);
72 }
73
74 void flush_tlb_mm_skas(struct mm_struct *mm)
75 {
76         unsigned long end;
77
78         /* Don't bother flushing if this address space is about to be
79          * destroyed.
80          */
81         if(atomic_read(&mm->mm_users) == 0)
82                 return;
83
84         end = proc_mm ? task_size : CONFIG_STUB_START;
85         fix_range(mm, 0, end, 0);
86 }
87
88 void force_flush_all_skas(void)
89 {
90         unsigned long end = proc_mm ? task_size : CONFIG_STUB_START;
91         fix_range(current->mm, 0, end, 1);
92 }