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