blob: 3742508cc5345882510d907dc5f58b48a08ad9e7 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _PARISC_CACHEFLUSH_H
3#define _PARISC_CACHEFLUSH_H
4
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/mm.h>
John David Anglin210501a2010-04-11 16:36:14 +00006#include <linux/uaccess.h>
James Bottomleyb7d45812011-04-15 12:37:22 -05007#include <asm/tlbflush.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
9/* The usual comment is "Caches aren't brain-dead on the <architecture>".
10 * Unfortunately, that doesn't apply to PA-RISC. */
11
Randolph Chungd6ce8622006-12-12 05:51:54 -080012/* Internal implementation */
13void flush_data_cache_local(void *); /* flushes local data-cache only */
14void flush_instruction_cache_local(void *); /* flushes local code-cache only */
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#ifdef CONFIG_SMP
Randolph Chungd6ce8622006-12-12 05:51:54 -080016void flush_data_cache(void); /* flushes data-cache only (all processors) */
17void flush_instruction_cache(void); /* flushes i-cache only (all processors) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#else
Randolph Chungd6ce8622006-12-12 05:51:54 -080019#define flush_data_cache() flush_data_cache_local(NULL)
20#define flush_instruction_cache() flush_instruction_cache_local(NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#endif
22
Ralf Baechleec8c0442006-12-12 17:14:57 +000023#define flush_cache_dup_mm(mm) flush_cache_mm(mm)
24
Randolph Chungd6ce8622006-12-12 05:51:54 -080025void flush_user_icache_range_asm(unsigned long, unsigned long);
26void flush_kernel_icache_range_asm(unsigned long, unsigned long);
27void flush_user_dcache_range_asm(unsigned long, unsigned long);
28void flush_kernel_dcache_range_asm(unsigned long, unsigned long);
29void flush_kernel_dcache_page_asm(void *);
30void flush_kernel_icache_page(void *);
Randolph Chungd6ce8622006-12-12 05:51:54 -080031
32/* Cache flush operations */
33
34void flush_cache_all_local(void);
35void flush_cache_all(void);
36void flush_cache_mm(struct mm_struct *mm);
37
James Bottomley8e1964a2011-01-20 12:54:18 -060038#define ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE
39void flush_kernel_dcache_page_addr(void *addr);
40static inline void flush_kernel_dcache_page(struct page *page)
41{
42 flush_kernel_dcache_page_addr(page_address(page));
43}
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#define flush_kernel_dcache_range(start,size) \
46 flush_kernel_dcache_range_asm((start), (start)+(size));
James Bottomleyef7cc352010-01-25 11:42:21 -060047
John David Anglin316ec062017-03-11 18:03:34 -050048void flush_kernel_vmap_range(void *vaddr, int size);
49void invalidate_kernel_vmap_range(void *vaddr, int size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define flush_cache_vmap(start, end) flush_cache_all()
52#define flush_cache_vunmap(start, end) flush_cache_all()
53
Ilya Loginov2d4dc892009-11-26 09:16:19 +010054#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
Linus Torvalds1da177e2005-04-16 15:20:36 -070055extern void flush_dcache_page(struct page *page);
56
57#define flush_dcache_mmap_lock(mapping) \
Nick Piggin19fd6232008-07-25 19:45:32 -070058 spin_lock_irq(&(mapping)->tree_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#define flush_dcache_mmap_unlock(mapping) \
Nick Piggin19fd6232008-07-25 19:45:32 -070060 spin_unlock_irq(&(mapping)->tree_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Randolph Chungd6ce8622006-12-12 05:51:54 -080062#define flush_icache_page(vma,page) do { \
63 flush_kernel_dcache_page(page); \
64 flush_kernel_icache_page(page_address(page)); \
65} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Randolph Chungd6ce8622006-12-12 05:51:54 -080067#define flush_icache_range(s,e) do { \
68 flush_kernel_dcache_range_asm(s,e); \
69 flush_kernel_icache_range_asm(s,e); \
70} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72#define copy_to_user_page(vma, page, vaddr, dst, src, len) \
73do { \
74 flush_cache_page(vma, vaddr, page_to_pfn(page)); \
75 memcpy(dst, src, len); \
76 flush_kernel_dcache_range_asm((unsigned long)dst, (unsigned long)dst + len); \
77} while (0)
78
79#define copy_from_user_page(vma, page, vaddr, dst, src, len) \
80do { \
81 flush_cache_page(vma, vaddr, page_to_pfn(page)); \
82 memcpy(dst, src, len); \
83} while (0)
84
Randolph Chungd6ce8622006-12-12 05:51:54 -080085void flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn);
86void flush_cache_range(struct vm_area_struct *vma,
87 unsigned long start, unsigned long end);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
James Bottomleyf3118472010-12-22 10:22:11 -060089/* defined in pacache.S exported in cache.c used by flush_anon_page */
90void flush_dcache_page_asm(unsigned long phys_addr, unsigned long vaddr);
91
Randolph Chungd6ce8622006-12-12 05:51:54 -080092#define ARCH_HAS_FLUSH_ANON_PAGE
James Bottomleyab432272006-03-22 08:28:59 -070093static inline void
Russell Kinga6f36be2006-12-30 22:24:19 +000094flush_anon_page(struct vm_area_struct *vma, struct page *page, unsigned long vmaddr)
James Bottomleyab432272006-03-22 08:28:59 -070095{
James Bottomleyb7d45812011-04-15 12:37:22 -050096 if (PageAnon(page)) {
97 flush_tlb_page(vma, vmaddr);
John David Anglin027f27c2013-02-02 23:41:24 +000098 preempt_disable();
James Bottomleyf3118472010-12-22 10:22:11 -060099 flush_dcache_page_asm(page_to_phys(page), vmaddr);
John David Anglin027f27c2013-02-02 23:41:24 +0000100 preempt_enable();
James Bottomleyb7d45812011-04-15 12:37:22 -0500101 }
James Bottomleyab432272006-03-22 08:28:59 -0700102}
James Bottomleyab432272006-03-22 08:28:59 -0700103
Kyle McMartinbb735012009-04-02 02:40:41 +0000104#include <asm/kmap_types.h>
105
James Bottomley20f4d3c2006-08-23 09:00:04 -0700106#define ARCH_HAS_KMAP
107
James Bottomley20f4d3c2006-08-23 09:00:04 -0700108static inline void *kmap(struct page *page)
109{
110 might_sleep();
111 return page_address(page);
112}
113
John David Anglin87be2f82013-04-23 00:23:50 +0000114static inline void kunmap(struct page *page)
115{
John David Anglinf8dae002014-01-05 21:25:00 -0500116 flush_kernel_dcache_page_addr(page_address(page));
John David Anglin87be2f82013-04-23 00:23:50 +0000117}
James Bottomley20f4d3c2006-08-23 09:00:04 -0700118
Cong Wanga24401b2011-11-26 10:53:39 +0800119static inline void *kmap_atomic(struct page *page)
John David Anglin210501a2010-04-11 16:36:14 +0000120{
David Hildenbrand2cb7c9c2015-05-11 17:52:09 +0200121 preempt_disable();
John David Anglin210501a2010-04-11 16:36:14 +0000122 pagefault_disable();
123 return page_address(page);
124}
James Bottomley20f4d3c2006-08-23 09:00:04 -0700125
James Bottomley765aaaf2010-10-28 10:14:41 -0500126static inline void __kunmap_atomic(void *addr)
John David Anglin210501a2010-04-11 16:36:14 +0000127{
John David Anglinf8dae002014-01-05 21:25:00 -0500128 flush_kernel_dcache_page_addr(addr);
John David Anglin210501a2010-04-11 16:36:14 +0000129 pagefault_enable();
David Hildenbrand2cb7c9c2015-05-11 17:52:09 +0200130 preempt_enable();
John David Anglin210501a2010-04-11 16:36:14 +0000131}
James Bottomley20f4d3c2006-08-23 09:00:04 -0700132
James Bottomley765aaaf2010-10-28 10:14:41 -0500133#define kmap_atomic_prot(page, prot) kmap_atomic(page)
134#define kmap_atomic_pfn(pfn) kmap_atomic(pfn_to_page(pfn))
James Bottomley20f4d3c2006-08-23 09:00:04 -0700135
Helge Deller1bcdd852006-01-13 13:21:06 -0700136#endif /* _PARISC_CACHEFLUSH_H */
137