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 #include <linux/jump_label.h>
13 
14 DECLARE_STATIC_KEY_TRUE(parisc_has_cache);
15 DECLARE_STATIC_KEY_TRUE(parisc_has_dcache);
16 DECLARE_STATIC_KEY_TRUE(parisc_has_icache);
17 
18 #define flush_cache_dup_mm(mm) flush_cache_mm(mm)
19 
20 void flush_user_icache_range_asm(unsigned long, unsigned long);
21 void flush_kernel_icache_range_asm(unsigned long, unsigned long);
22 void flush_user_dcache_range_asm(unsigned long, unsigned long);
23 void flush_kernel_dcache_range_asm(unsigned long, unsigned long);
24 void purge_kernel_dcache_range_asm(unsigned long, unsigned long);
25 void flush_kernel_dcache_page_asm(void *);
26 void flush_kernel_icache_page(void *);
27 
28 /* Cache flush operations */
29 
30 void flush_cache_all_local(void);
31 void flush_cache_all(void);
32 void flush_cache_mm(struct mm_struct *mm);
33 
34 void flush_kernel_dcache_page_addr(void *addr);
35 
36 #define flush_kernel_dcache_range(start,size) \
37 	flush_kernel_dcache_range_asm((start), (start)+(size));
38 
39 #define ARCH_IMPLEMENTS_FLUSH_KERNEL_VMAP_RANGE 1
40 void flush_kernel_vmap_range(void *vaddr, int size);
41 void invalidate_kernel_vmap_range(void *vaddr, int size);
42 
43 #define flush_cache_vmap(start, end)		flush_cache_all()
44 #define flush_cache_vunmap(start, end)		flush_cache_all()
45 
46 #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
47 void flush_dcache_page(struct page *page);
48 
49 #define flush_dcache_mmap_lock(mapping)		xa_lock_irq(&mapping->i_pages)
50 #define flush_dcache_mmap_unlock(mapping)	xa_unlock_irq(&mapping->i_pages)
51 
52 #define flush_icache_page(vma,page)	do { 		\
53 	flush_kernel_dcache_page_addr(page_address(page)); \
54 	flush_kernel_icache_page(page_address(page)); 	\
55 } while (0)
56 
57 #define flush_icache_range(s,e)		do { 		\
58 	flush_kernel_dcache_range_asm(s,e); 		\
59 	flush_kernel_icache_range_asm(s,e); 		\
60 } while (0)
61 
62 #define copy_to_user_page(vma, page, vaddr, dst, src, len) \
63 do { \
64 	flush_cache_page(vma, vaddr, page_to_pfn(page)); \
65 	memcpy(dst, src, len); \
66 	flush_kernel_dcache_range_asm((unsigned long)dst, (unsigned long)dst + len); \
67 } while (0)
68 
69 #define copy_from_user_page(vma, page, vaddr, dst, src, len) \
70 do { \
71 	flush_cache_page(vma, vaddr, page_to_pfn(page)); \
72 	memcpy(dst, src, len); \
73 } while (0)
74 
75 void flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn);
76 void flush_cache_range(struct vm_area_struct *vma,
77 		unsigned long start, unsigned long end);
78 
79 /* defined in pacache.S exported in cache.c used by flush_anon_page */
80 void flush_dcache_page_asm(unsigned long phys_addr, unsigned long vaddr);
81 
82 #define ARCH_HAS_FLUSH_ANON_PAGE
83 static inline void
84 flush_anon_page(struct vm_area_struct *vma, struct page *page, unsigned long vmaddr)
85 {
86 	if (PageAnon(page)) {
87 		flush_tlb_page(vma, vmaddr);
88 		preempt_disable();
89 		flush_dcache_page_asm(page_to_phys(page), vmaddr);
90 		preempt_enable();
91 	}
92 }
93 
94 #define ARCH_HAS_FLUSH_ON_KUNMAP
95 static inline void kunmap_flush_on_unmap(void *addr)
96 {
97 	flush_kernel_dcache_page_addr(addr);
98 }
99 
100 #endif /* _PARISC_CACHEFLUSH_H */
101 
102