tlbflush.h 12 KB

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