tlbflush.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. /* This is calld in munmap when we have freed up some page-table pages.
  34. * We don't need to do anything here, there's nothing special about our
  35. * page-table pages.
  36. */
  37. static inline void flush_tlb_pgtables(struct mm_struct *mm,
  38. unsigned long start, unsigned long end)
  39. {
  40. }
  41. /* TLB operations. */
  42. static inline unsigned long itlb_probe(unsigned long addr)
  43. {
  44. unsigned long tmp;
  45. __asm__ __volatile__("pitlb %0, %1\n\t" : "=a" (tmp) : "a" (addr));
  46. return tmp;
  47. }
  48. static inline unsigned long dtlb_probe(unsigned long addr)
  49. {
  50. unsigned long tmp;
  51. __asm__ __volatile__("pdtlb %0, %1\n\t" : "=a" (tmp) : "a" (addr));
  52. return tmp;
  53. }
  54. static inline void invalidate_itlb_entry (unsigned long probe)
  55. {
  56. __asm__ __volatile__("iitlb %0; isync\n\t" : : "a" (probe));
  57. }
  58. static inline void invalidate_dtlb_entry (unsigned long probe)
  59. {
  60. __asm__ __volatile__("idtlb %0; dsync\n\t" : : "a" (probe));
  61. }
  62. /* Use the .._no_isync functions with caution. Generally, these are
  63. * handy for bulk invalidates followed by a single 'isync'. The
  64. * caller must follow up with an 'isync', which can be relatively
  65. * expensive on some Xtensa implementations.
  66. */
  67. static inline void invalidate_itlb_entry_no_isync (unsigned entry)
  68. {
  69. /* Caller must follow up with 'isync'. */
  70. __asm__ __volatile__ ("iitlb %0\n" : : "a" (entry) );
  71. }
  72. static inline void invalidate_dtlb_entry_no_isync (unsigned entry)
  73. {
  74. /* Caller must follow up with 'isync'. */
  75. __asm__ __volatile__ ("idtlb %0\n" : : "a" (entry) );
  76. }
  77. static inline void set_itlbcfg_register (unsigned long val)
  78. {
  79. __asm__ __volatile__("wsr %0, "__stringify(ITLBCFG)"\n\t" "isync\n\t"
  80. : : "a" (val));
  81. }
  82. static inline void set_dtlbcfg_register (unsigned long val)
  83. {
  84. __asm__ __volatile__("wsr %0, "__stringify(DTLBCFG)"; dsync\n\t"
  85. : : "a" (val));
  86. }
  87. static inline void set_ptevaddr_register (unsigned long val)
  88. {
  89. __asm__ __volatile__(" wsr %0, "__stringify(PTEVADDR)"; isync\n"
  90. : : "a" (val));
  91. }
  92. static inline unsigned long read_ptevaddr_register (void)
  93. {
  94. unsigned long tmp;
  95. __asm__ __volatile__("rsr %0, "__stringify(PTEVADDR)"\n\t" : "=a" (tmp));
  96. return tmp;
  97. }
  98. static inline void write_dtlb_entry (pte_t entry, int way)
  99. {
  100. __asm__ __volatile__("wdtlb %1, %0; dsync\n\t"
  101. : : "r" (way), "r" (entry) );
  102. }
  103. static inline void write_itlb_entry (pte_t entry, int way)
  104. {
  105. __asm__ __volatile__("witlb %1, %0; isync\n\t"
  106. : : "r" (way), "r" (entry) );
  107. }
  108. static inline void invalidate_page_directory (void)
  109. {
  110. invalidate_dtlb_entry (DTLB_WAY_PGD);
  111. invalidate_dtlb_entry (DTLB_WAY_PGD+1);
  112. invalidate_dtlb_entry (DTLB_WAY_PGD+2);
  113. }
  114. static inline void invalidate_itlb_mapping (unsigned address)
  115. {
  116. unsigned long tlb_entry;
  117. if (((tlb_entry = itlb_probe(address)) & (1 << ITLB_HIT_BIT)) != 0)
  118. invalidate_itlb_entry(tlb_entry);
  119. }
  120. static inline void invalidate_dtlb_mapping (unsigned address)
  121. {
  122. unsigned long tlb_entry;
  123. if (((tlb_entry = dtlb_probe(address)) & (1 << DTLB_HIT_BIT)) != 0)
  124. invalidate_dtlb_entry(tlb_entry);
  125. }
  126. #define check_pgt_cache() do { } while (0)
  127. /*
  128. * DO NOT USE THESE FUNCTIONS. These instructions aren't part of the Xtensa
  129. * ISA and exist only for test purposes..
  130. * You may find it helpful for MMU debugging, however.
  131. *
  132. * 'at' is the unmodified input register
  133. * 'as' is the output register, as follows (specific to the Linux config):
  134. *
  135. * as[31..12] contain the virtual address
  136. * as[11..08] are meaningless
  137. * as[07..00] contain the asid
  138. */
  139. static inline unsigned long read_dtlb_virtual (int way)
  140. {
  141. unsigned long tmp;
  142. __asm__ __volatile__("rdtlb0 %0, %1\n\t" : "=a" (tmp), "+a" (way));
  143. return tmp;
  144. }
  145. static inline unsigned long read_dtlb_translation (int way)
  146. {
  147. unsigned long tmp;
  148. __asm__ __volatile__("rdtlb1 %0, %1\n\t" : "=a" (tmp), "+a" (way));
  149. return tmp;
  150. }
  151. static inline unsigned long read_itlb_virtual (int way)
  152. {
  153. unsigned long tmp;
  154. __asm__ __volatile__("ritlb0 %0, %1\n\t" : "=a" (tmp), "+a" (way));
  155. return tmp;
  156. }
  157. static inline unsigned long read_itlb_translation (int way)
  158. {
  159. unsigned long tmp;
  160. __asm__ __volatile__("ritlb1 %0, %1\n\t" : "=a" (tmp), "+a" (way));
  161. return tmp;
  162. }
  163. #endif /* __ASSEMBLY__ */
  164. #endif /* __KERNEL__ */
  165. #endif /* _XTENSA_TLBFLUSH_H */