Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #ifndef _PARISC_CACHEFLUSH_H |
| 3 | #define _PARISC_CACHEFLUSH_H |
| 4 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <linux/mm.h> |
John David Anglin | 210501a | 2010-04-11 16:36:14 +0000 | [diff] [blame] | 6 | #include <linux/uaccess.h> |
James Bottomley | b7d4581 | 2011-04-15 12:37:22 -0500 | [diff] [blame] | 7 | #include <asm/tlbflush.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
| 9 | /* The usual comment is "Caches aren't brain-dead on the <architecture>". |
| 10 | * Unfortunately, that doesn't apply to PA-RISC. */ |
| 11 | |
Randolph Chung | d6ce862 | 2006-12-12 05:51:54 -0800 | [diff] [blame] | 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 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #ifdef CONFIG_SMP |
Randolph Chung | d6ce862 | 2006-12-12 05:51:54 -0800 | [diff] [blame] | 16 | void flush_data_cache(void); /* flushes data-cache only (all processors) */ |
| 17 | void flush_instruction_cache(void); /* flushes i-cache only (all processors) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #else |
Randolph Chung | d6ce862 | 2006-12-12 05:51:54 -0800 | [diff] [blame] | 19 | #define flush_data_cache() flush_data_cache_local(NULL) |
| 20 | #define flush_instruction_cache() flush_instruction_cache_local(NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #endif |
| 22 | |
Ralf Baechle | ec8c044 | 2006-12-12 17:14:57 +0000 | [diff] [blame] | 23 | #define flush_cache_dup_mm(mm) flush_cache_mm(mm) |
| 24 | |
Randolph Chung | d6ce862 | 2006-12-12 05:51:54 -0800 | [diff] [blame] | 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 flush_kernel_dcache_page_asm(void *); |
| 30 | void flush_kernel_icache_page(void *); |
Randolph Chung | d6ce862 | 2006-12-12 05:51:54 -0800 | [diff] [blame] | 31 | |
| 32 | /* Cache flush operations */ |
| 33 | |
| 34 | void flush_cache_all_local(void); |
| 35 | void flush_cache_all(void); |
| 36 | void flush_cache_mm(struct mm_struct *mm); |
| 37 | |
James Bottomley | 8e1964a | 2011-01-20 12:54:18 -0600 | [diff] [blame] | 38 | #define ARCH_HAS_FLUSH_KERNEL_DCACHE_PAGE |
| 39 | void flush_kernel_dcache_page_addr(void *addr); |
| 40 | static inline void flush_kernel_dcache_page(struct page *page) |
| 41 | { |
| 42 | flush_kernel_dcache_page_addr(page_address(page)); |
| 43 | } |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #define flush_kernel_dcache_range(start,size) \ |
| 46 | flush_kernel_dcache_range_asm((start), (start)+(size)); |
James Bottomley | ef7cc35 | 2010-01-25 11:42:21 -0600 | [diff] [blame] | 47 | |
John David Anglin | 316ec06 | 2017-03-11 18:03:34 -0500 | [diff] [blame] | 48 | void flush_kernel_vmap_range(void *vaddr, int size); |
| 49 | void invalidate_kernel_vmap_range(void *vaddr, int size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define flush_cache_vmap(start, end) flush_cache_all() |
| 52 | #define flush_cache_vunmap(start, end) flush_cache_all() |
| 53 | |
Ilya Loginov | 2d4dc89 | 2009-11-26 09:16:19 +0100 | [diff] [blame] | 54 | #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | extern void flush_dcache_page(struct page *page); |
| 56 | |
| 57 | #define flush_dcache_mmap_lock(mapping) \ |
Nick Piggin | 19fd623 | 2008-07-25 19:45:32 -0700 | [diff] [blame] | 58 | spin_lock_irq(&(mapping)->tree_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #define flush_dcache_mmap_unlock(mapping) \ |
Nick Piggin | 19fd623 | 2008-07-25 19:45:32 -0700 | [diff] [blame] | 60 | spin_unlock_irq(&(mapping)->tree_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Randolph Chung | d6ce862 | 2006-12-12 05:51:54 -0800 | [diff] [blame] | 62 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Randolph Chung | d6ce862 | 2006-12-12 05:51:54 -0800 | [diff] [blame] | 67 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | #define copy_to_user_page(vma, page, vaddr, dst, src, len) \ |
| 73 | do { \ |
| 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) \ |
| 80 | do { \ |
| 81 | flush_cache_page(vma, vaddr, page_to_pfn(page)); \ |
| 82 | memcpy(dst, src, len); \ |
| 83 | } while (0) |
| 84 | |
Randolph Chung | d6ce862 | 2006-12-12 05:51:54 -0800 | [diff] [blame] | 85 | void flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn); |
| 86 | void flush_cache_range(struct vm_area_struct *vma, |
| 87 | unsigned long start, unsigned long end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
James Bottomley | f311847 | 2010-12-22 10:22:11 -0600 | [diff] [blame] | 89 | /* defined in pacache.S exported in cache.c used by flush_anon_page */ |
| 90 | void flush_dcache_page_asm(unsigned long phys_addr, unsigned long vaddr); |
| 91 | |
Randolph Chung | d6ce862 | 2006-12-12 05:51:54 -0800 | [diff] [blame] | 92 | #define ARCH_HAS_FLUSH_ANON_PAGE |
James Bottomley | ab43227 | 2006-03-22 08:28:59 -0700 | [diff] [blame] | 93 | static inline void |
Russell King | a6f36be | 2006-12-30 22:24:19 +0000 | [diff] [blame] | 94 | flush_anon_page(struct vm_area_struct *vma, struct page *page, unsigned long vmaddr) |
James Bottomley | ab43227 | 2006-03-22 08:28:59 -0700 | [diff] [blame] | 95 | { |
James Bottomley | b7d4581 | 2011-04-15 12:37:22 -0500 | [diff] [blame] | 96 | if (PageAnon(page)) { |
| 97 | flush_tlb_page(vma, vmaddr); |
John David Anglin | 027f27c | 2013-02-02 23:41:24 +0000 | [diff] [blame] | 98 | preempt_disable(); |
James Bottomley | f311847 | 2010-12-22 10:22:11 -0600 | [diff] [blame] | 99 | flush_dcache_page_asm(page_to_phys(page), vmaddr); |
John David Anglin | 027f27c | 2013-02-02 23:41:24 +0000 | [diff] [blame] | 100 | preempt_enable(); |
James Bottomley | b7d4581 | 2011-04-15 12:37:22 -0500 | [diff] [blame] | 101 | } |
James Bottomley | ab43227 | 2006-03-22 08:28:59 -0700 | [diff] [blame] | 102 | } |
James Bottomley | ab43227 | 2006-03-22 08:28:59 -0700 | [diff] [blame] | 103 | |
Kyle McMartin | bb73501 | 2009-04-02 02:40:41 +0000 | [diff] [blame] | 104 | #include <asm/kmap_types.h> |
| 105 | |
James Bottomley | 20f4d3c | 2006-08-23 09:00:04 -0700 | [diff] [blame] | 106 | #define ARCH_HAS_KMAP |
| 107 | |
James Bottomley | 20f4d3c | 2006-08-23 09:00:04 -0700 | [diff] [blame] | 108 | static inline void *kmap(struct page *page) |
| 109 | { |
| 110 | might_sleep(); |
| 111 | return page_address(page); |
| 112 | } |
| 113 | |
John David Anglin | 87be2f8 | 2013-04-23 00:23:50 +0000 | [diff] [blame] | 114 | static inline void kunmap(struct page *page) |
| 115 | { |
John David Anglin | f8dae00 | 2014-01-05 21:25:00 -0500 | [diff] [blame] | 116 | flush_kernel_dcache_page_addr(page_address(page)); |
John David Anglin | 87be2f8 | 2013-04-23 00:23:50 +0000 | [diff] [blame] | 117 | } |
James Bottomley | 20f4d3c | 2006-08-23 09:00:04 -0700 | [diff] [blame] | 118 | |
Cong Wang | a24401b | 2011-11-26 10:53:39 +0800 | [diff] [blame] | 119 | static inline void *kmap_atomic(struct page *page) |
John David Anglin | 210501a | 2010-04-11 16:36:14 +0000 | [diff] [blame] | 120 | { |
David Hildenbrand | 2cb7c9c | 2015-05-11 17:52:09 +0200 | [diff] [blame] | 121 | preempt_disable(); |
John David Anglin | 210501a | 2010-04-11 16:36:14 +0000 | [diff] [blame] | 122 | pagefault_disable(); |
| 123 | return page_address(page); |
| 124 | } |
James Bottomley | 20f4d3c | 2006-08-23 09:00:04 -0700 | [diff] [blame] | 125 | |
James Bottomley | 765aaaf | 2010-10-28 10:14:41 -0500 | [diff] [blame] | 126 | static inline void __kunmap_atomic(void *addr) |
John David Anglin | 210501a | 2010-04-11 16:36:14 +0000 | [diff] [blame] | 127 | { |
John David Anglin | f8dae00 | 2014-01-05 21:25:00 -0500 | [diff] [blame] | 128 | flush_kernel_dcache_page_addr(addr); |
John David Anglin | 210501a | 2010-04-11 16:36:14 +0000 | [diff] [blame] | 129 | pagefault_enable(); |
David Hildenbrand | 2cb7c9c | 2015-05-11 17:52:09 +0200 | [diff] [blame] | 130 | preempt_enable(); |
John David Anglin | 210501a | 2010-04-11 16:36:14 +0000 | [diff] [blame] | 131 | } |
James Bottomley | 20f4d3c | 2006-08-23 09:00:04 -0700 | [diff] [blame] | 132 | |
James Bottomley | 765aaaf | 2010-10-28 10:14:41 -0500 | [diff] [blame] | 133 | #define kmap_atomic_prot(page, prot) kmap_atomic(page) |
| 134 | #define kmap_atomic_pfn(pfn) kmap_atomic(pfn_to_page(pfn)) |
James Bottomley | 20f4d3c | 2006-08-23 09:00:04 -0700 | [diff] [blame] | 135 | |
Helge Deller | 1bcdd85 | 2006-01-13 13:21:06 -0700 | [diff] [blame] | 136 | #endif /* _PARISC_CACHEFLUSH_H */ |
| 137 | |