blob: e9662648e72d716b489153c17396815ff0ac956c [file] [log] [blame]
David Gibson26ef5c02005-11-10 11:50:16 +11001/*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version
5 * 2 of the License, or (at your option) any later version.
6 */
7#ifndef _ASM_POWERPC_CACHEFLUSH_H
8#define _ASM_POWERPC_CACHEFLUSH_H
9
10#ifdef __KERNEL__
11
12#include <linux/mm.h>
13#include <asm/cputable.h>
Kevin Haob92a2262016-07-23 14:42:40 +053014#include <asm/cpu_has_feature.h>
David Gibson26ef5c02005-11-10 11:50:16 +110015
16/*
17 * No cache flushing is required when address mappings are changed,
18 * because the caches on PowerPCs are physically addressed.
19 */
20#define flush_cache_all() do { } while (0)
21#define flush_cache_mm(mm) do { } while (0)
Ralf Baechleec8c0442006-12-12 17:14:57 +000022#define flush_cache_dup_mm(mm) do { } while (0)
David Gibson26ef5c02005-11-10 11:50:16 +110023#define flush_cache_range(vma, start, end) do { } while (0)
24#define flush_cache_page(vma, vmaddr, pfn) do { } while (0)
25#define flush_icache_page(vma, page) do { } while (0)
26#define flush_cache_vmap(start, end) do { } while (0)
27#define flush_cache_vunmap(start, end) do { } while (0)
28
Nicholas Pigginf1cb8f92018-06-01 20:01:19 +100029#ifdef CONFIG_BOOK3S_64
30/*
31 * Book3s has no ptesync after setting a pte, so without this ptesync it's
32 * possible for a kernel virtual mapping access to return a spurious fault
33 * if it's accessed right after the pte is set. The page fault handler does
34 * not expect this type of fault. flush_cache_vmap is not exactly the right
35 * place to put this, but it seems to work well enough.
36 */
37#define flush_cache_vmap(start, end) do { asm volatile("ptesync"); } while (0)
38#else
39#define flush_cache_vmap(start, end) do { } while (0)
40#endif
41
Ilya Loginov2d4dc892009-11-26 09:16:19 +010042#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
David Gibson26ef5c02005-11-10 11:50:16 +110043extern void flush_dcache_page(struct page *page);
44#define flush_dcache_mmap_lock(mapping) do { } while (0)
45#define flush_dcache_mmap_unlock(mapping) do { } while (0)
46
Kevin Hao3b04c302013-08-06 18:23:31 +080047extern void flush_icache_range(unsigned long, unsigned long);
David Gibson26ef5c02005-11-10 11:50:16 +110048extern void flush_icache_user_range(struct vm_area_struct *vma,
49 struct page *page, unsigned long addr,
50 int len);
51extern void __flush_dcache_icache(void *page_va);
52extern void flush_dcache_icache_page(struct page *page);
53#if defined(CONFIG_PPC32) && !defined(CONFIG_BOOKE)
54extern void __flush_dcache_icache_phys(unsigned long physaddr);
Scott Wood2f7d2b72015-04-15 19:40:23 -050055#else
56static inline void __flush_dcache_icache_phys(unsigned long physaddr)
57{
58 BUG();
59}
60#endif
David Gibson26ef5c02005-11-10 11:50:16 +110061
David Gibson26ef5c02005-11-10 11:50:16 +110062#ifdef CONFIG_PPC32
Christophe Leroyaffe5872016-02-09 17:08:27 +010063/*
64 * Write any modified data cache blocks out to memory and invalidate them.
65 * Does not invalidate the corresponding instruction cache blocks.
66 */
67static inline void flush_dcache_range(unsigned long start, unsigned long stop)
68{
69 void *addr = (void *)(start & ~(L1_CACHE_BYTES - 1));
70 unsigned long size = stop - (unsigned long)addr + (L1_CACHE_BYTES - 1);
71 unsigned long i;
72
73 for (i = 0; i < size >> L1_CACHE_SHIFT; i++, addr += L1_CACHE_BYTES)
74 dcbf(addr);
75 mb(); /* sync */
76}
77
78/*
79 * Write any modified data cache blocks out to memory.
80 * Does not invalidate the corresponding cache lines (especially for
81 * any corresponding instruction cache).
82 */
83static inline void clean_dcache_range(unsigned long start, unsigned long stop)
84{
85 void *addr = (void *)(start & ~(L1_CACHE_BYTES - 1));
86 unsigned long size = stop - (unsigned long)addr + (L1_CACHE_BYTES - 1);
87 unsigned long i;
88
89 for (i = 0; i < size >> L1_CACHE_SHIFT; i++, addr += L1_CACHE_BYTES)
90 dcbst(addr);
91 mb(); /* sync */
92}
93
94/*
95 * Like above, but invalidate the D-cache. This is used by the 8xx
96 * to invalidate the cache so the PPC core doesn't get stale data
97 * from the CPM (no cache snooping here :-).
98 */
99static inline void invalidate_dcache_range(unsigned long start,
100 unsigned long stop)
101{
102 void *addr = (void *)(start & ~(L1_CACHE_BYTES - 1));
103 unsigned long size = stop - (unsigned long)addr + (L1_CACHE_BYTES - 1);
104 unsigned long i;
105
106 for (i = 0; i < size >> L1_CACHE_SHIFT; i++, addr += L1_CACHE_BYTES)
107 dcbi(addr);
108 mb(); /* sync */
109}
110
David Gibson26ef5c02005-11-10 11:50:16 +1100111#endif /* CONFIG_PPC32 */
112#ifdef CONFIG_PPC64
Christophe Leroyaffe5872016-02-09 17:08:27 +0100113extern void flush_dcache_range(unsigned long start, unsigned long stop);
David Gibson26ef5c02005-11-10 11:50:16 +1100114extern void flush_inval_dcache_range(unsigned long start, unsigned long stop);
David Gibson26ef5c02005-11-10 11:50:16 +1100115#endif
116
117#define copy_to_user_page(vma, page, vaddr, dst, src, len) \
118 do { \
119 memcpy(dst, src, len); \
120 flush_icache_user_range(vma, page, vaddr, len); \
121 } while (0)
122#define copy_from_user_page(vma, page, vaddr, dst, src, len) \
123 memcpy(dst, src, len)
124
David Gibson26ef5c02005-11-10 11:50:16 +1100125#endif /* __KERNEL__ */
126
127#endif /* _ASM_POWERPC_CACHEFLUSH_H */