tlb.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
  3. * Copyright 2003 PathScale, Inc.
  4. * Licensed under the GPL
  5. */
  6. #include "linux/stddef.h"
  7. #include "linux/sched.h"
  8. #include "linux/config.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. static int do_ops(union mm_context *mmu, struct host_vm_op *ops, int last,
  20. int finished, void **flush)
  21. {
  22. struct host_vm_op *op;
  23. int i, ret = 0;
  24. for(i = 0; i <= last && !ret; i++){
  25. op = &ops[i];
  26. switch(op->type){
  27. case MMAP:
  28. ret = map(&mmu->skas.id, op->u.mmap.addr,
  29. op->u.mmap.len, op->u.mmap.r, op->u.mmap.w,
  30. op->u.mmap.x, op->u.mmap.fd,
  31. op->u.mmap.offset, finished, flush);
  32. break;
  33. case MUNMAP:
  34. ret = unmap(&mmu->skas.id,
  35. (void *) op->u.munmap.addr,
  36. op->u.munmap.len, finished, flush);
  37. break;
  38. case MPROTECT:
  39. ret = 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. finished, flush);
  43. break;
  44. default:
  45. printk("Unknown op type %d in do_ops\n", op->type);
  46. break;
  47. }
  48. }
  49. return ret;
  50. }
  51. extern int proc_mm;
  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. fix_range_common(mm, start_addr, end_addr, force, do_ops);
  58. }
  59. void __flush_tlb_one_skas(unsigned long addr)
  60. {
  61. flush_tlb_kernel_range_common(addr, addr + PAGE_SIZE);
  62. }
  63. void flush_tlb_range_skas(struct vm_area_struct *vma, unsigned long start,
  64. unsigned long end)
  65. {
  66. if(vma->vm_mm == NULL)
  67. flush_tlb_kernel_range_common(start, end);
  68. else fix_range(vma->vm_mm, start, end, 0);
  69. }
  70. void flush_tlb_mm_skas(struct mm_struct *mm)
  71. {
  72. unsigned long end;
  73. /* Don't bother flushing if this address space is about to be
  74. * destroyed.
  75. */
  76. if(atomic_read(&mm->mm_users) == 0)
  77. return;
  78. end = proc_mm ? task_size : CONFIG_STUB_START;
  79. fix_range(mm, 0, end, 0);
  80. }
  81. void force_flush_all_skas(void)
  82. {
  83. unsigned long end = proc_mm ? task_size : CONFIG_STUB_START;
  84. fix_range(current->mm, 0, end, 1);
  85. }