tlbflush.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. /*
  2. * linux/include/asm-arm/tlbflush.h
  3. *
  4. * Copyright (C) 1999-2003 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #ifndef _ASMARM_TLBFLUSH_H
  11. #define _ASMARM_TLBFLUSH_H
  12. #include <linux/config.h>
  13. #ifndef CONFIG_MMU
  14. #define tlb_flush(tlb) ((void) tlb)
  15. #else /* CONFIG_MMU */
  16. #include <asm/glue.h>
  17. #define TLB_V3_PAGE (1 << 0)
  18. #define TLB_V4_U_PAGE (1 << 1)
  19. #define TLB_V4_D_PAGE (1 << 2)
  20. #define TLB_V4_I_PAGE (1 << 3)
  21. #define TLB_V6_U_PAGE (1 << 4)
  22. #define TLB_V6_D_PAGE (1 << 5)
  23. #define TLB_V6_I_PAGE (1 << 6)
  24. #define TLB_V3_FULL (1 << 8)
  25. #define TLB_V4_U_FULL (1 << 9)
  26. #define TLB_V4_D_FULL (1 << 10)
  27. #define TLB_V4_I_FULL (1 << 11)
  28. #define TLB_V6_U_FULL (1 << 12)
  29. #define TLB_V6_D_FULL (1 << 13)
  30. #define TLB_V6_I_FULL (1 << 14)
  31. #define TLB_V6_U_ASID (1 << 16)
  32. #define TLB_V6_D_ASID (1 << 17)
  33. #define TLB_V6_I_ASID (1 << 18)
  34. #define TLB_DCLEAN (1 << 30)
  35. #define TLB_WB (1 << 31)
  36. /*
  37. * MMU TLB Model
  38. * =============
  39. *
  40. * We have the following to choose from:
  41. * v3 - ARMv3
  42. * v4 - ARMv4 without write buffer
  43. * v4wb - ARMv4 with write buffer without I TLB flush entry instruction
  44. * v4wbi - ARMv4 with write buffer with I TLB flush entry instruction
  45. * v6wbi - ARMv6 with write buffer with I TLB flush entry instruction
  46. */
  47. #undef _TLB
  48. #undef MULTI_TLB
  49. #define v3_tlb_flags (TLB_V3_FULL | TLB_V3_PAGE)
  50. #ifdef CONFIG_CPU_TLB_V3
  51. # define v3_possible_flags v3_tlb_flags
  52. # define v3_always_flags v3_tlb_flags
  53. # ifdef _TLB
  54. # define MULTI_TLB 1
  55. # else
  56. # define _TLB v3
  57. # endif
  58. #else
  59. # define v3_possible_flags 0
  60. # define v3_always_flags (-1UL)
  61. #endif
  62. #define v4_tlb_flags (TLB_V4_U_FULL | TLB_V4_U_PAGE)
  63. #ifdef CONFIG_CPU_TLB_V4WT
  64. # define v4_possible_flags v4_tlb_flags
  65. # define v4_always_flags v4_tlb_flags
  66. # ifdef _TLB
  67. # define MULTI_TLB 1
  68. # else
  69. # define _TLB v4
  70. # endif
  71. #else
  72. # define v4_possible_flags 0
  73. # define v4_always_flags (-1UL)
  74. #endif
  75. #define v4wbi_tlb_flags (TLB_WB | TLB_DCLEAN | \
  76. TLB_V4_I_FULL | TLB_V4_D_FULL | \
  77. TLB_V4_I_PAGE | TLB_V4_D_PAGE)
  78. #ifdef CONFIG_CPU_TLB_V4WBI
  79. # define v4wbi_possible_flags v4wbi_tlb_flags
  80. # define v4wbi_always_flags v4wbi_tlb_flags
  81. # ifdef _TLB
  82. # define MULTI_TLB 1
  83. # else
  84. # define _TLB v4wbi
  85. # endif
  86. #else
  87. # define v4wbi_possible_flags 0
  88. # define v4wbi_always_flags (-1UL)
  89. #endif
  90. #define v4wb_tlb_flags (TLB_WB | TLB_DCLEAN | \
  91. TLB_V4_I_FULL | TLB_V4_D_FULL | \
  92. TLB_V4_D_PAGE)
  93. #ifdef CONFIG_CPU_TLB_V4WB
  94. # define v4wb_possible_flags v4wb_tlb_flags
  95. # define v4wb_always_flags v4wb_tlb_flags
  96. # ifdef _TLB
  97. # define MULTI_TLB 1
  98. # else
  99. # define _TLB v4wb
  100. # endif
  101. #else
  102. # define v4wb_possible_flags 0
  103. # define v4wb_always_flags (-1UL)
  104. #endif
  105. #define v6wbi_tlb_flags (TLB_WB | TLB_DCLEAN | \
  106. TLB_V6_I_FULL | TLB_V6_D_FULL | \
  107. TLB_V6_I_PAGE | TLB_V6_D_PAGE | \
  108. TLB_V6_I_ASID | TLB_V6_D_ASID)
  109. #ifdef CONFIG_CPU_TLB_V6
  110. # define v6wbi_possible_flags v6wbi_tlb_flags
  111. # define v6wbi_always_flags v6wbi_tlb_flags
  112. # ifdef _TLB
  113. # define MULTI_TLB 1
  114. # else
  115. # define _TLB v6wbi
  116. # endif
  117. #else
  118. # define v6wbi_possible_flags 0
  119. # define v6wbi_always_flags (-1UL)
  120. #endif
  121. #ifndef _TLB
  122. #error Unknown TLB model
  123. #endif
  124. #ifndef __ASSEMBLY__
  125. struct cpu_tlb_fns {
  126. void (*flush_user_range)(unsigned long, unsigned long, struct vm_area_struct *);
  127. void (*flush_kern_range)(unsigned long, unsigned long);
  128. unsigned long tlb_flags;
  129. };
  130. /*
  131. * Select the calling method
  132. */
  133. #ifdef MULTI_TLB
  134. #define __cpu_flush_user_tlb_range cpu_tlb.flush_user_range
  135. #define __cpu_flush_kern_tlb_range cpu_tlb.flush_kern_range
  136. #else
  137. #define __cpu_flush_user_tlb_range __glue(_TLB,_flush_user_tlb_range)
  138. #define __cpu_flush_kern_tlb_range __glue(_TLB,_flush_kern_tlb_range)
  139. extern void __cpu_flush_user_tlb_range(unsigned long, unsigned long, struct vm_area_struct *);
  140. extern void __cpu_flush_kern_tlb_range(unsigned long, unsigned long);
  141. #endif
  142. extern struct cpu_tlb_fns cpu_tlb;
  143. #define __cpu_tlb_flags cpu_tlb.tlb_flags
  144. /*
  145. * TLB Management
  146. * ==============
  147. *
  148. * The arch/arm/mm/tlb-*.S files implement these methods.
  149. *
  150. * The TLB specific code is expected to perform whatever tests it
  151. * needs to determine if it should invalidate the TLB for each
  152. * call. Start addresses are inclusive and end addresses are
  153. * exclusive; it is safe to round these addresses down.
  154. *
  155. * flush_tlb_all()
  156. *
  157. * Invalidate the entire TLB.
  158. *
  159. * flush_tlb_mm(mm)
  160. *
  161. * Invalidate all TLB entries in a particular address
  162. * space.
  163. * - mm - mm_struct describing address space
  164. *
  165. * flush_tlb_range(mm,start,end)
  166. *
  167. * Invalidate a range of TLB entries in the specified
  168. * address space.
  169. * - mm - mm_struct describing address space
  170. * - start - start address (may not be aligned)
  171. * - end - end address (exclusive, may not be aligned)
  172. *
  173. * flush_tlb_page(vaddr,vma)
  174. *
  175. * Invalidate the specified page in the specified address range.
  176. * - vaddr - virtual address (may not be aligned)
  177. * - vma - vma_struct describing address range
  178. *
  179. * flush_kern_tlb_page(kaddr)
  180. *
  181. * Invalidate the TLB entry for the specified page. The address
  182. * will be in the kernels virtual memory space. Current uses
  183. * only require the D-TLB to be invalidated.
  184. * - kaddr - Kernel virtual memory address
  185. */
  186. /*
  187. * We optimise the code below by:
  188. * - building a set of TLB flags that might be set in __cpu_tlb_flags
  189. * - building a set of TLB flags that will always be set in __cpu_tlb_flags
  190. * - if we're going to need __cpu_tlb_flags, access it once and only once
  191. *
  192. * This allows us to build optimal assembly for the single-CPU type case,
  193. * and as close to optimal given the compiler constrants for multi-CPU
  194. * case. We could do better for the multi-CPU case if the compiler
  195. * implemented the "%?" method, but this has been discontinued due to too
  196. * many people getting it wrong.
  197. */
  198. #define possible_tlb_flags (v3_possible_flags | \
  199. v4_possible_flags | \
  200. v4wbi_possible_flags | \
  201. v4wb_possible_flags | \
  202. v6wbi_possible_flags)
  203. #define always_tlb_flags (v3_always_flags & \
  204. v4_always_flags & \
  205. v4wbi_always_flags & \
  206. v4wb_always_flags & \
  207. v6wbi_always_flags)
  208. #define tlb_flag(f) ((always_tlb_flags & (f)) || (__tlb_flag & possible_tlb_flags & (f)))
  209. static inline void local_flush_tlb_all(void)
  210. {
  211. const int zero = 0;
  212. const unsigned int __tlb_flag = __cpu_tlb_flags;
  213. if (tlb_flag(TLB_WB))
  214. asm("mcr%? p15, 0, %0, c7, c10, 4" : : "r" (zero));
  215. if (tlb_flag(TLB_V3_FULL))
  216. asm("mcr%? p15, 0, %0, c6, c0, 0" : : "r" (zero));
  217. if (tlb_flag(TLB_V4_U_FULL | TLB_V6_U_FULL))
  218. asm("mcr%? p15, 0, %0, c8, c7, 0" : : "r" (zero));
  219. if (tlb_flag(TLB_V4_D_FULL | TLB_V6_D_FULL))
  220. asm("mcr%? p15, 0, %0, c8, c6, 0" : : "r" (zero));
  221. if (tlb_flag(TLB_V4_I_FULL | TLB_V6_I_FULL))
  222. asm("mcr%? p15, 0, %0, c8, c5, 0" : : "r" (zero));
  223. }
  224. static inline void local_flush_tlb_mm(struct mm_struct *mm)
  225. {
  226. const int zero = 0;
  227. const int asid = ASID(mm);
  228. const unsigned int __tlb_flag = __cpu_tlb_flags;
  229. if (tlb_flag(TLB_WB))
  230. asm("mcr%? p15, 0, %0, c7, c10, 4" : : "r" (zero));
  231. if (cpu_isset(smp_processor_id(), mm->cpu_vm_mask)) {
  232. if (tlb_flag(TLB_V3_FULL))
  233. asm("mcr%? p15, 0, %0, c6, c0, 0" : : "r" (zero));
  234. if (tlb_flag(TLB_V4_U_FULL))
  235. asm("mcr%? p15, 0, %0, c8, c7, 0" : : "r" (zero));
  236. if (tlb_flag(TLB_V4_D_FULL))
  237. asm("mcr%? p15, 0, %0, c8, c6, 0" : : "r" (zero));
  238. if (tlb_flag(TLB_V4_I_FULL))
  239. asm("mcr%? p15, 0, %0, c8, c5, 0" : : "r" (zero));
  240. }
  241. if (tlb_flag(TLB_V6_U_ASID))
  242. asm("mcr%? p15, 0, %0, c8, c7, 2" : : "r" (asid));
  243. if (tlb_flag(TLB_V6_D_ASID))
  244. asm("mcr%? p15, 0, %0, c8, c6, 2" : : "r" (asid));
  245. if (tlb_flag(TLB_V6_I_ASID))
  246. asm("mcr%? p15, 0, %0, c8, c5, 2" : : "r" (asid));
  247. }
  248. static inline void
  249. local_flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
  250. {
  251. const int zero = 0;
  252. const unsigned int __tlb_flag = __cpu_tlb_flags;
  253. uaddr = (uaddr & PAGE_MASK) | ASID(vma->vm_mm);
  254. if (tlb_flag(TLB_WB))
  255. asm("mcr%? p15, 0, %0, c7, c10, 4" : : "r" (zero));
  256. if (cpu_isset(smp_processor_id(), vma->vm_mm->cpu_vm_mask)) {
  257. if (tlb_flag(TLB_V3_PAGE))
  258. asm("mcr%? p15, 0, %0, c6, c0, 0" : : "r" (uaddr));
  259. if (tlb_flag(TLB_V4_U_PAGE))
  260. asm("mcr%? p15, 0, %0, c8, c7, 1" : : "r" (uaddr));
  261. if (tlb_flag(TLB_V4_D_PAGE))
  262. asm("mcr%? p15, 0, %0, c8, c6, 1" : : "r" (uaddr));
  263. if (tlb_flag(TLB_V4_I_PAGE))
  264. asm("mcr%? p15, 0, %0, c8, c5, 1" : : "r" (uaddr));
  265. if (!tlb_flag(TLB_V4_I_PAGE) && tlb_flag(TLB_V4_I_FULL))
  266. asm("mcr%? p15, 0, %0, c8, c5, 0" : : "r" (zero));
  267. }
  268. if (tlb_flag(TLB_V6_U_PAGE))
  269. asm("mcr%? p15, 0, %0, c8, c7, 1" : : "r" (uaddr));
  270. if (tlb_flag(TLB_V6_D_PAGE))
  271. asm("mcr%? p15, 0, %0, c8, c6, 1" : : "r" (uaddr));
  272. if (tlb_flag(TLB_V6_I_PAGE))
  273. asm("mcr%? p15, 0, %0, c8, c5, 1" : : "r" (uaddr));
  274. }
  275. static inline void local_flush_tlb_kernel_page(unsigned long kaddr)
  276. {
  277. const int zero = 0;
  278. const unsigned int __tlb_flag = __cpu_tlb_flags;
  279. kaddr &= PAGE_MASK;
  280. if (tlb_flag(TLB_WB))
  281. asm("mcr%? p15, 0, %0, c7, c10, 4" : : "r" (zero));
  282. if (tlb_flag(TLB_V3_PAGE))
  283. asm("mcr%? p15, 0, %0, c6, c0, 0" : : "r" (kaddr));
  284. if (tlb_flag(TLB_V4_U_PAGE))
  285. asm("mcr%? p15, 0, %0, c8, c7, 1" : : "r" (kaddr));
  286. if (tlb_flag(TLB_V4_D_PAGE))
  287. asm("mcr%? p15, 0, %0, c8, c6, 1" : : "r" (kaddr));
  288. if (tlb_flag(TLB_V4_I_PAGE))
  289. asm("mcr%? p15, 0, %0, c8, c5, 1" : : "r" (kaddr));
  290. if (!tlb_flag(TLB_V4_I_PAGE) && tlb_flag(TLB_V4_I_FULL))
  291. asm("mcr%? p15, 0, %0, c8, c5, 0" : : "r" (zero));
  292. if (tlb_flag(TLB_V6_U_PAGE))
  293. asm("mcr%? p15, 0, %0, c8, c7, 1" : : "r" (kaddr));
  294. if (tlb_flag(TLB_V6_D_PAGE))
  295. asm("mcr%? p15, 0, %0, c8, c6, 1" : : "r" (kaddr));
  296. if (tlb_flag(TLB_V6_I_PAGE))
  297. asm("mcr%? p15, 0, %0, c8, c5, 1" : : "r" (kaddr));
  298. /* The ARM ARM states that the completion of a TLB maintenance
  299. * operation is only guaranteed by a DSB instruction
  300. */
  301. if (tlb_flag(TLB_V6_U_PAGE | TLB_V6_D_PAGE | TLB_V6_I_PAGE))
  302. asm("mcr%? p15, 0, %0, c7, c10, 4" : : "r" (zero));
  303. }
  304. /*
  305. * flush_pmd_entry
  306. *
  307. * Flush a PMD entry (word aligned, or double-word aligned) to
  308. * RAM if the TLB for the CPU we are running on requires this.
  309. * This is typically used when we are creating PMD entries.
  310. *
  311. * clean_pmd_entry
  312. *
  313. * Clean (but don't drain the write buffer) if the CPU requires
  314. * these operations. This is typically used when we are removing
  315. * PMD entries.
  316. */
  317. static inline void flush_pmd_entry(pmd_t *pmd)
  318. {
  319. const unsigned int zero = 0;
  320. const unsigned int __tlb_flag = __cpu_tlb_flags;
  321. if (tlb_flag(TLB_DCLEAN))
  322. asm("mcr%? p15, 0, %0, c7, c10, 1 @ flush_pmd"
  323. : : "r" (pmd));
  324. if (tlb_flag(TLB_WB))
  325. asm("mcr%? p15, 0, %0, c7, c10, 4 @ flush_pmd"
  326. : : "r" (zero));
  327. }
  328. static inline void clean_pmd_entry(pmd_t *pmd)
  329. {
  330. const unsigned int __tlb_flag = __cpu_tlb_flags;
  331. if (tlb_flag(TLB_DCLEAN))
  332. asm("mcr%? p15, 0, %0, c7, c10, 1 @ flush_pmd"
  333. : : "r" (pmd));
  334. }
  335. #undef tlb_flag
  336. #undef always_tlb_flags
  337. #undef possible_tlb_flags
  338. /*
  339. * Convert calls to our calling convention.
  340. */
  341. #define local_flush_tlb_range(vma,start,end) __cpu_flush_user_tlb_range(start,end,vma)
  342. #define local_flush_tlb_kernel_range(s,e) __cpu_flush_kern_tlb_range(s,e)
  343. #ifndef CONFIG_SMP
  344. #define flush_tlb_all local_flush_tlb_all
  345. #define flush_tlb_mm local_flush_tlb_mm
  346. #define flush_tlb_page local_flush_tlb_page
  347. #define flush_tlb_kernel_page local_flush_tlb_kernel_page
  348. #define flush_tlb_range local_flush_tlb_range
  349. #define flush_tlb_kernel_range local_flush_tlb_kernel_range
  350. #else
  351. extern void flush_tlb_all(void);
  352. extern void flush_tlb_mm(struct mm_struct *mm);
  353. extern void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr);
  354. extern void flush_tlb_kernel_page(unsigned long kaddr);
  355. extern void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
  356. extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
  357. #endif
  358. /*
  359. * if PG_dcache_dirty is set for the page, we need to ensure that any
  360. * cache entries for the kernels virtual memory range are written
  361. * back to the page.
  362. */
  363. extern void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr, pte_t pte);
  364. /*
  365. * ARM processors do not cache TLB tables in RAM.
  366. */
  367. #define flush_tlb_pgtables(mm,start,end) do { } while (0)
  368. #endif
  369. #endif /* CONFIG_MMU */
  370. #endif