tlbflush.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef _ASM_TILE_TLBFLUSH_H
  15. #define _ASM_TILE_TLBFLUSH_H
  16. #include <linux/mm.h>
  17. #include <linux/sched.h>
  18. #include <linux/smp.h>
  19. #include <asm/cacheflush.h>
  20. #include <asm/page.h>
  21. #include <hv/hypervisor.h>
  22. /*
  23. * Rather than associating each mm with its own ASID, we just use
  24. * ASIDs to allow us to lazily flush the TLB when we switch mms.
  25. * This way we only have to do an actual TLB flush on mm switch
  26. * every time we wrap ASIDs, not every single time we switch.
  27. *
  28. * FIXME: We might improve performance by keeping ASIDs around
  29. * properly, though since the hypervisor direct-maps VAs to TSB
  30. * entries, we're likely to have lost at least the executable page
  31. * mappings by the time we switch back to the original mm.
  32. */
  33. DECLARE_PER_CPU(int, current_asid);
  34. /* The hypervisor tells us what ASIDs are available to us. */
  35. extern int min_asid, max_asid;
  36. /* Pass as vma pointer for non-executable mapping, if no vma available. */
  37. #define FLUSH_NONEXEC ((struct vm_area_struct *)-1UL)
  38. /* Flush a single user page on this cpu. */
  39. static inline void local_flush_tlb_page(struct vm_area_struct *vma,
  40. unsigned long addr,
  41. unsigned long page_size)
  42. {
  43. int rc = hv_flush_page(addr, page_size);
  44. if (rc < 0)
  45. panic("hv_flush_page(%#lx,%#lx) failed: %d",
  46. addr, page_size, rc);
  47. if (!vma || (vma != FLUSH_NONEXEC && (vma->vm_flags & VM_EXEC)))
  48. __flush_icache();
  49. }
  50. /* Flush range of user pages on this cpu. */
  51. static inline void local_flush_tlb_pages(struct vm_area_struct *vma,
  52. unsigned long addr,
  53. unsigned long page_size,
  54. unsigned long len)
  55. {
  56. int rc = hv_flush_pages(addr, page_size, len);
  57. if (rc < 0)
  58. panic("hv_flush_pages(%#lx,%#lx,%#lx) failed: %d",
  59. addr, page_size, len, rc);
  60. if (!vma || (vma != FLUSH_NONEXEC && (vma->vm_flags & VM_EXEC)))
  61. __flush_icache();
  62. }
  63. /* Flush all user pages on this cpu. */
  64. static inline void local_flush_tlb(void)
  65. {
  66. int rc = hv_flush_all(1); /* preserve global mappings */
  67. if (rc < 0)
  68. panic("hv_flush_all(1) failed: %d", rc);
  69. __flush_icache();
  70. }
  71. /*
  72. * Global pages have to be flushed a bit differently. Not a real
  73. * performance problem because this does not happen often.
  74. */
  75. static inline void local_flush_tlb_all(void)
  76. {
  77. int i;
  78. for (i = 0; ; ++i) {
  79. HV_VirtAddrRange r = hv_inquire_virtual(i);
  80. if (r.size == 0)
  81. break;
  82. local_flush_tlb_pages(NULL, r.start, PAGE_SIZE, r.size);
  83. local_flush_tlb_pages(NULL, r.start, HPAGE_SIZE, r.size);
  84. }
  85. }
  86. /*
  87. * TLB flushing:
  88. *
  89. * - flush_tlb() flushes the current mm struct TLBs
  90. * - flush_tlb_all() flushes all processes TLBs
  91. * - flush_tlb_mm(mm) flushes the specified mm context TLB's
  92. * - flush_tlb_page(vma, vmaddr) flushes one page
  93. * - flush_tlb_range(vma, start, end) flushes a range of pages
  94. * - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
  95. * - flush_tlb_others(cpumask, mm, va) flushes TLBs on other cpus
  96. *
  97. * Here (as in vm_area_struct), "end" means the first byte after
  98. * our end address.
  99. */
  100. extern void flush_tlb_all(void);
  101. extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
  102. extern void flush_tlb_current_task(void);
  103. extern void flush_tlb_mm(struct mm_struct *);
  104. extern void flush_tlb_page(struct vm_area_struct *, unsigned long);
  105. extern void flush_tlb_page_mm(struct vm_area_struct *,
  106. struct mm_struct *, unsigned long);
  107. extern void flush_tlb_range(struct vm_area_struct *,
  108. unsigned long start, unsigned long end);
  109. #define flush_tlb() flush_tlb_current_task()
  110. #endif /* _ASM_TILE_TLBFLUSH_H */