tlbflush.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*
  2. * arch/arm/include/asm/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. #ifdef CONFIG_MMU
  13. #include <asm/glue.h>
  14. #define TLB_V4_U_PAGE (1 << 1)
  15. #define TLB_V4_D_PAGE (1 << 2)
  16. #define TLB_V4_I_PAGE (1 << 3)
  17. #define TLB_V6_U_PAGE (1 << 4)
  18. #define TLB_V6_D_PAGE (1 << 5)
  19. #define TLB_V6_I_PAGE (1 << 6)
  20. #define TLB_V4_U_FULL (1 << 9)
  21. #define TLB_V4_D_FULL (1 << 10)
  22. #define TLB_V4_I_FULL (1 << 11)
  23. #define TLB_V6_U_FULL (1 << 12)
  24. #define TLB_V6_D_FULL (1 << 13)
  25. #define TLB_V6_I_FULL (1 << 14)
  26. #define TLB_V6_U_ASID (1 << 16)
  27. #define TLB_V6_D_ASID (1 << 17)
  28. #define TLB_V6_I_ASID (1 << 18)
  29. #define TLB_V6_BP (1 << 19)
  30. /* Unified Inner Shareable TLB operations (ARMv7 MP extensions) */
  31. #define TLB_V7_UIS_PAGE (1 << 20)
  32. #define TLB_V7_UIS_FULL (1 << 21)
  33. #define TLB_V7_UIS_ASID (1 << 22)
  34. #define TLB_V7_UIS_BP (1 << 23)
  35. #define TLB_BARRIER (1 << 28)
  36. #define TLB_L2CLEAN_FR (1 << 29) /* Feroceon */
  37. #define TLB_DCLEAN (1 << 30)
  38. #define TLB_WB (1 << 31)
  39. /*
  40. * MMU TLB Model
  41. * =============
  42. *
  43. * We have the following to choose from:
  44. * v4 - ARMv4 without write buffer
  45. * v4wb - ARMv4 with write buffer without I TLB flush entry instruction
  46. * v4wbi - ARMv4 with write buffer with I TLB flush entry instruction
  47. * fr - Feroceon (v4wbi with non-outer-cacheable page table walks)
  48. * fa - Faraday (v4 with write buffer with UTLB)
  49. * v6wbi - ARMv6 with write buffer with I TLB flush entry instruction
  50. * v7wbi - identical to v6wbi
  51. */
  52. #undef _TLB
  53. #undef MULTI_TLB
  54. #ifdef CONFIG_SMP_ON_UP
  55. #define MULTI_TLB 1
  56. #endif
  57. #define v4_tlb_flags (TLB_V4_U_FULL | TLB_V4_U_PAGE)
  58. #ifdef CONFIG_CPU_TLB_V4WT
  59. # define v4_possible_flags v4_tlb_flags
  60. # define v4_always_flags v4_tlb_flags
  61. # ifdef _TLB
  62. # define MULTI_TLB 1
  63. # else
  64. # define _TLB v4
  65. # endif
  66. #else
  67. # define v4_possible_flags 0
  68. # define v4_always_flags (-1UL)
  69. #endif
  70. #define fa_tlb_flags (TLB_WB | TLB_DCLEAN | TLB_BARRIER | \
  71. TLB_V4_U_FULL | TLB_V4_U_PAGE)
  72. #ifdef CONFIG_CPU_TLB_FA
  73. # define fa_possible_flags fa_tlb_flags
  74. # define fa_always_flags fa_tlb_flags
  75. # ifdef _TLB
  76. # define MULTI_TLB 1
  77. # else
  78. # define _TLB fa
  79. # endif
  80. #else
  81. # define fa_possible_flags 0
  82. # define fa_always_flags (-1UL)
  83. #endif
  84. #define v4wbi_tlb_flags (TLB_WB | TLB_DCLEAN | \
  85. TLB_V4_I_FULL | TLB_V4_D_FULL | \
  86. TLB_V4_I_PAGE | TLB_V4_D_PAGE)
  87. #ifdef CONFIG_CPU_TLB_V4WBI
  88. # define v4wbi_possible_flags v4wbi_tlb_flags
  89. # define v4wbi_always_flags v4wbi_tlb_flags
  90. # ifdef _TLB
  91. # define MULTI_TLB 1
  92. # else
  93. # define _TLB v4wbi
  94. # endif
  95. #else
  96. # define v4wbi_possible_flags 0
  97. # define v4wbi_always_flags (-1UL)
  98. #endif
  99. #define fr_tlb_flags (TLB_WB | TLB_DCLEAN | TLB_L2CLEAN_FR | \
  100. TLB_V4_I_FULL | TLB_V4_D_FULL | \
  101. TLB_V4_I_PAGE | TLB_V4_D_PAGE)
  102. #ifdef CONFIG_CPU_TLB_FEROCEON
  103. # define fr_possible_flags fr_tlb_flags
  104. # define fr_always_flags fr_tlb_flags
  105. # ifdef _TLB
  106. # define MULTI_TLB 1
  107. # else
  108. # define _TLB v4wbi
  109. # endif
  110. #else
  111. # define fr_possible_flags 0
  112. # define fr_always_flags (-1UL)
  113. #endif
  114. #define v4wb_tlb_flags (TLB_WB | TLB_DCLEAN | \
  115. TLB_V4_I_FULL | TLB_V4_D_FULL | \
  116. TLB_V4_D_PAGE)
  117. #ifdef CONFIG_CPU_TLB_V4WB
  118. # define v4wb_possible_flags v4wb_tlb_flags
  119. # define v4wb_always_flags v4wb_tlb_flags
  120. # ifdef _TLB
  121. # define MULTI_TLB 1
  122. # else
  123. # define _TLB v4wb
  124. # endif
  125. #else
  126. # define v4wb_possible_flags 0
  127. # define v4wb_always_flags (-1UL)
  128. #endif
  129. #define v6wbi_tlb_flags (TLB_WB | TLB_DCLEAN | TLB_BARRIER | \
  130. TLB_V6_I_FULL | TLB_V6_D_FULL | \
  131. TLB_V6_I_PAGE | TLB_V6_D_PAGE | \
  132. TLB_V6_I_ASID | TLB_V6_D_ASID | \
  133. TLB_V6_BP)
  134. #ifdef CONFIG_CPU_TLB_V6
  135. # define v6wbi_possible_flags v6wbi_tlb_flags
  136. # define v6wbi_always_flags v6wbi_tlb_flags
  137. # ifdef _TLB
  138. # define MULTI_TLB 1
  139. # else
  140. # define _TLB v6wbi
  141. # endif
  142. #else
  143. # define v6wbi_possible_flags 0
  144. # define v6wbi_always_flags (-1UL)
  145. #endif
  146. #define v7wbi_tlb_flags_smp (TLB_WB | TLB_BARRIER | \
  147. TLB_V7_UIS_FULL | TLB_V7_UIS_PAGE | \
  148. TLB_V7_UIS_ASID | TLB_V7_UIS_BP)
  149. #define v7wbi_tlb_flags_up (TLB_WB | TLB_DCLEAN | TLB_BARRIER | \
  150. TLB_V6_U_FULL | TLB_V6_U_PAGE | \
  151. TLB_V6_U_ASID | TLB_V6_BP)
  152. #ifdef CONFIG_CPU_TLB_V7
  153. # ifdef CONFIG_SMP_ON_UP
  154. # define v7wbi_possible_flags (v7wbi_tlb_flags_smp | v7wbi_tlb_flags_up)
  155. # define v7wbi_always_flags (v7wbi_tlb_flags_smp & v7wbi_tlb_flags_up)
  156. # elif defined(CONFIG_SMP)
  157. # define v7wbi_possible_flags v7wbi_tlb_flags_smp
  158. # define v7wbi_always_flags v7wbi_tlb_flags_smp
  159. # else
  160. # define v7wbi_possible_flags v7wbi_tlb_flags_up
  161. # define v7wbi_always_flags v7wbi_tlb_flags_up
  162. # endif
  163. # ifdef _TLB
  164. # define MULTI_TLB 1
  165. # else
  166. # define _TLB v7wbi
  167. # endif
  168. #else
  169. # define v7wbi_possible_flags 0
  170. # define v7wbi_always_flags (-1UL)
  171. #endif
  172. #ifndef _TLB
  173. #error Unknown TLB model
  174. #endif
  175. #ifndef __ASSEMBLY__
  176. #include <linux/sched.h>
  177. struct cpu_tlb_fns {
  178. void (*flush_user_range)(unsigned long, unsigned long, struct vm_area_struct *);
  179. void (*flush_kern_range)(unsigned long, unsigned long);
  180. unsigned long tlb_flags;
  181. };
  182. /*
  183. * Select the calling method
  184. */
  185. #ifdef MULTI_TLB
  186. #define __cpu_flush_user_tlb_range cpu_tlb.flush_user_range
  187. #define __cpu_flush_kern_tlb_range cpu_tlb.flush_kern_range
  188. #else
  189. #define __cpu_flush_user_tlb_range __glue(_TLB,_flush_user_tlb_range)
  190. #define __cpu_flush_kern_tlb_range __glue(_TLB,_flush_kern_tlb_range)
  191. extern void __cpu_flush_user_tlb_range(unsigned long, unsigned long, struct vm_area_struct *);
  192. extern void __cpu_flush_kern_tlb_range(unsigned long, unsigned long);
  193. #endif
  194. extern struct cpu_tlb_fns cpu_tlb;
  195. #define __cpu_tlb_flags cpu_tlb.tlb_flags
  196. /*
  197. * TLB Management
  198. * ==============
  199. *
  200. * The arch/arm/mm/tlb-*.S files implement these methods.
  201. *
  202. * The TLB specific code is expected to perform whatever tests it
  203. * needs to determine if it should invalidate the TLB for each
  204. * call. Start addresses are inclusive and end addresses are
  205. * exclusive; it is safe to round these addresses down.
  206. *
  207. * flush_tlb_all()
  208. *
  209. * Invalidate the entire TLB.
  210. *
  211. * flush_tlb_mm(mm)
  212. *
  213. * Invalidate all TLB entries in a particular address
  214. * space.
  215. * - mm - mm_struct describing address space
  216. *
  217. * flush_tlb_range(mm,start,end)
  218. *
  219. * Invalidate a range of TLB entries in the specified
  220. * address space.
  221. * - mm - mm_struct describing address space
  222. * - start - start address (may not be aligned)
  223. * - end - end address (exclusive, may not be aligned)
  224. *
  225. * flush_tlb_page(vaddr,vma)
  226. *
  227. * Invalidate the specified page in the specified address range.
  228. * - vaddr - virtual address (may not be aligned)
  229. * - vma - vma_struct describing address range
  230. *
  231. * flush_kern_tlb_page(kaddr)
  232. *
  233. * Invalidate the TLB entry for the specified page. The address
  234. * will be in the kernels virtual memory space. Current uses
  235. * only require the D-TLB to be invalidated.
  236. * - kaddr - Kernel virtual memory address
  237. */
  238. /*
  239. * We optimise the code below by:
  240. * - building a set of TLB flags that might be set in __cpu_tlb_flags
  241. * - building a set of TLB flags that will always be set in __cpu_tlb_flags
  242. * - if we're going to need __cpu_tlb_flags, access it once and only once
  243. *
  244. * This allows us to build optimal assembly for the single-CPU type case,
  245. * and as close to optimal given the compiler constrants for multi-CPU
  246. * case. We could do better for the multi-CPU case if the compiler
  247. * implemented the "%?" method, but this has been discontinued due to too
  248. * many people getting it wrong.
  249. */
  250. #define possible_tlb_flags (v4_possible_flags | \
  251. v4wbi_possible_flags | \
  252. fr_possible_flags | \
  253. v4wb_possible_flags | \
  254. fa_possible_flags | \
  255. v6wbi_possible_flags | \
  256. v7wbi_possible_flags)
  257. #define always_tlb_flags (v4_always_flags & \
  258. v4wbi_always_flags & \
  259. fr_always_flags & \
  260. v4wb_always_flags & \
  261. fa_always_flags & \
  262. v6wbi_always_flags & \
  263. v7wbi_always_flags)
  264. #define tlb_flag(f) ((always_tlb_flags & (f)) || (__tlb_flag & possible_tlb_flags & (f)))
  265. #define __tlb_op(f, insnarg, arg) \
  266. do { \
  267. if (always_tlb_flags & (f)) \
  268. asm("mcr " insnarg \
  269. : : "r" (arg) : "cc"); \
  270. else if (possible_tlb_flags & (f)) \
  271. asm("tst %1, %2\n\t" \
  272. "mcrne " insnarg \
  273. : : "r" (arg), "r" (__tlb_flag), "Ir" (f) \
  274. : "cc"); \
  275. } while (0)
  276. #define tlb_op(f, regs, arg) __tlb_op(f, "p15, 0, %0, " regs, arg)
  277. #define tlb_l2_op(f, regs, arg) __tlb_op(f, "p15, 1, %0, " regs, arg)
  278. static inline void __local_flush_tlb_all(void)
  279. {
  280. const int zero = 0;
  281. const unsigned int __tlb_flag = __cpu_tlb_flags;
  282. tlb_op(TLB_V4_U_FULL | TLB_V6_U_FULL, "c8, c7, 0", zero);
  283. tlb_op(TLB_V4_D_FULL | TLB_V6_D_FULL, "c8, c6, 0", zero);
  284. tlb_op(TLB_V4_I_FULL | TLB_V6_I_FULL, "c8, c5, 0", zero);
  285. }
  286. static inline void local_flush_tlb_all(void)
  287. {
  288. const int zero = 0;
  289. const unsigned int __tlb_flag = __cpu_tlb_flags;
  290. if (tlb_flag(TLB_WB))
  291. dsb(nshst);
  292. __local_flush_tlb_all();
  293. tlb_op(TLB_V7_UIS_FULL, "c8, c7, 0", zero);
  294. if (tlb_flag(TLB_BARRIER)) {
  295. dsb(nsh);
  296. isb();
  297. }
  298. }
  299. static inline void __flush_tlb_all(void)
  300. {
  301. const int zero = 0;
  302. const unsigned int __tlb_flag = __cpu_tlb_flags;
  303. if (tlb_flag(TLB_WB))
  304. dsb(ishst);
  305. __local_flush_tlb_all();
  306. tlb_op(TLB_V7_UIS_FULL, "c8, c3, 0", zero);
  307. if (tlb_flag(TLB_BARRIER)) {
  308. dsb(ish);
  309. isb();
  310. }
  311. }
  312. static inline void __local_flush_tlb_mm(struct mm_struct *mm)
  313. {
  314. const int zero = 0;
  315. const int asid = ASID(mm);
  316. const unsigned int __tlb_flag = __cpu_tlb_flags;
  317. if (possible_tlb_flags & (TLB_V4_U_FULL|TLB_V4_D_FULL|TLB_V4_I_FULL)) {
  318. if (cpumask_test_cpu(smp_processor_id(), mm_cpumask(mm))) {
  319. tlb_op(TLB_V4_U_FULL, "c8, c7, 0", zero);
  320. tlb_op(TLB_V4_D_FULL, "c8, c6, 0", zero);
  321. tlb_op(TLB_V4_I_FULL, "c8, c5, 0", zero);
  322. }
  323. }
  324. tlb_op(TLB_V6_U_ASID, "c8, c7, 2", asid);
  325. tlb_op(TLB_V6_D_ASID, "c8, c6, 2", asid);
  326. tlb_op(TLB_V6_I_ASID, "c8, c5, 2", asid);
  327. }
  328. static inline void local_flush_tlb_mm(struct mm_struct *mm)
  329. {
  330. const int asid = ASID(mm);
  331. const unsigned int __tlb_flag = __cpu_tlb_flags;
  332. if (tlb_flag(TLB_WB))
  333. dsb(nshst);
  334. __local_flush_tlb_mm(mm);
  335. tlb_op(TLB_V7_UIS_ASID, "c8, c7, 2", asid);
  336. if (tlb_flag(TLB_BARRIER))
  337. dsb(nsh);
  338. }
  339. static inline void __flush_tlb_mm(struct mm_struct *mm)
  340. {
  341. const unsigned int __tlb_flag = __cpu_tlb_flags;
  342. if (tlb_flag(TLB_WB))
  343. dsb(ishst);
  344. __local_flush_tlb_mm(mm);
  345. #ifdef CONFIG_ARM_ERRATA_720789
  346. tlb_op(TLB_V7_UIS_ASID, "c8, c3, 0", 0);
  347. #else
  348. tlb_op(TLB_V7_UIS_ASID, "c8, c3, 2", ASID(mm));
  349. #endif
  350. if (tlb_flag(TLB_BARRIER))
  351. dsb(ish);
  352. }
  353. static inline void
  354. __local_flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
  355. {
  356. const int zero = 0;
  357. const unsigned int __tlb_flag = __cpu_tlb_flags;
  358. uaddr = (uaddr & PAGE_MASK) | ASID(vma->vm_mm);
  359. if (possible_tlb_flags & (TLB_V4_U_PAGE|TLB_V4_D_PAGE|TLB_V4_I_PAGE|TLB_V4_I_FULL) &&
  360. cpumask_test_cpu(smp_processor_id(), mm_cpumask(vma->vm_mm))) {
  361. tlb_op(TLB_V4_U_PAGE, "c8, c7, 1", uaddr);
  362. tlb_op(TLB_V4_D_PAGE, "c8, c6, 1", uaddr);
  363. tlb_op(TLB_V4_I_PAGE, "c8, c5, 1", uaddr);
  364. if (!tlb_flag(TLB_V4_I_PAGE) && tlb_flag(TLB_V4_I_FULL))
  365. asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc");
  366. }
  367. tlb_op(TLB_V6_U_PAGE, "c8, c7, 1", uaddr);
  368. tlb_op(TLB_V6_D_PAGE, "c8, c6, 1", uaddr);
  369. tlb_op(TLB_V6_I_PAGE, "c8, c5, 1", uaddr);
  370. }
  371. static inline void
  372. local_flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
  373. {
  374. const unsigned int __tlb_flag = __cpu_tlb_flags;
  375. uaddr = (uaddr & PAGE_MASK) | ASID(vma->vm_mm);
  376. if (tlb_flag(TLB_WB))
  377. dsb(nshst);
  378. __local_flush_tlb_page(vma, uaddr);
  379. tlb_op(TLB_V7_UIS_PAGE, "c8, c7, 1", uaddr);
  380. if (tlb_flag(TLB_BARRIER))
  381. dsb(nsh);
  382. }
  383. static inline void
  384. __flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr)
  385. {
  386. const unsigned int __tlb_flag = __cpu_tlb_flags;
  387. uaddr = (uaddr & PAGE_MASK) | ASID(vma->vm_mm);
  388. if (tlb_flag(TLB_WB))
  389. dsb(ishst);
  390. __local_flush_tlb_page(vma, uaddr);
  391. #ifdef CONFIG_ARM_ERRATA_720789
  392. tlb_op(TLB_V7_UIS_PAGE, "c8, c3, 3", uaddr & PAGE_MASK);
  393. #else
  394. tlb_op(TLB_V7_UIS_PAGE, "c8, c3, 1", uaddr);
  395. #endif
  396. if (tlb_flag(TLB_BARRIER))
  397. dsb(ish);
  398. }
  399. static inline void __local_flush_tlb_kernel_page(unsigned long kaddr)
  400. {
  401. const int zero = 0;
  402. const unsigned int __tlb_flag = __cpu_tlb_flags;
  403. tlb_op(TLB_V4_U_PAGE, "c8, c7, 1", kaddr);
  404. tlb_op(TLB_V4_D_PAGE, "c8, c6, 1", kaddr);
  405. tlb_op(TLB_V4_I_PAGE, "c8, c5, 1", kaddr);
  406. if (!tlb_flag(TLB_V4_I_PAGE) && tlb_flag(TLB_V4_I_FULL))
  407. asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc");
  408. tlb_op(TLB_V6_U_PAGE, "c8, c7, 1", kaddr);
  409. tlb_op(TLB_V6_D_PAGE, "c8, c6, 1", kaddr);
  410. tlb_op(TLB_V6_I_PAGE, "c8, c5, 1", kaddr);
  411. }
  412. static inline void local_flush_tlb_kernel_page(unsigned long kaddr)
  413. {
  414. const unsigned int __tlb_flag = __cpu_tlb_flags;
  415. kaddr &= PAGE_MASK;
  416. if (tlb_flag(TLB_WB))
  417. dsb(nshst);
  418. __local_flush_tlb_kernel_page(kaddr);
  419. tlb_op(TLB_V7_UIS_PAGE, "c8, c7, 1", kaddr);
  420. if (tlb_flag(TLB_BARRIER)) {
  421. dsb(nsh);
  422. isb();
  423. }
  424. }
  425. static inline void __flush_tlb_kernel_page(unsigned long kaddr)
  426. {
  427. const unsigned int __tlb_flag = __cpu_tlb_flags;
  428. kaddr &= PAGE_MASK;
  429. if (tlb_flag(TLB_WB))
  430. dsb(ishst);
  431. __local_flush_tlb_kernel_page(kaddr);
  432. tlb_op(TLB_V7_UIS_PAGE, "c8, c3, 1", kaddr);
  433. if (tlb_flag(TLB_BARRIER)) {
  434. dsb(ish);
  435. isb();
  436. }
  437. }
  438. /*
  439. * Branch predictor maintenance is paired with full TLB invalidation, so
  440. * there is no need for any barriers here.
  441. */
  442. static inline void __local_flush_bp_all(void)
  443. {
  444. const int zero = 0;
  445. const unsigned int __tlb_flag = __cpu_tlb_flags;
  446. if (tlb_flag(TLB_V6_BP))
  447. asm("mcr p15, 0, %0, c7, c5, 6" : : "r" (zero));
  448. }
  449. static inline void local_flush_bp_all(void)
  450. {
  451. const int zero = 0;
  452. const unsigned int __tlb_flag = __cpu_tlb_flags;
  453. __local_flush_bp_all();
  454. if (tlb_flag(TLB_V7_UIS_BP))
  455. asm("mcr p15, 0, %0, c7, c5, 6" : : "r" (zero));
  456. }
  457. static inline void __flush_bp_all(void)
  458. {
  459. const int zero = 0;
  460. const unsigned int __tlb_flag = __cpu_tlb_flags;
  461. __local_flush_bp_all();
  462. if (tlb_flag(TLB_V7_UIS_BP))
  463. asm("mcr p15, 0, %0, c7, c1, 6" : : "r" (zero));
  464. }
  465. /*
  466. * flush_pmd_entry
  467. *
  468. * Flush a PMD entry (word aligned, or double-word aligned) to
  469. * RAM if the TLB for the CPU we are running on requires this.
  470. * This is typically used when we are creating PMD entries.
  471. *
  472. * clean_pmd_entry
  473. *
  474. * Clean (but don't drain the write buffer) if the CPU requires
  475. * these operations. This is typically used when we are removing
  476. * PMD entries.
  477. */
  478. static inline void flush_pmd_entry(void *pmd)
  479. {
  480. const unsigned int __tlb_flag = __cpu_tlb_flags;
  481. tlb_op(TLB_DCLEAN, "c7, c10, 1 @ flush_pmd", pmd);
  482. tlb_l2_op(TLB_L2CLEAN_FR, "c15, c9, 1 @ L2 flush_pmd", pmd);
  483. if (tlb_flag(TLB_WB))
  484. dsb(ishst);
  485. }
  486. static inline void clean_pmd_entry(void *pmd)
  487. {
  488. const unsigned int __tlb_flag = __cpu_tlb_flags;
  489. tlb_op(TLB_DCLEAN, "c7, c10, 1 @ flush_pmd", pmd);
  490. tlb_l2_op(TLB_L2CLEAN_FR, "c15, c9, 1 @ L2 flush_pmd", pmd);
  491. }
  492. #undef tlb_op
  493. #undef tlb_flag
  494. #undef always_tlb_flags
  495. #undef possible_tlb_flags
  496. /*
  497. * Convert calls to our calling convention.
  498. */
  499. #define local_flush_tlb_range(vma,start,end) __cpu_flush_user_tlb_range(start,end,vma)
  500. #define local_flush_tlb_kernel_range(s,e) __cpu_flush_kern_tlb_range(s,e)
  501. #ifndef CONFIG_SMP
  502. #define flush_tlb_all local_flush_tlb_all
  503. #define flush_tlb_mm local_flush_tlb_mm
  504. #define flush_tlb_page local_flush_tlb_page
  505. #define flush_tlb_kernel_page local_flush_tlb_kernel_page
  506. #define flush_tlb_range local_flush_tlb_range
  507. #define flush_tlb_kernel_range local_flush_tlb_kernel_range
  508. #define flush_bp_all local_flush_bp_all
  509. #else
  510. extern void flush_tlb_all(void);
  511. extern void flush_tlb_mm(struct mm_struct *mm);
  512. extern void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr);
  513. extern void flush_tlb_kernel_page(unsigned long kaddr);
  514. extern void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
  515. extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
  516. extern void flush_bp_all(void);
  517. #endif
  518. /*
  519. * If PG_dcache_clean is not set for the page, we need to ensure that any
  520. * cache entries for the kernels virtual memory range are written
  521. * back to the page. On ARMv6 and later, the cache coherency is handled via
  522. * the set_pte_at() function.
  523. */
  524. #if __LINUX_ARM_ARCH__ < 6
  525. extern void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr,
  526. pte_t *ptep);
  527. #else
  528. static inline void update_mmu_cache(struct vm_area_struct *vma,
  529. unsigned long addr, pte_t *ptep)
  530. {
  531. }
  532. #endif
  533. #define update_mmu_cache_pmd(vma, address, pmd) do { } while (0)
  534. #endif
  535. #elif defined(CONFIG_SMP) /* !CONFIG_MMU */
  536. #ifndef __ASSEMBLY__
  537. #include <linux/mm_types.h>
  538. static inline void local_flush_tlb_all(void) { }
  539. static inline void local_flush_tlb_mm(struct mm_struct *mm) { }
  540. static inline void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr) { }
  541. static inline void local_flush_tlb_kernel_page(unsigned long kaddr) { }
  542. static inline void local_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end) { }
  543. static inline void local_flush_tlb_kernel_range(unsigned long start, unsigned long end) { }
  544. static inline void local_flush_bp_all(void) { }
  545. extern void flush_tlb_all(void);
  546. extern void flush_tlb_mm(struct mm_struct *mm);
  547. extern void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr);
  548. extern void flush_tlb_kernel_page(unsigned long kaddr);
  549. extern void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
  550. extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
  551. extern void flush_bp_all(void);
  552. #endif /* __ASSEMBLY__ */
  553. #endif
  554. #ifndef __ASSEMBLY__
  555. #ifdef CONFIG_ARM_ERRATA_798181
  556. extern void erratum_a15_798181_init(void);
  557. #else
  558. static inline void erratum_a15_798181_init(void) {}
  559. #endif
  560. extern bool (*erratum_a15_798181_handler)(void);
  561. static inline bool erratum_a15_798181(void)
  562. {
  563. if (unlikely(IS_ENABLED(CONFIG_ARM_ERRATA_798181) &&
  564. erratum_a15_798181_handler))
  565. return erratum_a15_798181_handler();
  566. return false;
  567. }
  568. #endif
  569. #endif