xref: /openbmc/linux/arch/alpha/include/asm/cacheflush.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2024b246eSLinus Torvalds #ifndef _ALPHA_CACHEFLUSH_H
3024b246eSLinus Torvalds #define _ALPHA_CACHEFLUSH_H
4024b246eSLinus Torvalds 
5024b246eSLinus Torvalds #include <linux/mm.h>
6024b246eSLinus Torvalds 
7024b246eSLinus Torvalds /* Note that the following two definitions are _highly_ dependent
8024b246eSLinus Torvalds    on the contexts in which they are used in the kernel.  I personally
9024b246eSLinus Torvalds    think it is criminal how loosely defined these macros are.  */
10024b246eSLinus Torvalds 
11024b246eSLinus Torvalds /* We need to flush the kernel's icache after loading modules.  The
12024b246eSLinus Torvalds    only other use of this macro is in load_aout_interp which is not
13024b246eSLinus Torvalds    used on Alpha.
14024b246eSLinus Torvalds 
15024b246eSLinus Torvalds    Note that this definition should *not* be used for userspace
16024b246eSLinus Torvalds    icache flushing.  While functional, it is _way_ overkill.  The
17024b246eSLinus Torvalds    icache is tagged with ASNs and it suffices to allocate a new ASN
18024b246eSLinus Torvalds    for the process.  */
19024b246eSLinus Torvalds #ifndef CONFIG_SMP
20024b246eSLinus Torvalds #define flush_icache_range(start, end)		imb()
21024b246eSLinus Torvalds #else
22024b246eSLinus Torvalds #define flush_icache_range(start, end)		smp_imb()
23024b246eSLinus Torvalds extern void smp_imb(void);
24024b246eSLinus Torvalds #endif
25024b246eSLinus Torvalds 
26024b246eSLinus Torvalds /* We need to flush the userspace icache after setting breakpoints in
27024b246eSLinus Torvalds    ptrace.
28024b246eSLinus Torvalds 
29024b246eSLinus Torvalds    Instead of indiscriminately using imb, take advantage of the fact
30024b246eSLinus Torvalds    that icache entries are tagged with the ASN and load a new mm context.  */
31024b246eSLinus Torvalds /* ??? Ought to use this in arch/alpha/kernel/signal.c too.  */
32024b246eSLinus Torvalds 
33024b246eSLinus Torvalds #ifndef CONFIG_SMP
34b97f897dSTejun Heo #include <linux/sched.h>
35b97f897dSTejun Heo 
36024b246eSLinus Torvalds extern void __load_new_mm_context(struct mm_struct *);
37024b246eSLinus Torvalds static inline void
flush_icache_user_page(struct vm_area_struct * vma,struct page * page,unsigned long addr,int len)38885f7f8eSChristoph Hellwig flush_icache_user_page(struct vm_area_struct *vma, struct page *page,
39024b246eSLinus Torvalds 			unsigned long addr, int len)
40024b246eSLinus Torvalds {
41024b246eSLinus Torvalds 	if (vma->vm_flags & VM_EXEC) {
42024b246eSLinus Torvalds 		struct mm_struct *mm = vma->vm_mm;
43024b246eSLinus Torvalds 		if (current->active_mm == mm)
44024b246eSLinus Torvalds 			__load_new_mm_context(mm);
45024b246eSLinus Torvalds 		else
46024b246eSLinus Torvalds 			mm->context[smp_processor_id()] = 0;
47024b246eSLinus Torvalds 	}
48024b246eSLinus Torvalds }
49885f7f8eSChristoph Hellwig #define flush_icache_user_page flush_icache_user_page
5043c74ca3SChristoph Hellwig #else /* CONFIG_SMP */
51885f7f8eSChristoph Hellwig extern void flush_icache_user_page(struct vm_area_struct *vma,
52024b246eSLinus Torvalds 		struct page *page, unsigned long addr, int len);
53885f7f8eSChristoph Hellwig #define flush_icache_user_page flush_icache_user_page
5443c74ca3SChristoph Hellwig #endif /* CONFIG_SMP */
55024b246eSLinus Torvalds 
5663497b71SMatthew Wilcox (Oracle) /*
5763497b71SMatthew Wilcox (Oracle)  * Both implementations of flush_icache_user_page flush the entire
5863497b71SMatthew Wilcox (Oracle)  * address space, so one call, no matter how many pages.
5963497b71SMatthew Wilcox (Oracle)  */
flush_icache_pages(struct vm_area_struct * vma,struct page * page,unsigned int nr)6063497b71SMatthew Wilcox (Oracle) static inline void flush_icache_pages(struct vm_area_struct *vma,
6163497b71SMatthew Wilcox (Oracle) 		struct page *page, unsigned int nr)
6263497b71SMatthew Wilcox (Oracle) {
6363497b71SMatthew Wilcox (Oracle) 	flush_icache_user_page(vma, page, 0, 0);
6463497b71SMatthew Wilcox (Oracle) }
65*203b7b6aSMatthew Wilcox (Oracle) #define flush_icache_pages flush_icache_pages
6663497b71SMatthew Wilcox (Oracle) 
6743c74ca3SChristoph Hellwig #include <asm-generic/cacheflush.h>
68024b246eSLinus Torvalds 
69024b246eSLinus Torvalds #endif /* _ALPHA_CACHEFLUSH_H */
70