Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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" |
Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 9 | #include "linux/config.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Bodo Stroesser | 07bf731 | 2005-09-03 15:57:50 -0700 | [diff] [blame^] | 21 | static int do_ops(union mm_context *mmu, struct host_vm_op *ops, int last, |
| 22 | int finished, void **flush) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | { |
| 24 | struct host_vm_op *op; |
Bodo Stroesser | 07bf731 | 2005-09-03 15:57:50 -0700 | [diff] [blame^] | 25 | int i, ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Bodo Stroesser | 07bf731 | 2005-09-03 15:57:50 -0700 | [diff] [blame^] | 27 | for(i = 0; i <= last && !ret; i++){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | op = &ops[i]; |
| 29 | switch(op->type){ |
| 30 | case MMAP: |
Bodo Stroesser | 07bf731 | 2005-09-03 15:57:50 -0700 | [diff] [blame^] | 31 | ret = map(&mmu->skas.id, op->u.mmap.addr, |
| 32 | op->u.mmap.len, op->u.mmap.r, op->u.mmap.w, |
| 33 | op->u.mmap.x, op->u.mmap.fd, |
| 34 | op->u.mmap.offset, finished, flush); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | break; |
| 36 | case MUNMAP: |
Bodo Stroesser | 07bf731 | 2005-09-03 15:57:50 -0700 | [diff] [blame^] | 37 | ret = unmap(&mmu->skas.id, |
| 38 | (void *) op->u.munmap.addr, |
| 39 | op->u.munmap.len, finished, flush); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | break; |
| 41 | case MPROTECT: |
Bodo Stroesser | 07bf731 | 2005-09-03 15:57:50 -0700 | [diff] [blame^] | 42 | ret = protect(&mmu->skas.id, op->u.mprotect.addr, |
| 43 | op->u.mprotect.len, op->u.mprotect.r, |
| 44 | op->u.mprotect.w, op->u.mprotect.x, |
| 45 | finished, flush); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | break; |
| 47 | default: |
| 48 | printk("Unknown op type %d in do_ops\n", op->type); |
| 49 | break; |
| 50 | } |
| 51 | } |
Jeff Dike | c560049 | 2005-09-03 15:57:36 -0700 | [diff] [blame] | 52 | |
Bodo Stroesser | 07bf731 | 2005-09-03 15:57:50 -0700 | [diff] [blame^] | 53 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 56 | extern int proc_mm; |
| 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | static void fix_range(struct mm_struct *mm, unsigned long start_addr, |
| 59 | unsigned long end_addr, int force) |
| 60 | { |
Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 61 | if(!proc_mm && (end_addr > CONFIG_STUB_START)) |
| 62 | end_addr = CONFIG_STUB_START; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 64 | fix_range_common(mm, start_addr, end_addr, force, do_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void __flush_tlb_one_skas(unsigned long addr) |
| 68 | { |
| 69 | flush_tlb_kernel_range_common(addr, addr + PAGE_SIZE); |
| 70 | } |
| 71 | |
| 72 | void flush_tlb_range_skas(struct vm_area_struct *vma, unsigned long start, |
| 73 | unsigned long end) |
| 74 | { |
| 75 | if(vma->vm_mm == NULL) |
| 76 | flush_tlb_kernel_range_common(start, end); |
| 77 | else fix_range(vma->vm_mm, start, end, 0); |
| 78 | } |
| 79 | |
| 80 | void flush_tlb_mm_skas(struct mm_struct *mm) |
| 81 | { |
Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 82 | unsigned long end; |
| 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | /* Don't bother flushing if this address space is about to be |
| 85 | * destroyed. |
| 86 | */ |
| 87 | if(atomic_read(&mm->mm_users) == 0) |
| 88 | return; |
| 89 | |
Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 90 | end = proc_mm ? task_size : CONFIG_STUB_START; |
| 91 | fix_range(mm, 0, end, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | void force_flush_all_skas(void) |
| 95 | { |
Jeff Dike | d67b569 | 2005-07-07 17:56:49 -0700 | [diff] [blame] | 96 | unsigned long end = proc_mm ? task_size : CONFIG_STUB_START; |
| 97 | fix_range(current->mm, 0, end, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |