tlbflush.h 4.9 KB

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