blob: 74d60cfe8ce5b59bd736fe40994470dc421e5cfc [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
David Gibson26ef5c02005-11-10 11:50:16 +11002/*
David Gibson26ef5c02005-11-10 11:50:16 +11003 */
4#ifndef _ASM_POWERPC_CACHEFLUSH_H
5#define _ASM_POWERPC_CACHEFLUSH_H
6
7#ifdef __KERNEL__
8
9#include <linux/mm.h>
10#include <asm/cputable.h>
11
12/*
13 * No cache flushing is required when address mappings are changed,
14 * because the caches on PowerPCs are physically addressed.
15 */
16#define flush_cache_all() do { } while (0)
17#define flush_cache_mm(mm) do { } while (0)
Ralf Baechleec8c0442006-12-12 17:14:57 +000018#define flush_cache_dup_mm(mm) do { } while (0)
David Gibson26ef5c02005-11-10 11:50:16 +110019#define flush_cache_range(vma, start, end) do { } while (0)
20#define flush_cache_page(vma, vmaddr, pfn) do { } while (0)
21#define flush_icache_page(vma, page) do { } while (0)
David Gibson26ef5c02005-11-10 11:50:16 +110022#define flush_cache_vunmap(start, end) do { } while (0)
23
Nicholas Pigginff5bc792018-06-06 11:40:08 +100024#ifdef CONFIG_PPC_BOOK3S_64
Nicholas Pigginf1cb8f92018-06-01 20:01:19 +100025/*
26 * Book3s has no ptesync after setting a pte, so without this ptesync it's
27 * possible for a kernel virtual mapping access to return a spurious fault
28 * if it's accessed right after the pte is set. The page fault handler does
29 * not expect this type of fault. flush_cache_vmap is not exactly the right
30 * place to put this, but it seems to work well enough.
31 */
Nicholas Pigginff5bc792018-06-06 11:40:08 +100032#define flush_cache_vmap(start, end) do { asm volatile("ptesync" ::: "memory"); } while (0)
Nicholas Pigginf1cb8f92018-06-01 20:01:19 +100033#else
34#define flush_cache_vmap(start, end) do { } while (0)
35#endif
36
Ilya Loginov2d4dc892009-11-26 09:16:19 +010037#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
David Gibson26ef5c02005-11-10 11:50:16 +110038extern void flush_dcache_page(struct page *page);
39#define flush_dcache_mmap_lock(mapping) do { } while (0)
40#define flush_dcache_mmap_unlock(mapping) do { } while (0)
41
Kevin Hao3b04c302013-08-06 18:23:31 +080042extern void flush_icache_range(unsigned long, unsigned long);
David Gibson26ef5c02005-11-10 11:50:16 +110043extern void flush_icache_user_range(struct vm_area_struct *vma,
44 struct page *page, unsigned long addr,
45 int len);
46extern void __flush_dcache_icache(void *page_va);
47extern void flush_dcache_icache_page(struct page *page);
48#if defined(CONFIG_PPC32) && !defined(CONFIG_BOOKE)
49extern void __flush_dcache_icache_phys(unsigned long physaddr);
Scott Wood2f7d2b72015-04-15 19:40:23 -050050#else
51static inline void __flush_dcache_icache_phys(unsigned long physaddr)
52{
53 BUG();
54}
55#endif
David Gibson26ef5c02005-11-10 11:50:16 +110056
David Gibson26ef5c02005-11-10 11:50:16 +110057#ifdef CONFIG_PPC32
Christophe Leroyaffe5872016-02-09 17:08:27 +010058/*
59 * Write any modified data cache blocks out to memory and invalidate them.
60 * Does not invalidate the corresponding instruction cache blocks.
61 */
62static inline void flush_dcache_range(unsigned long start, unsigned long stop)
63{
64 void *addr = (void *)(start & ~(L1_CACHE_BYTES - 1));
65 unsigned long size = stop - (unsigned long)addr + (L1_CACHE_BYTES - 1);
66 unsigned long i;
67
68 for (i = 0; i < size >> L1_CACHE_SHIFT; i++, addr += L1_CACHE_BYTES)
69 dcbf(addr);
70 mb(); /* sync */
71}
72
73/*
74 * Write any modified data cache blocks out to memory.
75 * Does not invalidate the corresponding cache lines (especially for
76 * any corresponding instruction cache).
77 */
78static inline void clean_dcache_range(unsigned long start, unsigned long stop)
79{
80 void *addr = (void *)(start & ~(L1_CACHE_BYTES - 1));
81 unsigned long size = stop - (unsigned long)addr + (L1_CACHE_BYTES - 1);
82 unsigned long i;
83
84 for (i = 0; i < size >> L1_CACHE_SHIFT; i++, addr += L1_CACHE_BYTES)
85 dcbst(addr);
86 mb(); /* sync */
87}
88
89/*
90 * Like above, but invalidate the D-cache. This is used by the 8xx
91 * to invalidate the cache so the PPC core doesn't get stale data
92 * from the CPM (no cache snooping here :-).
93 */
94static inline void invalidate_dcache_range(unsigned long start,
95 unsigned long stop)
96{
97 void *addr = (void *)(start & ~(L1_CACHE_BYTES - 1));
98 unsigned long size = stop - (unsigned long)addr + (L1_CACHE_BYTES - 1);
99 unsigned long i;
100
101 for (i = 0; i < size >> L1_CACHE_SHIFT; i++, addr += L1_CACHE_BYTES)
102 dcbi(addr);
103 mb(); /* sync */
104}
105
David Gibson26ef5c02005-11-10 11:50:16 +1100106#endif /* CONFIG_PPC32 */
107#ifdef CONFIG_PPC64
Christophe Leroyaffe5872016-02-09 17:08:27 +0100108extern void flush_dcache_range(unsigned long start, unsigned long stop);
David Gibson26ef5c02005-11-10 11:50:16 +1100109extern void flush_inval_dcache_range(unsigned long start, unsigned long stop);
David Gibson26ef5c02005-11-10 11:50:16 +1100110#endif
111
112#define copy_to_user_page(vma, page, vaddr, dst, src, len) \
113 do { \
114 memcpy(dst, src, len); \
115 flush_icache_user_range(vma, page, vaddr, len); \
116 } while (0)
117#define copy_from_user_page(vma, page, vaddr, dst, src, len) \
118 memcpy(dst, src, len)
119
David Gibson26ef5c02005-11-10 11:50:16 +1100120#endif /* __KERNEL__ */
121
122#endif /* _ASM_POWERPC_CACHEFLUSH_H */