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