tlbflush.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * include/asm-xtensa/tlbflush.h
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 2001 - 2005 Tensilica Inc.
  9. */
  10. #ifndef _XTENSA_TLBFLUSH_H
  11. #define _XTENSA_TLBFLUSH_H
  12. #define DEBUG_TLB
  13. #ifdef __KERNEL__
  14. #include <asm/processor.h>
  15. #include <linux/stringify.h>
  16. /* TLB flushing:
  17. *
  18. * - flush_tlb_all() flushes all processes TLB entries
  19. * - flush_tlb_mm(mm) flushes the specified mm context TLB entries
  20. * - flush_tlb_page(mm, vmaddr) flushes a single page
  21. * - flush_tlb_range(mm, start, end) flushes a range of pages
  22. */
  23. extern void flush_tlb_all(void);
  24. extern void flush_tlb_mm(struct mm_struct*);
  25. extern void flush_tlb_page(struct vm_area_struct*,unsigned long);
  26. extern void flush_tlb_range(struct vm_area_struct*,unsigned long,unsigned long);
  27. #define flush_tlb_kernel_range(start,end) flush_tlb_all()
  28. /* This is calld in munmap when we have freed up some page-table pages.
  29. * We don't need to do anything here, there's nothing special about our
  30. * page-table pages.
  31. */
  32. static inline void flush_tlb_pgtables(struct mm_struct *mm,
  33. unsigned long start, unsigned long end)
  34. {
  35. }
  36. /* TLB operations. */
  37. #define ITLB_WAYS_LOG2 XCHAL_ITLB_WAY_BITS
  38. #define DTLB_WAYS_LOG2 XCHAL_DTLB_WAY_BITS
  39. #define ITLB_PROBE_SUCCESS (1 << ITLB_WAYS_LOG2)
  40. #define DTLB_PROBE_SUCCESS (1 << DTLB_WAYS_LOG2)
  41. static inline unsigned long itlb_probe(unsigned long addr)
  42. {
  43. unsigned long tmp;
  44. __asm__ __volatile__("pitlb %0, %1\n\t" : "=a" (tmp) : "a" (addr));
  45. return tmp;
  46. }
  47. static inline unsigned long dtlb_probe(unsigned long addr)
  48. {
  49. unsigned long tmp;
  50. __asm__ __volatile__("pdtlb %0, %1\n\t" : "=a" (tmp) : "a" (addr));
  51. return tmp;
  52. }
  53. static inline void invalidate_itlb_entry (unsigned long probe)
  54. {
  55. __asm__ __volatile__("iitlb %0; isync\n\t" : : "a" (probe));
  56. }
  57. static inline void invalidate_dtlb_entry (unsigned long probe)
  58. {
  59. __asm__ __volatile__("idtlb %0; dsync\n\t" : : "a" (probe));
  60. }
  61. /* Use the .._no_isync functions with caution. Generally, these are
  62. * handy for bulk invalidates followed by a single 'isync'. The
  63. * caller must follow up with an 'isync', which can be relatively
  64. * expensive on some Xtensa implementations.
  65. */
  66. static inline void invalidate_itlb_entry_no_isync (unsigned entry)
  67. {
  68. /* Caller must follow up with 'isync'. */
  69. __asm__ __volatile__ ("iitlb %0\n" : : "a" (entry) );
  70. }
  71. static inline void invalidate_dtlb_entry_no_isync (unsigned entry)
  72. {
  73. /* Caller must follow up with 'isync'. */
  74. __asm__ __volatile__ ("idtlb %0\n" : : "a" (entry) );
  75. }
  76. static inline void set_itlbcfg_register (unsigned long val)
  77. {
  78. __asm__ __volatile__("wsr %0, "__stringify(ITLBCFG)"\n\t" "isync\n\t"
  79. : : "a" (val));
  80. }
  81. static inline void set_dtlbcfg_register (unsigned long val)
  82. {
  83. __asm__ __volatile__("wsr %0, "__stringify(DTLBCFG)"; dsync\n\t"
  84. : : "a" (val));
  85. }
  86. static inline void set_ptevaddr_register (unsigned long val)
  87. {
  88. __asm__ __volatile__(" wsr %0, "__stringify(PTEVADDR)"; isync\n"
  89. : : "a" (val));
  90. }
  91. static inline unsigned long read_ptevaddr_register (void)
  92. {
  93. unsigned long tmp;
  94. __asm__ __volatile__("rsr %0, "__stringify(PTEVADDR)"\n\t" : "=a" (tmp));
  95. return tmp;
  96. }
  97. static inline void write_dtlb_entry (pte_t entry, int way)
  98. {
  99. __asm__ __volatile__("wdtlb %1, %0; dsync\n\t"
  100. : : "r" (way), "r" (entry) );
  101. }
  102. static inline void write_itlb_entry (pte_t entry, int way)
  103. {
  104. __asm__ __volatile__("witlb %1, %0; isync\n\t"
  105. : : "r" (way), "r" (entry) );
  106. }
  107. static inline void invalidate_page_directory (void)
  108. {
  109. invalidate_dtlb_entry (DTLB_WAY_PGTABLE);
  110. }
  111. static inline void invalidate_itlb_mapping (unsigned address)
  112. {
  113. unsigned long tlb_entry;
  114. while ((tlb_entry = itlb_probe (address)) & ITLB_PROBE_SUCCESS)
  115. invalidate_itlb_entry (tlb_entry);
  116. }
  117. static inline void invalidate_dtlb_mapping (unsigned address)
  118. {
  119. unsigned long tlb_entry;
  120. while ((tlb_entry = dtlb_probe (address)) & DTLB_PROBE_SUCCESS)
  121. invalidate_dtlb_entry (tlb_entry);
  122. }
  123. #define check_pgt_cache() do { } while (0)
  124. #ifdef DEBUG_TLB
  125. /* DO NOT USE THESE FUNCTIONS. These instructions aren't part of the Xtensa
  126. * ISA and exist only for test purposes..
  127. * You may find it helpful for MMU debugging, however.
  128. *
  129. * 'at' is the unmodified input register
  130. * 'as' is the output register, as follows (specific to the Linux config):
  131. *
  132. * as[31..12] contain the virtual address
  133. * as[11..08] are meaningless
  134. * as[07..00] contain the asid
  135. */
  136. static inline unsigned long read_dtlb_virtual (int way)
  137. {
  138. unsigned long tmp;
  139. __asm__ __volatile__("rdtlb0 %0, %1\n\t" : "=a" (tmp), "+a" (way));
  140. return tmp;
  141. }
  142. static inline unsigned long read_dtlb_translation (int way)
  143. {
  144. unsigned long tmp;
  145. __asm__ __volatile__("rdtlb1 %0, %1\n\t" : "=a" (tmp), "+a" (way));
  146. return tmp;
  147. }
  148. static inline unsigned long read_itlb_virtual (int way)
  149. {
  150. unsigned long tmp;
  151. __asm__ __volatile__("ritlb0 %0, %1\n\t" : "=a" (tmp), "+a" (way));
  152. return tmp;
  153. }
  154. static inline unsigned long read_itlb_translation (int way)
  155. {
  156. unsigned long tmp;
  157. __asm__ __volatile__("ritlb1 %0, %1\n\t" : "=a" (tmp), "+a" (way));
  158. return tmp;
  159. }
  160. #endif /* DEBUG_TLB */
  161. #endif /* __KERNEL__ */
  162. #endif /* _XTENSA_PGALLOC_H */