tlbflush.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. static inline unsigned long hv_page_size(const struct vm_area_struct *vma)
  37. {
  38. return (vma->vm_flags & VM_HUGETLB) ? HPAGE_SIZE : PAGE_SIZE;
  39. }
  40. /* Pass as vma pointer for non-executable mapping, if no vma available. */
  41. #define FLUSH_NONEXEC ((const struct vm_area_struct *)-1UL)
  42. /* Flush a single user page on this cpu. */
  43. static inline void local_flush_tlb_page(const struct vm_area_struct *vma,
  44. unsigned long addr,
  45. unsigned long page_size)
  46. {
  47. int rc = hv_flush_page(addr, page_size);
  48. if (rc < 0)
  49. panic("hv_flush_page(%#lx,%#lx) failed: %d",
  50. addr, page_size, rc);
  51. if (!vma || (vma != FLUSH_NONEXEC && (vma->vm_flags & VM_EXEC)))
  52. __flush_icache();
  53. }
  54. /* Flush range of user pages on this cpu. */
  55. static inline void local_flush_tlb_pages(const struct vm_area_struct *vma,
  56. unsigned long addr,
  57. unsigned long page_size,
  58. unsigned long len)
  59. {
  60. int rc = hv_flush_pages(addr, page_size, len);
  61. if (rc < 0)
  62. panic("hv_flush_pages(%#lx,%#lx,%#lx) failed: %d",
  63. addr, page_size, len, rc);
  64. if (!vma || (vma != FLUSH_NONEXEC && (vma->vm_flags & VM_EXEC)))
  65. __flush_icache();
  66. }
  67. /* Flush all user pages on this cpu. */
  68. static inline void local_flush_tlb(void)
  69. {
  70. int rc = hv_flush_all(1); /* preserve global mappings */
  71. if (rc < 0)
  72. panic("hv_flush_all(1) failed: %d", rc);
  73. __flush_icache();
  74. }
  75. /*
  76. * Global pages have to be flushed a bit differently. Not a real
  77. * performance problem because this does not happen often.
  78. */
  79. static inline void local_flush_tlb_all(void)
  80. {
  81. int i;
  82. for (i = 0; ; ++i) {
  83. HV_VirtAddrRange r = hv_inquire_virtual(i);
  84. if (r.size == 0)
  85. break;
  86. local_flush_tlb_pages(NULL, r.start, PAGE_SIZE, r.size);
  87. local_flush_tlb_pages(NULL, r.start, HPAGE_SIZE, r.size);
  88. }
  89. }
  90. /*
  91. * TLB flushing:
  92. *
  93. * - flush_tlb() flushes the current mm struct TLBs
  94. * - flush_tlb_all() flushes all processes TLBs
  95. * - flush_tlb_mm(mm) flushes the specified mm context TLB's
  96. * - flush_tlb_page(vma, vmaddr) flushes one page
  97. * - flush_tlb_range(vma, start, end) flushes a range of pages
  98. * - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
  99. * - flush_tlb_others(cpumask, mm, va) flushes TLBs on other cpus
  100. *
  101. * Here (as in vm_area_struct), "end" means the first byte after
  102. * our end address.
  103. */
  104. extern void flush_tlb_all(void);
  105. extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
  106. extern void flush_tlb_current_task(void);
  107. extern void flush_tlb_mm(struct mm_struct *);
  108. extern void flush_tlb_page(const struct vm_area_struct *, unsigned long);
  109. extern void flush_tlb_page_mm(const struct vm_area_struct *,
  110. struct mm_struct *, unsigned long);
  111. extern void flush_tlb_range(const struct vm_area_struct *,
  112. unsigned long start, unsigned long end);
  113. #define flush_tlb() flush_tlb_current_task()
  114. #endif /* _ASM_TILE_TLBFLUSH_H */