tlb.c 2.3 KB

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