blob: 138e46d8c04e587ab36ec3ac8f2049fcf1d763e3 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001/* SPDX-License-Identifier: GPL-2.0-or-later */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00003 */
4#ifndef _ASM_POWERPC_CACHEFLUSH_H
5#define _ASM_POWERPC_CACHEFLUSH_H
6
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00007#include <linux/mm.h>
8#include <asm/cputable.h>
Olivier Deprez157378f2022-04-04 15:47:50 +02009#include <asm/cpu_has_feature.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000010
11#ifdef CONFIG_PPC_BOOK3S_64
12/*
13 * Book3s has no ptesync after setting a pte, so without this ptesync it's
14 * possible for a kernel virtual mapping access to return a spurious fault
15 * if it's accessed right after the pte is set. The page fault handler does
16 * not expect this type of fault. flush_cache_vmap is not exactly the right
17 * place to put this, but it seems to work well enough.
18 */
David Brazdil0f672f62019-12-10 10:32:29 +000019static inline void flush_cache_vmap(unsigned long start, unsigned long end)
20{
21 asm volatile("ptesync" ::: "memory");
22}
Olivier Deprez157378f2022-04-04 15:47:50 +020023#define flush_cache_vmap flush_cache_vmap
24#endif /* CONFIG_PPC_BOOK3S_64 */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000025
26#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
27extern void flush_dcache_page(struct page *page);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000028
Olivier Deprez0e641232021-09-23 10:07:05 +020029void flush_icache_range(unsigned long start, unsigned long stop);
Olivier Deprez157378f2022-04-04 15:47:50 +020030#define flush_icache_range flush_icache_range
31
32void flush_icache_user_page(struct vm_area_struct *vma, struct page *page,
33 unsigned long addr, int len);
34#define flush_icache_user_page flush_icache_user_page
35
36void flush_dcache_icache_page(struct page *page);
Olivier Deprez0e641232021-09-23 10:07:05 +020037void __flush_dcache_icache(void *page);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000038
Olivier Deprez0e641232021-09-23 10:07:05 +020039/**
40 * flush_dcache_range(): Write any modified data cache blocks out to memory and
41 * invalidate them. Does not invalidate the corresponding instruction cache
42 * blocks.
43 *
44 * @start: the start address
45 * @stop: the stop address (exclusive)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000046 */
47static inline void flush_dcache_range(unsigned long start, unsigned long stop)
48{
Olivier Deprez0e641232021-09-23 10:07:05 +020049 unsigned long shift = l1_dcache_shift();
50 unsigned long bytes = l1_dcache_bytes();
David Brazdil0f672f62019-12-10 10:32:29 +000051 void *addr = (void *)(start & ~(bytes - 1));
52 unsigned long size = stop - (unsigned long)addr + (bytes - 1);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000053 unsigned long i;
54
Olivier Deprez157378f2022-04-04 15:47:50 +020055 if (IS_ENABLED(CONFIG_PPC64))
David Brazdil0f672f62019-12-10 10:32:29 +000056 mb(); /* sync */
David Brazdil0f672f62019-12-10 10:32:29 +000057
58 for (i = 0; i < size >> shift; i++, addr += bytes)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000059 dcbf(addr);
60 mb(); /* sync */
David Brazdil0f672f62019-12-10 10:32:29 +000061
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000062}
63
64/*
65 * Write any modified data cache blocks out to memory.
66 * Does not invalidate the corresponding cache lines (especially for
67 * any corresponding instruction cache).
68 */
69static inline void clean_dcache_range(unsigned long start, unsigned long stop)
70{
Olivier Deprez0e641232021-09-23 10:07:05 +020071 unsigned long shift = l1_dcache_shift();
72 unsigned long bytes = l1_dcache_bytes();
David Brazdil0f672f62019-12-10 10:32:29 +000073 void *addr = (void *)(start & ~(bytes - 1));
74 unsigned long size = stop - (unsigned long)addr + (bytes - 1);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000075 unsigned long i;
76
David Brazdil0f672f62019-12-10 10:32:29 +000077 for (i = 0; i < size >> shift; i++, addr += bytes)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000078 dcbst(addr);
79 mb(); /* sync */
80}
81
82/*
83 * Like above, but invalidate the D-cache. This is used by the 8xx
84 * to invalidate the cache so the PPC core doesn't get stale data
85 * from the CPM (no cache snooping here :-).
86 */
87static inline void invalidate_dcache_range(unsigned long start,
88 unsigned long stop)
89{
Olivier Deprez0e641232021-09-23 10:07:05 +020090 unsigned long shift = l1_dcache_shift();
91 unsigned long bytes = l1_dcache_bytes();
David Brazdil0f672f62019-12-10 10:32:29 +000092 void *addr = (void *)(start & ~(bytes - 1));
93 unsigned long size = stop - (unsigned long)addr + (bytes - 1);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000094 unsigned long i;
95
David Brazdil0f672f62019-12-10 10:32:29 +000096 for (i = 0; i < size >> shift; i++, addr += bytes)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000097 dcbi(addr);
98 mb(); /* sync */
99}
100
Olivier Deprez157378f2022-04-04 15:47:50 +0200101#ifdef CONFIG_4xx
102static inline void flush_instruction_cache(void)
103{
104 iccci((void *)KERNELBASE);
105 isync();
106}
107#else
108void flush_instruction_cache(void);
109#endif
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000110
Olivier Deprez157378f2022-04-04 15:47:50 +0200111#include <asm-generic/cacheflush.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000112
113#endif /* _ASM_POWERPC_CACHEFLUSH_H */