cache.c 18 KB

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