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
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)
10 * Cache and TLB management
14 #include <linux/init.h>
15 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/seq_file.h>
19 #include <linux/pagemap.h>
20 #include <linux/sched.h>
21 #include <linux/sched/mm.h>
22 #include <linux/syscalls.h>
24 #include <asm/cache.h>
25 #include <asm/cacheflush.h>
26 #include <asm/tlbflush.h>
28 #include <asm/processor.h>
29 #include <asm/sections.h>
30 #include <asm/shmparam.h>
31 #include <asm/mmu_context.h>
32 #include <asm/cachectl.h>
34 int split_tlb __ro_after_init;
35 int dcache_stride __ro_after_init;
36 int icache_stride __ro_after_init;
37 EXPORT_SYMBOL(dcache_stride);
39 void flush_dcache_page_asm(unsigned long phys_addr, unsigned long vaddr);
40 EXPORT_SYMBOL(flush_dcache_page_asm);
41 void purge_dcache_page_asm(unsigned long phys_addr, unsigned long vaddr);
42 void flush_icache_page_asm(unsigned long phys_addr, unsigned long vaddr);
44 /* Internal implementation in arch/parisc/kernel/pacache.S */
45 void flush_data_cache_local(void *); /* flushes local data-cache only */
46 void flush_instruction_cache_local(void); /* flushes local code-cache only */
48 /* On some machines (i.e., ones with the Merced bus), there can be
49 * only a single PxTLB broadcast at a time; this must be guaranteed
50 * by software. We need a spinlock around all TLB flushes to ensure
53 DEFINE_SPINLOCK(pa_tlb_flush_lock);
55 #if defined(CONFIG_64BIT) && defined(CONFIG_SMP)
56 int pa_serialize_tlb_flushes __ro_after_init;
59 struct pdc_cache_info cache_info __ro_after_init;
61 struct pdc_btlb_info btlb_info;
64 DEFINE_STATIC_KEY_TRUE(parisc_has_cache);
65 DEFINE_STATIC_KEY_TRUE(parisc_has_dcache);
66 DEFINE_STATIC_KEY_TRUE(parisc_has_icache);
68 static void cache_flush_local_cpu(void *dummy)
70 if (static_branch_likely(&parisc_has_icache))
71 flush_instruction_cache_local();
72 if (static_branch_likely(&parisc_has_dcache))
73 flush_data_cache_local(NULL);
76 void flush_cache_all_local(void)
78 cache_flush_local_cpu(NULL);
81 void flush_cache_all(void)
83 if (static_branch_likely(&parisc_has_cache))
84 on_each_cpu(cache_flush_local_cpu, NULL, 1);
87 static inline void flush_data_cache(void)
89 if (static_branch_likely(&parisc_has_dcache))
90 on_each_cpu(flush_data_cache_local, NULL, 1);
94 /* Kernel virtual address of pfn. */
95 #define pfn_va(pfn) __va(PFN_PHYS(pfn))
97 void __update_cache(pte_t pte)
99 unsigned long pfn = pte_pfn(pte);
103 /* We don't have pte special. As a result, we can be called with
104 an invalid pfn and we don't need to flush the kernel dcache page.
105 This occurs with FireGL card in C8000. */
109 folio = page_folio(pfn_to_page(pfn));
110 pfn = folio_pfn(folio);
111 nr = folio_nr_pages(folio);
112 if (folio_flush_mapping(folio) &&
113 test_bit(PG_dcache_dirty, &folio->flags)) {
115 flush_kernel_dcache_page_addr(pfn_va(pfn + nr));
116 clear_bit(PG_dcache_dirty, &folio->flags);
117 } else if (parisc_requires_coherency())
119 flush_kernel_dcache_page_addr(pfn_va(pfn + nr));
123 show_cache_info(struct seq_file *m)
127 seq_printf(m, "I-cache\t\t: %ld KB\n",
128 cache_info.ic_size/1024 );
129 if (cache_info.dc_loop != 1)
130 snprintf(buf, 32, "%lu-way associative", cache_info.dc_loop);
131 seq_printf(m, "D-cache\t\t: %ld KB (%s%s, %s, alias=%d)\n",
132 cache_info.dc_size/1024,
133 (cache_info.dc_conf.cc_wt ? "WT":"WB"),
134 (cache_info.dc_conf.cc_sh ? ", shared I/D":""),
135 ((cache_info.dc_loop == 1) ? "direct mapped" : buf),
136 cache_info.dc_conf.cc_alias
138 seq_printf(m, "ITLB entries\t: %ld\n" "DTLB entries\t: %ld%s\n",
141 cache_info.dt_conf.tc_sh ? " - shared with ITLB":""
145 /* BTLB - Block TLB */
146 if (btlb_info.max_size==0) {
147 seq_printf(m, "BTLB\t\t: not supported\n" );
150 "BTLB fixed\t: max. %d pages, pagesize=%d (%dMB)\n"
151 "BTLB fix-entr.\t: %d instruction, %d data (%d combined)\n"
152 "BTLB var-entr.\t: %d instruction, %d data (%d combined)\n",
153 btlb_info.max_size, (int)4096,
154 btlb_info.max_size>>8,
155 btlb_info.fixed_range_info.num_i,
156 btlb_info.fixed_range_info.num_d,
157 btlb_info.fixed_range_info.num_comb,
158 btlb_info.variable_range_info.num_i,
159 btlb_info.variable_range_info.num_d,
160 btlb_info.variable_range_info.num_comb
167 parisc_cache_init(void)
169 if (pdc_cache_info(&cache_info) < 0)
170 panic("parisc_cache_init: pdc_cache_info failed");
173 printk("ic_size %lx dc_size %lx it_size %lx\n",
178 printk("DC base 0x%lx stride 0x%lx count 0x%lx loop 0x%lx\n",
180 cache_info.dc_stride,
184 printk("dc_conf = 0x%lx alias %d blk %d line %d shift %d\n",
185 *(unsigned long *) (&cache_info.dc_conf),
186 cache_info.dc_conf.cc_alias,
187 cache_info.dc_conf.cc_block,
188 cache_info.dc_conf.cc_line,
189 cache_info.dc_conf.cc_shift);
190 printk(" wt %d sh %d cst %d hv %d\n",
191 cache_info.dc_conf.cc_wt,
192 cache_info.dc_conf.cc_sh,
193 cache_info.dc_conf.cc_cst,
194 cache_info.dc_conf.cc_hv);
196 printk("IC base 0x%lx stride 0x%lx count 0x%lx loop 0x%lx\n",
198 cache_info.ic_stride,
202 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",
203 cache_info.it_sp_base,
204 cache_info.it_sp_stride,
205 cache_info.it_sp_count,
207 cache_info.it_off_base,
208 cache_info.it_off_stride,
209 cache_info.it_off_count);
211 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",
212 cache_info.dt_sp_base,
213 cache_info.dt_sp_stride,
214 cache_info.dt_sp_count,
216 cache_info.dt_off_base,
217 cache_info.dt_off_stride,
218 cache_info.dt_off_count);
220 printk("ic_conf = 0x%lx alias %d blk %d line %d shift %d\n",
221 *(unsigned long *) (&cache_info.ic_conf),
222 cache_info.ic_conf.cc_alias,
223 cache_info.ic_conf.cc_block,
224 cache_info.ic_conf.cc_line,
225 cache_info.ic_conf.cc_shift);
226 printk(" wt %d sh %d cst %d hv %d\n",
227 cache_info.ic_conf.cc_wt,
228 cache_info.ic_conf.cc_sh,
229 cache_info.ic_conf.cc_cst,
230 cache_info.ic_conf.cc_hv);
232 printk("D-TLB conf: sh %d page %d cst %d aid %d sr %d\n",
233 cache_info.dt_conf.tc_sh,
234 cache_info.dt_conf.tc_page,
235 cache_info.dt_conf.tc_cst,
236 cache_info.dt_conf.tc_aid,
237 cache_info.dt_conf.tc_sr);
239 printk("I-TLB conf: sh %d page %d cst %d aid %d sr %d\n",
240 cache_info.it_conf.tc_sh,
241 cache_info.it_conf.tc_page,
242 cache_info.it_conf.tc_cst,
243 cache_info.it_conf.tc_aid,
244 cache_info.it_conf.tc_sr);
248 if (cache_info.dt_conf.tc_sh == 0 || cache_info.dt_conf.tc_sh == 2) {
249 if (cache_info.dt_conf.tc_sh == 2)
250 printk(KERN_WARNING "Unexpected TLB configuration. "
251 "Will flush I/D separately (could be optimized).\n");
256 /* "New and Improved" version from Jim Hull
257 * (1 << (cc_block-1)) * (cc_line << (4 + cnf.cc_shift))
258 * The following CAFL_STRIDE is an optimized version, see
259 * http://lists.parisc-linux.org/pipermail/parisc-linux/2004-June/023625.html
260 * http://lists.parisc-linux.org/pipermail/parisc-linux/2004-June/023671.html
262 #define CAFL_STRIDE(cnf) (cnf.cc_line << (3 + cnf.cc_block + cnf.cc_shift))
263 dcache_stride = CAFL_STRIDE(cache_info.dc_conf);
264 icache_stride = CAFL_STRIDE(cache_info.ic_conf);
267 if ((boot_cpu_data.pdc.capabilities & PDC_MODEL_NVA_MASK) ==
268 PDC_MODEL_NVA_UNSUPPORTED) {
269 printk(KERN_WARNING "parisc_cache_init: Only equivalent aliasing supported!\n");
271 panic("SMP kernel required to avoid non-equivalent aliasing");
276 void disable_sr_hashing(void)
278 int srhash_type, retval;
279 unsigned long space_bits;
281 switch (boot_cpu_data.cpu_type) {
282 case pcx: /* We shouldn't get this far. setup.c should prevent it. */
289 srhash_type = SRHASH_PCXST;
293 srhash_type = SRHASH_PCXL;
296 case pcxl2: /* pcxl2 doesn't support space register hashing */
299 default: /* Currently all PA2.0 machines use the same ins. sequence */
300 srhash_type = SRHASH_PA20;
304 disable_sr_hashing_asm(srhash_type);
306 retval = pdc_spaceid_bits(&space_bits);
307 /* If this procedure isn't implemented, don't panic. */
308 if (retval < 0 && retval != PDC_BAD_OPTION)
309 panic("pdc_spaceid_bits call failed.\n");
311 panic("SpaceID hashing is still on!\n");
315 __flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr,
316 unsigned long physaddr)
318 if (!static_branch_likely(&parisc_has_cache))
321 flush_dcache_page_asm(physaddr, vmaddr);
322 if (vma->vm_flags & VM_EXEC)
323 flush_icache_page_asm(physaddr, vmaddr);
327 static void flush_user_cache_page(struct vm_area_struct *vma, unsigned long vmaddr)
329 unsigned long flags, space, pgd, prot;
330 #ifdef CONFIG_TLB_PTLOCK
331 unsigned long pgd_lock;
338 /* Set context for flush */
339 local_irq_save(flags);
341 space = mfsp(SR_USER);
343 #ifdef CONFIG_TLB_PTLOCK
344 pgd_lock = mfctl(28);
346 switch_mm_irqs_off(NULL, vma->vm_mm, NULL);
347 local_irq_restore(flags);
349 flush_user_dcache_range_asm(vmaddr, vmaddr + PAGE_SIZE);
350 if (vma->vm_flags & VM_EXEC)
351 flush_user_icache_range_asm(vmaddr, vmaddr + PAGE_SIZE);
352 flush_tlb_page(vma, vmaddr);
354 /* Restore previous context */
355 local_irq_save(flags);
356 #ifdef CONFIG_TLB_PTLOCK
360 mtsp(space, SR_USER);
362 local_irq_restore(flags);
367 void flush_icache_pages(struct vm_area_struct *vma, struct page *page,
370 void *kaddr = page_address(page);
373 flush_kernel_dcache_page_addr(kaddr);
374 flush_kernel_icache_page(kaddr);
381 static inline pte_t *get_ptep(struct mm_struct *mm, unsigned long addr)
384 pgd_t *pgd = mm->pgd;
389 if (!pgd_none(*pgd)) {
390 p4d = p4d_offset(pgd, addr);
391 if (!p4d_none(*p4d)) {
392 pud = pud_offset(p4d, addr);
393 if (!pud_none(*pud)) {
394 pmd = pmd_offset(pud, addr);
396 ptep = pte_offset_map(pmd, addr);
403 static inline bool pte_needs_flush(pte_t pte)
405 return (pte_val(pte) & (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_NO_CACHE))
406 == (_PAGE_PRESENT | _PAGE_ACCESSED);
409 void flush_dcache_folio(struct folio *folio)
411 struct address_space *mapping = folio_flush_mapping(folio);
412 struct vm_area_struct *vma;
413 unsigned long addr, old_addr = 0;
415 unsigned long count = 0;
416 unsigned long i, nr, flags;
419 if (mapping && !mapping_mapped(mapping)) {
420 set_bit(PG_dcache_dirty, &folio->flags);
424 nr = folio_nr_pages(folio);
425 kaddr = folio_address(folio);
426 for (i = 0; i < nr; i++)
427 flush_kernel_dcache_page_addr(kaddr + i * PAGE_SIZE);
432 pgoff = folio->index;
435 * We have carefully arranged in arch_get_unmapped_area() that
436 * *any* mappings of a file are always congruently mapped (whether
437 * declared as MAP_PRIVATE or MAP_SHARED), so we only need
438 * to flush one address here for them all to become coherent
439 * on machines that support equivalent aliasing
441 flush_dcache_mmap_lock_irqsave(mapping, flags);
442 vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff + nr - 1) {
443 unsigned long offset = pgoff - vma->vm_pgoff;
444 unsigned long pfn = folio_pfn(folio);
446 addr = vma->vm_start;
447 nr = folio_nr_pages(folio);
452 addr += offset * PAGE_SIZE;
454 if (addr + nr * PAGE_SIZE > vma->vm_end)
455 nr = (vma->vm_end - addr) / PAGE_SIZE;
457 if (parisc_requires_coherency()) {
458 for (i = 0; i < nr; i++) {
459 pte_t *ptep = get_ptep(vma->vm_mm,
460 addr + i * PAGE_SIZE);
463 if (pte_needs_flush(*ptep))
464 flush_user_cache_page(vma,
465 addr + i * PAGE_SIZE);
466 /* Optimise accesses to the same table? */
471 * The TLB is the engine of coherence on parisc:
472 * The CPU is entitled to speculate any page
473 * with a TLB mapping, so here we kill the
474 * mapping then flush the page along a special
475 * flush only alias mapping. This guarantees that
476 * the page is no-longer in the cache for any
477 * process and nor may it be speculatively read
478 * in (until the user or kernel specifically
479 * accesses it, of course)
481 for (i = 0; i < nr; i++)
482 flush_tlb_page(vma, addr + i * PAGE_SIZE);
483 if (old_addr == 0 || (old_addr & (SHM_COLOUR - 1))
484 != (addr & (SHM_COLOUR - 1))) {
485 for (i = 0; i < nr; i++)
486 __flush_cache_page(vma,
487 addr + i * PAGE_SIZE,
488 (pfn + i) * PAGE_SIZE);
490 * Software is allowed to have any number
491 * of private mappings to a page.
493 if (!(vma->vm_flags & VM_SHARED))
496 pr_err("INEQUIVALENT ALIASES 0x%lx and 0x%lx in file %pD\n",
497 old_addr, addr, vma->vm_file);
498 if (nr == folio_nr_pages(folio))
502 WARN_ON(++count == 4096);
504 flush_dcache_mmap_unlock_irqrestore(mapping, flags);
506 EXPORT_SYMBOL(flush_dcache_folio);
508 /* Defined in arch/parisc/kernel/pacache.S */
509 EXPORT_SYMBOL(flush_kernel_dcache_range_asm);
510 EXPORT_SYMBOL(flush_kernel_icache_range_asm);
512 #define FLUSH_THRESHOLD 0x80000 /* 0.5MB */
513 static unsigned long parisc_cache_flush_threshold __ro_after_init = FLUSH_THRESHOLD;
515 #define FLUSH_TLB_THRESHOLD (16*1024) /* 16 KiB minimum TLB threshold */
516 static unsigned long parisc_tlb_flush_threshold __ro_after_init = ~0UL;
518 void __init parisc_setup_cache_timing(void)
520 unsigned long rangetime, alltime;
522 unsigned long threshold, threshold2;
526 alltime = mfctl(16) - alltime;
528 size = (unsigned long)(_end - _text);
529 rangetime = mfctl(16);
530 flush_kernel_dcache_range((unsigned long)_text, size);
531 rangetime = mfctl(16) - rangetime;
533 printk(KERN_DEBUG "Whole cache flush %lu cycles, flushing %lu bytes %lu cycles\n",
534 alltime, size, rangetime);
536 threshold = L1_CACHE_ALIGN((unsigned long)((uint64_t)size * alltime / rangetime));
537 pr_info("Calculated flush threshold is %lu KiB\n",
541 * The threshold computed above isn't very reliable. The following
542 * heuristic works reasonably well on c8000/rp3440.
544 threshold2 = cache_info.dc_size * num_online_cpus();
545 parisc_cache_flush_threshold = threshold2;
546 printk(KERN_INFO "Cache flush threshold set to %lu KiB\n",
547 parisc_cache_flush_threshold/1024);
549 /* calculate TLB flush threshold */
551 /* On SMP machines, skip the TLB measure of kernel text which
552 * has been mapped as huge pages. */
553 if (num_online_cpus() > 1 && !parisc_requires_coherency()) {
554 threshold = max(cache_info.it_size, cache_info.dt_size);
555 threshold *= PAGE_SIZE;
556 threshold /= num_online_cpus();
557 goto set_tlb_threshold;
560 size = (unsigned long)_end - (unsigned long)_text;
561 rangetime = mfctl(16);
562 flush_tlb_kernel_range((unsigned long)_text, (unsigned long)_end);
563 rangetime = mfctl(16) - rangetime;
567 alltime = mfctl(16) - alltime;
569 printk(KERN_INFO "Whole TLB flush %lu cycles, Range flush %lu bytes %lu cycles\n",
570 alltime, size, rangetime);
572 threshold = PAGE_ALIGN((num_online_cpus() * size * alltime) / rangetime);
573 printk(KERN_INFO "Calculated TLB flush threshold %lu KiB\n",
577 if (threshold > FLUSH_TLB_THRESHOLD)
578 parisc_tlb_flush_threshold = threshold;
580 parisc_tlb_flush_threshold = FLUSH_TLB_THRESHOLD;
582 printk(KERN_INFO "TLB flush threshold set to %lu KiB\n",
583 parisc_tlb_flush_threshold/1024);
586 extern void purge_kernel_dcache_page_asm(unsigned long);
587 extern void clear_user_page_asm(void *, unsigned long);
588 extern void copy_user_page_asm(void *, void *, unsigned long);
590 void flush_kernel_dcache_page_addr(const void *addr)
594 flush_kernel_dcache_page_asm(addr);
595 purge_tlb_start(flags);
596 pdtlb(SR_KERNEL, addr);
597 purge_tlb_end(flags);
599 EXPORT_SYMBOL(flush_kernel_dcache_page_addr);
601 static void flush_cache_page_if_present(struct vm_area_struct *vma,
602 unsigned long vmaddr, unsigned long pfn)
604 bool needs_flush = false;
608 * The pte check is racy and sometimes the flush will trigger
609 * a non-access TLB miss. Hopefully, the page has already been
612 ptep = get_ptep(vma->vm_mm, vmaddr);
614 needs_flush = pte_needs_flush(*ptep);
618 flush_cache_page(vma, vmaddr, pfn);
621 void copy_user_highpage(struct page *to, struct page *from,
622 unsigned long vaddr, struct vm_area_struct *vma)
626 kfrom = kmap_local_page(from);
627 kto = kmap_local_page(to);
628 flush_cache_page_if_present(vma, vaddr, page_to_pfn(from));
629 copy_page_asm(kto, kfrom);
634 void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
635 unsigned long user_vaddr, void *dst, void *src, int len)
637 flush_cache_page_if_present(vma, user_vaddr, page_to_pfn(page));
638 memcpy(dst, src, len);
639 flush_kernel_dcache_range_asm((unsigned long)dst, (unsigned long)dst + len);
642 void copy_from_user_page(struct vm_area_struct *vma, struct page *page,
643 unsigned long user_vaddr, void *dst, void *src, int len)
645 flush_cache_page_if_present(vma, user_vaddr, page_to_pfn(page));
646 memcpy(dst, src, len);
649 /* __flush_tlb_range()
651 * returns 1 if all TLBs were flushed.
653 int __flush_tlb_range(unsigned long sid, unsigned long start,
658 if ((!IS_ENABLED(CONFIG_SMP) || !arch_irqs_disabled()) &&
659 end - start >= parisc_tlb_flush_threshold) {
664 /* Purge TLB entries for small ranges using the pdtlb and
665 pitlb instructions. These instructions execute locally
666 but cause a purge request to be broadcast to other TLBs. */
667 while (start < end) {
668 purge_tlb_start(flags);
670 pdtlb(SR_TEMP1, start);
671 pitlb(SR_TEMP1, start);
672 purge_tlb_end(flags);
678 static void flush_cache_pages(struct vm_area_struct *vma, unsigned long start, unsigned long end)
680 unsigned long addr, pfn;
683 for (addr = start; addr < end; addr += PAGE_SIZE) {
684 bool needs_flush = false;
686 * The vma can contain pages that aren't present. Although
687 * the pte search is expensive, we need the pte to find the
688 * page pfn and to check whether the page should be flushed.
690 ptep = get_ptep(vma->vm_mm, addr);
692 needs_flush = pte_needs_flush(*ptep);
693 pfn = pte_pfn(*ptep);
697 if (parisc_requires_coherency()) {
698 flush_user_cache_page(vma, addr);
700 if (WARN_ON(!pfn_valid(pfn)))
702 __flush_cache_page(vma, addr, PFN_PHYS(pfn));
708 static inline unsigned long mm_total_size(struct mm_struct *mm)
710 struct vm_area_struct *vma;
711 unsigned long usize = 0;
712 VMA_ITERATOR(vmi, mm, 0);
714 for_each_vma(vmi, vma) {
715 if (usize >= parisc_cache_flush_threshold)
717 usize += vma->vm_end - vma->vm_start;
722 void flush_cache_mm(struct mm_struct *mm)
724 struct vm_area_struct *vma;
725 VMA_ITERATOR(vmi, mm, 0);
728 * Flushing the whole cache on each cpu takes forever on
729 * rp3440, etc. So, avoid it if the mm isn't too big.
731 * Note that we must flush the entire cache on machines
732 * with aliasing caches to prevent random segmentation
735 if (!parisc_requires_coherency()
736 || mm_total_size(mm) >= parisc_cache_flush_threshold) {
737 if (WARN_ON(IS_ENABLED(CONFIG_SMP) && arch_irqs_disabled()))
745 for_each_vma(vmi, vma)
746 flush_cache_pages(vma, vma->vm_start, vma->vm_end);
749 void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
751 if (!parisc_requires_coherency()
752 || end - start >= parisc_cache_flush_threshold) {
753 if (WARN_ON(IS_ENABLED(CONFIG_SMP) && arch_irqs_disabled()))
755 flush_tlb_range(vma, start, end);
760 flush_cache_pages(vma, start, end);
763 void flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn)
765 if (WARN_ON(!pfn_valid(pfn)))
767 if (parisc_requires_coherency())
768 flush_user_cache_page(vma, vmaddr);
770 __flush_cache_page(vma, vmaddr, PFN_PHYS(pfn));
773 void flush_anon_page(struct vm_area_struct *vma, struct page *page, unsigned long vmaddr)
778 if (parisc_requires_coherency()) {
779 if (vma->vm_flags & VM_SHARED)
782 flush_user_cache_page(vma, vmaddr);
786 flush_tlb_page(vma, vmaddr);
788 flush_dcache_page_asm(page_to_phys(page), vmaddr);
792 void flush_kernel_vmap_range(void *vaddr, int size)
794 unsigned long start = (unsigned long)vaddr;
795 unsigned long end = start + size;
797 if ((!IS_ENABLED(CONFIG_SMP) || !arch_irqs_disabled()) &&
798 (unsigned long)size >= parisc_cache_flush_threshold) {
799 flush_tlb_kernel_range(start, end);
804 flush_kernel_dcache_range_asm(start, end);
805 flush_tlb_kernel_range(start, end);
807 EXPORT_SYMBOL(flush_kernel_vmap_range);
809 void invalidate_kernel_vmap_range(void *vaddr, int size)
811 unsigned long start = (unsigned long)vaddr;
812 unsigned long end = start + size;
814 /* Ensure DMA is complete */
817 if ((!IS_ENABLED(CONFIG_SMP) || !arch_irqs_disabled()) &&
818 (unsigned long)size >= parisc_cache_flush_threshold) {
819 flush_tlb_kernel_range(start, end);
824 purge_kernel_dcache_range_asm(start, end);
825 flush_tlb_kernel_range(start, end);
827 EXPORT_SYMBOL(invalidate_kernel_vmap_range);
830 SYSCALL_DEFINE3(cacheflush, unsigned long, addr, unsigned long, bytes,
833 unsigned long start, end;
834 ASM_EXCEPTIONTABLE_VAR(error);
838 if (!access_ok((void __user *) addr, bytes))
843 if (cache & DCACHE) {
845 __asm__ __volatile__ (
847 "1: cmpb,*<<,n %0,%2,1b\n"
849 "1: cmpb,<<,n %0,%2,1b\n"
853 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 2b, "%1")
854 : "+r" (start), "+r" (error)
855 : "r" (end), "r" (dcache_stride), "i" (SR_USER));
858 if (cache & ICACHE && error == 0) {
860 __asm__ __volatile__ (
862 "1: cmpb,*<<,n %0,%2,1b\n"
864 "1: cmpb,<<,n %0,%2,1b\n"
868 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 2b, "%1")
869 : "+r" (start), "+r" (error)
870 : "r" (end), "r" (icache_stride), "i" (SR_USER));