1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _PARISC_CACHEFLUSH_H 3 #define _PARISC_CACHEFLUSH_H 4 5 #include <linux/mm.h> 6 #include <linux/uaccess.h> 7 #include <asm/tlbflush.h> 8 9 /* The usual comment is "Caches aren't brain-dead on the <architecture>". 10 * Unfortunately, that doesn't apply to PA-RISC. */ 11 12 /* Internal implementation */ 13 void flush_data_cache_local(void *); /* flushes local data-cache only */ 14 void flush_instruction_cache_local(void *); /* flushes local code-cache only */ 15 #ifdef CONFIG_SMP 16 void flush_data_cache(void); /* flushes data-cache only (all processors) */ 17 void flush_instruction_cache(void); /* flushes i-cache only (all processors) */ 18 #else 19 #define flush_data_cache() flush_data_cache_local(NULL) 20 #define flush_instruction_cache() flush_instruction_cache_local(NULL) 21 #endif 22 23 #define flush_cache_dup_mm(mm) flush_cache_mm(mm) 24 25 void flush_user_icache_range_asm(unsigned long, unsigned long); 26 void flush_kernel_icache_range_asm(unsigned long, unsigned long); 27 void flush_user_dcache_range_asm(unsigned long, unsigned long); 28 void flush_kernel_dcache_range_asm(unsigned long, unsigned long); 29 void purge_kernel_dcache_range_asm(unsigned long, unsigned long); 30 void flush_kernel_dcache_page_asm(void *); 31 void flush_kernel_icache_page(void *); 32 33 /* Cache flush operations */ 34 35 void flush_cache_all_local(void); 36 void flush_cache_all(void); 37 void flush_cache_mm(struct mm_struct *mm); 38 39 void flush_kernel_dcache_page_addr(void *addr); 40 41 #define flush_kernel_dcache_range(start,size) \ 42 flush_kernel_dcache_range_asm((start), (start)+(size)); 43 44 #define ARCH_IMPLEMENTS_FLUSH_KERNEL_VMAP_RANGE 1 45 void flush_kernel_vmap_range(void *vaddr, int size); 46 void invalidate_kernel_vmap_range(void *vaddr, int size); 47 48 #define flush_cache_vmap(start, end) flush_cache_all() 49 #define flush_cache_vunmap(start, end) flush_cache_all() 50 51 #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 52 void flush_dcache_page(struct page *page); 53 void flush_dcache_folio(struct folio *folio); 54 55 #define flush_dcache_mmap_lock(mapping) xa_lock_irq(&mapping->i_pages) 56 #define flush_dcache_mmap_unlock(mapping) xa_unlock_irq(&mapping->i_pages) 57 58 #define flush_icache_page(vma,page) do { \ 59 flush_kernel_dcache_page_addr(page_address(page)); \ 60 flush_kernel_icache_page(page_address(page)); \ 61 } while (0) 62 63 #define flush_icache_range(s,e) do { \ 64 flush_kernel_dcache_range_asm(s,e); \ 65 flush_kernel_icache_range_asm(s,e); \ 66 } while (0) 67 68 #define copy_to_user_page(vma, page, vaddr, dst, src, len) \ 69 do { \ 70 flush_cache_page(vma, vaddr, page_to_pfn(page)); \ 71 memcpy(dst, src, len); \ 72 flush_kernel_dcache_range_asm((unsigned long)dst, (unsigned long)dst + len); \ 73 } while (0) 74 75 #define copy_from_user_page(vma, page, vaddr, dst, src, len) \ 76 do { \ 77 flush_cache_page(vma, vaddr, page_to_pfn(page)); \ 78 memcpy(dst, src, len); \ 79 } while (0) 80 81 void flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn); 82 void flush_cache_range(struct vm_area_struct *vma, 83 unsigned long start, unsigned long end); 84 85 /* defined in pacache.S exported in cache.c used by flush_anon_page */ 86 void flush_dcache_page_asm(unsigned long phys_addr, unsigned long vaddr); 87 88 #define ARCH_HAS_FLUSH_ANON_PAGE 89 static inline void 90 flush_anon_page(struct vm_area_struct *vma, struct page *page, unsigned long vmaddr) 91 { 92 if (PageAnon(page)) { 93 flush_tlb_page(vma, vmaddr); 94 preempt_disable(); 95 flush_dcache_page_asm(page_to_phys(page), vmaddr); 96 preempt_enable(); 97 } 98 } 99 100 #define ARCH_HAS_FLUSH_ON_KUNMAP 101 static inline void kunmap_flush_on_unmap(void *addr) 102 { 103 flush_kernel_dcache_page_addr(addr); 104 } 105 106 #endif /* _PARISC_CACHEFLUSH_H */ 107 108