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