cache.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1999-2006 Helge Deller <deller@gmx.de> (07-13-1999)
  7. * Copyright (C) 1999 SuSE GmbH Nuernberg
  8. * Copyright (C) 2000 Philipp Rumpf (prumpf@tux.org)
  9. *
  10. * Cache and TLB management
  11. *
  12. */
  13. #include <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mm.h>
  16. #include <linux/module.h>
  17. #include <linux/seq_file.h>
  18. #include <linux/pagemap.h>
  19. #include <linux/sched.h>
  20. #include <linux/sched/mm.h>
  21. #include <asm/pdc.h>
  22. #include <asm/cache.h>
  23. #include <asm/cacheflush.h>
  24. #include <asm/tlbflush.h>
  25. #include <asm/page.h>
  26. #include <asm/pgalloc.h>
  27. #include <asm/processor.h>
  28. #include <asm/sections.h>
  29. #include <asm/shmparam.h>
  30. int split_tlb __read_mostly;
  31. int dcache_stride __read_mostly;
  32. int icache_stride __read_mostly;
  33. EXPORT_SYMBOL(dcache_stride);
  34. void flush_dcache_page_asm(unsigned long phys_addr, unsigned long vaddr);
  35. EXPORT_SYMBOL(flush_dcache_page_asm);
  36. void flush_icache_page_asm(unsigned long phys_addr, unsigned long vaddr);
  37. /* On some machines (e.g. ones with the Merced bus), there can be
  38. * only a single PxTLB broadcast at a time; this must be guaranteed
  39. * by software. We put a spinlock around all TLB flushes to
  40. * ensure this.
  41. */
  42. DEFINE_SPINLOCK(pa_tlb_lock);
  43. struct pdc_cache_info cache_info __read_mostly;
  44. #ifndef CONFIG_PA20
  45. static struct pdc_btlb_info btlb_info __read_mostly;
  46. #endif
  47. #ifdef CONFIG_SMP
  48. void
  49. flush_data_cache(void)
  50. {
  51. on_each_cpu(flush_data_cache_local, NULL, 1);
  52. }
  53. void
  54. flush_instruction_cache(void)
  55. {
  56. on_each_cpu(flush_instruction_cache_local, NULL, 1);
  57. }
  58. #endif
  59. void
  60. flush_cache_all_local(void)
  61. {
  62. flush_instruction_cache_local(NULL);
  63. flush_data_cache_local(NULL);
  64. }
  65. EXPORT_SYMBOL(flush_cache_all_local);
  66. /* Virtual address of pfn. */
  67. #define pfn_va(pfn) __va(PFN_PHYS(pfn))
  68. void
  69. update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep)
  70. {
  71. unsigned long pfn = pte_pfn(*ptep);
  72. struct page *page;
  73. /* We don't have pte special. As a result, we can be called with
  74. an invalid pfn and we don't need to flush the kernel dcache page.
  75. This occurs with FireGL card in C8000. */
  76. if (!pfn_valid(pfn))
  77. return;
  78. page = pfn_to_page(pfn);
  79. if (page_mapping(page) && test_bit(PG_dcache_dirty, &page->flags)) {
  80. flush_kernel_dcache_page_addr(pfn_va(pfn));
  81. clear_bit(PG_dcache_dirty, &page->flags);
  82. } else if (parisc_requires_coherency())
  83. flush_kernel_dcache_page_addr(pfn_va(pfn));
  84. }
  85. void
  86. show_cache_info(struct seq_file *m)
  87. {
  88. char buf[32];
  89. seq_printf(m, "I-cache\t\t: %ld KB\n",
  90. cache_info.ic_size/1024 );
  91. if (cache_info.dc_loop != 1)
  92. snprintf(buf, 32, "%lu-way associative", cache_info.dc_loop);
  93. seq_printf(m, "D-cache\t\t: %ld KB (%s%s, %s)\n",
  94. cache_info.dc_size/1024,
  95. (cache_info.dc_conf.cc_wt ? "WT":"WB"),
  96. (cache_info.dc_conf.cc_sh ? ", shared I/D":""),
  97. ((cache_info.dc_loop == 1) ? "direct mapped" : buf));
  98. seq_printf(m, "ITLB entries\t: %ld\n" "DTLB entries\t: %ld%s\n",
  99. cache_info.it_size,
  100. cache_info.dt_size,
  101. cache_info.dt_conf.tc_sh ? " - shared with ITLB":""
  102. );
  103. #ifndef CONFIG_PA20
  104. /* BTLB - Block TLB */
  105. if (btlb_info.max_size==0) {
  106. seq_printf(m, "BTLB\t\t: not supported\n" );
  107. } else {
  108. seq_printf(m,
  109. "BTLB fixed\t: max. %d pages, pagesize=%d (%dMB)\n"
  110. "BTLB fix-entr.\t: %d instruction, %d data (%d combined)\n"
  111. "BTLB var-entr.\t: %d instruction, %d data (%d combined)\n",
  112. btlb_info.max_size, (int)4096,
  113. btlb_info.max_size>>8,
  114. btlb_info.fixed_range_info.num_i,
  115. btlb_info.fixed_range_info.num_d,
  116. btlb_info.fixed_range_info.num_comb,
  117. btlb_info.variable_range_info.num_i,
  118. btlb_info.variable_range_info.num_d,
  119. btlb_info.variable_range_info.num_comb
  120. );
  121. }
  122. #endif
  123. }
  124. void __init
  125. parisc_cache_init(void)
  126. {
  127. if (pdc_cache_info(&cache_info) < 0)
  128. panic("parisc_cache_init: pdc_cache_info failed");
  129. #if 0
  130. printk("ic_size %lx dc_size %lx it_size %lx\n",
  131. cache_info.ic_size,
  132. cache_info.dc_size,
  133. cache_info.it_size);
  134. printk("DC base 0x%lx stride 0x%lx count 0x%lx loop 0x%lx\n",
  135. cache_info.dc_base,
  136. cache_info.dc_stride,
  137. cache_info.dc_count,
  138. cache_info.dc_loop);
  139. printk("dc_conf = 0x%lx alias %d blk %d line %d shift %d\n",
  140. *(unsigned long *) (&cache_info.dc_conf),
  141. cache_info.dc_conf.cc_alias,
  142. cache_info.dc_conf.cc_block,
  143. cache_info.dc_conf.cc_line,
  144. cache_info.dc_conf.cc_shift);
  145. printk(" wt %d sh %d cst %d hv %d\n",
  146. cache_info.dc_conf.cc_wt,
  147. cache_info.dc_conf.cc_sh,
  148. cache_info.dc_conf.cc_cst,
  149. cache_info.dc_conf.cc_hv);
  150. printk("IC base 0x%lx stride 0x%lx count 0x%lx loop 0x%lx\n",
  151. cache_info.ic_base,
  152. cache_info.ic_stride,
  153. cache_info.ic_count,
  154. cache_info.ic_loop);
  155. printk("IT base 0x%lx stride 0x%lx count 0x%lx loop 0x%lx off_base 0x%lx off_stride 0x%lx off_count 0x%lx\n",
  156. cache_info.it_sp_base,
  157. cache_info.it_sp_stride,
  158. cache_info.it_sp_count,
  159. cache_info.it_loop,
  160. cache_info.it_off_base,
  161. cache_info.it_off_stride,
  162. cache_info.it_off_count);
  163. printk("DT base 0x%lx stride 0x%lx count 0x%lx loop 0x%lx off_base 0x%lx off_stride 0x%lx off_count 0x%lx\n",
  164. cache_info.dt_sp_base,
  165. cache_info.dt_sp_stride,
  166. cache_info.dt_sp_count,
  167. cache_info.dt_loop,
  168. cache_info.dt_off_base,
  169. cache_info.dt_off_stride,
  170. cache_info.dt_off_count);
  171. printk("ic_conf = 0x%lx alias %d blk %d line %d shift %d\n",
  172. *(unsigned long *) (&cache_info.ic_conf),
  173. cache_info.ic_conf.cc_alias,
  174. cache_info.ic_conf.cc_block,
  175. cache_info.ic_conf.cc_line,
  176. cache_info.ic_conf.cc_shift);
  177. printk(" wt %d sh %d cst %d hv %d\n",
  178. cache_info.ic_conf.cc_wt,
  179. cache_info.ic_conf.cc_sh,
  180. cache_info.ic_conf.cc_cst,
  181. cache_info.ic_conf.cc_hv);
  182. printk("D-TLB conf: sh %d page %d cst %d aid %d sr %d\n",
  183. cache_info.dt_conf.tc_sh,
  184. cache_info.dt_conf.tc_page,
  185. cache_info.dt_conf.tc_cst,
  186. cache_info.dt_conf.tc_aid,
  187. cache_info.dt_conf.tc_sr);
  188. printk("I-TLB conf: sh %d page %d cst %d aid %d sr %d\n",
  189. cache_info.it_conf.tc_sh,
  190. cache_info.it_conf.tc_page,
  191. cache_info.it_conf.tc_cst,
  192. cache_info.it_conf.tc_aid,
  193. cache_info.it_conf.tc_sr);
  194. #endif
  195. split_tlb = 0;
  196. if (cache_info.dt_conf.tc_sh == 0 || cache_info.dt_conf.tc_sh == 2) {
  197. if (cache_info.dt_conf.tc_sh == 2)
  198. printk(KERN_WARNING "Unexpected TLB configuration. "
  199. "Will flush I/D separately (could be optimized).\n");
  200. split_tlb = 1;
  201. }
  202. /* "New and Improved" version from Jim Hull
  203. * (1 << (cc_block-1)) * (cc_line << (4 + cnf.cc_shift))
  204. * The following CAFL_STRIDE is an optimized version, see
  205. * http://lists.parisc-linux.org/pipermail/parisc-linux/2004-June/023625.html
  206. * http://lists.parisc-linux.org/pipermail/parisc-linux/2004-June/023671.html
  207. */
  208. #define CAFL_STRIDE(cnf) (cnf.cc_line << (3 + cnf.cc_block + cnf.cc_shift))
  209. dcache_stride = CAFL_STRIDE(cache_info.dc_conf);
  210. icache_stride = CAFL_STRIDE(cache_info.ic_conf);
  211. #undef CAFL_STRIDE
  212. #ifndef CONFIG_PA20
  213. if (pdc_btlb_info(&btlb_info) < 0) {
  214. memset(&btlb_info, 0, sizeof btlb_info);
  215. }
  216. #endif
  217. if ((boot_cpu_data.pdc.capabilities & PDC_MODEL_NVA_MASK) ==
  218. PDC_MODEL_NVA_UNSUPPORTED) {
  219. printk(KERN_WARNING "parisc_cache_init: Only equivalent aliasing supported!\n");
  220. #if 0
  221. panic("SMP kernel required to avoid non-equivalent aliasing");
  222. #endif
  223. }
  224. }
  225. void disable_sr_hashing(void)
  226. {
  227. int srhash_type, retval;
  228. unsigned long space_bits;
  229. switch (boot_cpu_data.cpu_type) {
  230. case pcx: /* We shouldn't get this far. setup.c should prevent it. */
  231. BUG();
  232. return;
  233. case pcxs:
  234. case pcxt:
  235. case pcxt_:
  236. srhash_type = SRHASH_PCXST;
  237. break;
  238. case pcxl:
  239. srhash_type = SRHASH_PCXL;
  240. break;
  241. case pcxl2: /* pcxl2 doesn't support space register hashing */
  242. return;
  243. default: /* Currently all PA2.0 machines use the same ins. sequence */
  244. srhash_type = SRHASH_PA20;
  245. break;
  246. }
  247. disable_sr_hashing_asm(srhash_type);
  248. retval = pdc_spaceid_bits(&space_bits);
  249. /* If this procedure isn't implemented, don't panic. */
  250. if (retval < 0 && retval != PDC_BAD_OPTION)
  251. panic("pdc_spaceid_bits call failed.\n");
  252. if (space_bits != 0)
  253. panic("SpaceID hashing is still on!\n");
  254. }
  255. static inline void
  256. __flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr,
  257. unsigned long physaddr)
  258. {
  259. preempt_disable();
  260. flush_dcache_page_asm(physaddr, vmaddr);
  261. if (vma->vm_flags & VM_EXEC)
  262. flush_icache_page_asm(physaddr, vmaddr);
  263. preempt_enable();
  264. }
  265. void flush_dcache_page(struct page *page)
  266. {
  267. struct address_space *mapping = page_mapping(page);
  268. struct vm_area_struct *mpnt;
  269. unsigned long offset;
  270. unsigned long addr, old_addr = 0;
  271. pgoff_t pgoff;
  272. if (mapping && !mapping_mapped(mapping)) {
  273. set_bit(PG_dcache_dirty, &page->flags);
  274. return;
  275. }
  276. flush_kernel_dcache_page(page);
  277. if (!mapping)
  278. return;
  279. pgoff = page->index;
  280. /* We have carefully arranged in arch_get_unmapped_area() that
  281. * *any* mappings of a file are always congruently mapped (whether
  282. * declared as MAP_PRIVATE or MAP_SHARED), so we only need
  283. * to flush one address here for them all to become coherent */
  284. flush_dcache_mmap_lock(mapping);
  285. vma_interval_tree_foreach(mpnt, &mapping->i_mmap, pgoff, pgoff) {
  286. offset = (pgoff - mpnt->vm_pgoff) << PAGE_SHIFT;
  287. addr = mpnt->vm_start + offset;
  288. /* The TLB is the engine of coherence on parisc: The
  289. * CPU is entitled to speculate any page with a TLB
  290. * mapping, so here we kill the mapping then flush the
  291. * page along a special flush only alias mapping.
  292. * This guarantees that the page is no-longer in the
  293. * cache for any process and nor may it be
  294. * speculatively read in (until the user or kernel
  295. * specifically accesses it, of course) */
  296. flush_tlb_page(mpnt, addr);
  297. if (old_addr == 0 || (old_addr & (SHM_COLOUR - 1))
  298. != (addr & (SHM_COLOUR - 1))) {
  299. __flush_cache_page(mpnt, addr, page_to_phys(page));
  300. if (old_addr)
  301. printk(KERN_ERR "INEQUIVALENT ALIASES 0x%lx and 0x%lx in file %pD\n", old_addr, addr, mpnt->vm_file);
  302. old_addr = addr;
  303. }
  304. }
  305. flush_dcache_mmap_unlock(mapping);
  306. }
  307. EXPORT_SYMBOL(flush_dcache_page);
  308. /* Defined in arch/parisc/kernel/pacache.S */
  309. EXPORT_SYMBOL(flush_kernel_dcache_range_asm);
  310. EXPORT_SYMBOL(flush_kernel_dcache_page_asm);
  311. EXPORT_SYMBOL(flush_data_cache_local);
  312. EXPORT_SYMBOL(flush_kernel_icache_range_asm);
  313. #define FLUSH_THRESHOLD 0x80000 /* 0.5MB */
  314. static unsigned long parisc_cache_flush_threshold __read_mostly = FLUSH_THRESHOLD;
  315. #define FLUSH_TLB_THRESHOLD (2*1024*1024) /* 2MB initial TLB threshold */
  316. static unsigned long parisc_tlb_flush_threshold __read_mostly = FLUSH_TLB_THRESHOLD;
  317. void __init parisc_setup_cache_timing(void)
  318. {
  319. unsigned long rangetime, alltime;
  320. unsigned long size, start;
  321. unsigned long threshold;
  322. alltime = mfctl(16);
  323. flush_data_cache();
  324. alltime = mfctl(16) - alltime;
  325. size = (unsigned long)(_end - _text);
  326. rangetime = mfctl(16);
  327. flush_kernel_dcache_range((unsigned long)_text, size);
  328. rangetime = mfctl(16) - rangetime;
  329. printk(KERN_DEBUG "Whole cache flush %lu cycles, flushing %lu bytes %lu cycles\n",
  330. alltime, size, rangetime);
  331. threshold = L1_CACHE_ALIGN(size * alltime / rangetime);
  332. if (threshold > cache_info.dc_size)
  333. threshold = cache_info.dc_size;
  334. if (threshold)
  335. parisc_cache_flush_threshold = threshold;
  336. printk(KERN_INFO "Cache flush threshold set to %lu KiB\n",
  337. parisc_cache_flush_threshold/1024);
  338. /* calculate TLB flush threshold */
  339. /* On SMP machines, skip the TLB measure of kernel text which
  340. * has been mapped as huge pages. */
  341. if (num_online_cpus() > 1 && !parisc_requires_coherency()) {
  342. threshold = max(cache_info.it_size, cache_info.dt_size);
  343. threshold *= PAGE_SIZE;
  344. threshold /= num_online_cpus();
  345. goto set_tlb_threshold;
  346. }
  347. alltime = mfctl(16);
  348. flush_tlb_all();
  349. alltime = mfctl(16) - alltime;
  350. size = 0;
  351. start = (unsigned long) _text;
  352. rangetime = mfctl(16);
  353. while (start < (unsigned long) _end) {
  354. flush_tlb_kernel_range(start, start + PAGE_SIZE);
  355. start += PAGE_SIZE;
  356. size += PAGE_SIZE;
  357. }
  358. rangetime = mfctl(16) - rangetime;
  359. printk(KERN_DEBUG "Whole TLB flush %lu cycles, flushing %lu bytes %lu cycles\n",
  360. alltime, size, rangetime);
  361. threshold = PAGE_ALIGN(num_online_cpus() * size * alltime / rangetime);
  362. set_tlb_threshold:
  363. if (threshold)
  364. parisc_tlb_flush_threshold = threshold;
  365. printk(KERN_INFO "TLB flush threshold set to %lu KiB\n",
  366. parisc_tlb_flush_threshold/1024);
  367. }
  368. extern void purge_kernel_dcache_page_asm(unsigned long);
  369. extern void clear_user_page_asm(void *, unsigned long);
  370. extern void copy_user_page_asm(void *, void *, unsigned long);
  371. void flush_kernel_dcache_page_addr(void *addr)
  372. {
  373. unsigned long flags;
  374. flush_kernel_dcache_page_asm(addr);
  375. purge_tlb_start(flags);
  376. pdtlb_kernel(addr);
  377. purge_tlb_end(flags);
  378. }
  379. EXPORT_SYMBOL(flush_kernel_dcache_page_addr);
  380. void copy_user_page(void *vto, void *vfrom, unsigned long vaddr,
  381. struct page *pg)
  382. {
  383. /* Copy using kernel mapping. No coherency is needed (all in
  384. kunmap) for the `to' page. However, the `from' page needs to
  385. be flushed through a mapping equivalent to the user mapping
  386. before it can be accessed through the kernel mapping. */
  387. preempt_disable();
  388. flush_dcache_page_asm(__pa(vfrom), vaddr);
  389. copy_page_asm(vto, vfrom);
  390. preempt_enable();
  391. }
  392. EXPORT_SYMBOL(copy_user_page);
  393. /* __flush_tlb_range()
  394. *
  395. * returns 1 if all TLBs were flushed.
  396. */
  397. int __flush_tlb_range(unsigned long sid, unsigned long start,
  398. unsigned long end)
  399. {
  400. unsigned long flags;
  401. if ((!IS_ENABLED(CONFIG_SMP) || !arch_irqs_disabled()) &&
  402. end - start >= parisc_tlb_flush_threshold) {
  403. flush_tlb_all();
  404. return 1;
  405. }
  406. /* Purge TLB entries for small ranges using the pdtlb and
  407. pitlb instructions. These instructions execute locally
  408. but cause a purge request to be broadcast to other TLBs. */
  409. if (likely(!split_tlb)) {
  410. while (start < end) {
  411. purge_tlb_start(flags);
  412. mtsp(sid, 1);
  413. pdtlb(start);
  414. purge_tlb_end(flags);
  415. start += PAGE_SIZE;
  416. }
  417. return 0;
  418. }
  419. /* split TLB case */
  420. while (start < end) {
  421. purge_tlb_start(flags);
  422. mtsp(sid, 1);
  423. pdtlb(start);
  424. pitlb(start);
  425. purge_tlb_end(flags);
  426. start += PAGE_SIZE;
  427. }
  428. return 0;
  429. }
  430. static void cacheflush_h_tmp_function(void *dummy)
  431. {
  432. flush_cache_all_local();
  433. }
  434. void flush_cache_all(void)
  435. {
  436. on_each_cpu(cacheflush_h_tmp_function, NULL, 1);
  437. }
  438. static inline unsigned long mm_total_size(struct mm_struct *mm)
  439. {
  440. struct vm_area_struct *vma;
  441. unsigned long usize = 0;
  442. for (vma = mm->mmap; vma; vma = vma->vm_next)
  443. usize += vma->vm_end - vma->vm_start;
  444. return usize;
  445. }
  446. static inline pte_t *get_ptep(pgd_t *pgd, unsigned long addr)
  447. {
  448. pte_t *ptep = NULL;
  449. if (!pgd_none(*pgd)) {
  450. pud_t *pud = pud_offset(pgd, addr);
  451. if (!pud_none(*pud)) {
  452. pmd_t *pmd = pmd_offset(pud, addr);
  453. if (!pmd_none(*pmd))
  454. ptep = pte_offset_map(pmd, addr);
  455. }
  456. }
  457. return ptep;
  458. }
  459. void flush_cache_mm(struct mm_struct *mm)
  460. {
  461. struct vm_area_struct *vma;
  462. pgd_t *pgd;
  463. /* Flushing the whole cache on each cpu takes forever on
  464. rp3440, etc. So, avoid it if the mm isn't too big. */
  465. if ((!IS_ENABLED(CONFIG_SMP) || !arch_irqs_disabled()) &&
  466. mm_total_size(mm) >= parisc_cache_flush_threshold) {
  467. if (mm->context)
  468. flush_tlb_all();
  469. flush_cache_all();
  470. return;
  471. }
  472. if (mm->context == mfsp(3)) {
  473. for (vma = mm->mmap; vma; vma = vma->vm_next) {
  474. flush_user_dcache_range_asm(vma->vm_start, vma->vm_end);
  475. if (vma->vm_flags & VM_EXEC)
  476. flush_user_icache_range_asm(vma->vm_start, vma->vm_end);
  477. flush_tlb_range(vma, vma->vm_start, vma->vm_end);
  478. }
  479. return;
  480. }
  481. pgd = mm->pgd;
  482. for (vma = mm->mmap; vma; vma = vma->vm_next) {
  483. unsigned long addr;
  484. for (addr = vma->vm_start; addr < vma->vm_end;
  485. addr += PAGE_SIZE) {
  486. unsigned long pfn;
  487. pte_t *ptep = get_ptep(pgd, addr);
  488. if (!ptep)
  489. continue;
  490. pfn = pte_pfn(*ptep);
  491. if (!pfn_valid(pfn))
  492. continue;
  493. if (unlikely(mm->context))
  494. flush_tlb_page(vma, addr);
  495. __flush_cache_page(vma, addr, PFN_PHYS(pfn));
  496. }
  497. }
  498. }
  499. void flush_cache_range(struct vm_area_struct *vma,
  500. unsigned long start, unsigned long end)
  501. {
  502. pgd_t *pgd;
  503. unsigned long addr;
  504. if ((!IS_ENABLED(CONFIG_SMP) || !arch_irqs_disabled()) &&
  505. end - start >= parisc_cache_flush_threshold) {
  506. if (vma->vm_mm->context)
  507. flush_tlb_range(vma, start, end);
  508. flush_cache_all();
  509. return;
  510. }
  511. if (vma->vm_mm->context == mfsp(3)) {
  512. flush_user_dcache_range_asm(start, end);
  513. if (vma->vm_flags & VM_EXEC)
  514. flush_user_icache_range_asm(start, end);
  515. flush_tlb_range(vma, start, end);
  516. return;
  517. }
  518. pgd = vma->vm_mm->pgd;
  519. for (addr = vma->vm_start; addr < vma->vm_end; addr += PAGE_SIZE) {
  520. unsigned long pfn;
  521. pte_t *ptep = get_ptep(pgd, addr);
  522. if (!ptep)
  523. continue;
  524. pfn = pte_pfn(*ptep);
  525. if (pfn_valid(pfn)) {
  526. if (unlikely(vma->vm_mm->context))
  527. flush_tlb_page(vma, addr);
  528. __flush_cache_page(vma, addr, PFN_PHYS(pfn));
  529. }
  530. }
  531. }
  532. void
  533. flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn)
  534. {
  535. if (pfn_valid(pfn)) {
  536. if (likely(vma->vm_mm->context))
  537. flush_tlb_page(vma, vmaddr);
  538. __flush_cache_page(vma, vmaddr, PFN_PHYS(pfn));
  539. }
  540. }
  541. void flush_kernel_vmap_range(void *vaddr, int size)
  542. {
  543. unsigned long start = (unsigned long)vaddr;
  544. unsigned long end = start + size;
  545. if ((!IS_ENABLED(CONFIG_SMP) || !arch_irqs_disabled()) &&
  546. (unsigned long)size >= parisc_cache_flush_threshold) {
  547. flush_tlb_kernel_range(start, end);
  548. flush_data_cache();
  549. return;
  550. }
  551. flush_kernel_dcache_range_asm(start, end);
  552. flush_tlb_kernel_range(start, end);
  553. }
  554. EXPORT_SYMBOL(flush_kernel_vmap_range);
  555. void invalidate_kernel_vmap_range(void *vaddr, int size)
  556. {
  557. unsigned long start = (unsigned long)vaddr;
  558. unsigned long end = start + size;
  559. if ((!IS_ENABLED(CONFIG_SMP) || !arch_irqs_disabled()) &&
  560. (unsigned long)size >= parisc_cache_flush_threshold) {
  561. flush_tlb_kernel_range(start, end);
  562. flush_data_cache();
  563. return;
  564. }
  565. purge_kernel_dcache_range_asm(start, end);
  566. flush_tlb_kernel_range(start, end);
  567. }
  568. EXPORT_SYMBOL(invalidate_kernel_vmap_range);