2019-05-27 06:55:01 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
[PATCH] powerpc: Merge cacheflush.h and cache.h
The ppc32 and ppc64 versions of cacheflush.h were almost identical.
The two versions of cache.h are fairly similar, except for a bunch of
register definitions in the ppc32 version which probably belong better
elsewhere. This patch, therefore, merges both headers. Notable
points:
- there are several functions in cacheflush.h which exist only
on ppc32 or only on ppc64. These are handled by #ifdef for now, but
these should probably be consolidated, along with the actual code
behind them later.
- Confusingly, both ppc32 and ppc64 have a
flush_dcache_range(), but they're subtly different: it uses dcbf on
ppc32 and dcbst on ppc64, ppc64 has a flush_inval_dcache_range() which
uses dcbf. These too should be merged and consolidated later.
- Also flush_dcache_range() was defined in cacheflush.h on
ppc64, and in cache.h on ppc32. In the merged version it's in
cacheflush.h
- On ppc32 flush_icache_range() is a normal function from
misc.S. On ppc64, it was wrapper, testing a feature bit before
calling __flush_icache_range() which does the actual flush. This
patch takes the ppc64 approach, which amounts to no change on ppc32,
since CPU_FTR_COHERENT_ICACHE will never be set there, but does mean
renaming flush_icache_range() to __flush_icache_range() in
arch/ppc/kernel/misc.S and arch/powerpc/kernel/misc_32.S
- The PReP register info from asm-ppc/cache.h has moved to
arch/ppc/platforms/prep_setup.c
- The 8xx register info from asm-ppc/cache.h has moved to a
new asm-powerpc/reg_8xx.h, included from reg.h
- flush_dcache_all() was defined on ppc32 (only), but was
never called (although it was exported). Thus this patch removes it
from cacheflush.h and from ARCH=powerpc (misc_32.S) entirely. It's
left in ARCH=ppc for now, with the prototype moved to ppc_ksyms.c.
Built for Walnut (ARCH=ppc), 32-bit multiplatform (pmac, CHRP and PReP
ARCH=ppc, pmac and CHRP ARCH=powerpc). Built and booted on POWER5
LPAR (ARCH=powerpc and ARCH=ppc64).
Built for 32-bit powermac (ARCH=ppc and ARCH=powerpc). Built and
booted on POWER5 LPAR (ARCH=powerpc and ARCH=ppc64). Built and booted
on G5 (ARCH=powerpc)
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-10 00:50:16 +00:00
|
|
|
/*
|
|
|
|
*/
|
|
|
|
#ifndef _ASM_POWERPC_CACHEFLUSH_H
|
|
|
|
#define _ASM_POWERPC_CACHEFLUSH_H
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <asm/cputable.h>
|
2020-07-01 07:22:31 +00:00
|
|
|
#include <asm/cpu_has_feature.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2021-02-03 04:58:11 +00:00
|
|
|
/*
|
|
|
|
* This flag is used to indicate that the page pointed to by a pte is clean
|
|
|
|
* and does not require cleaning before returning it to the user.
|
|
|
|
*/
|
|
|
|
#define PG_dcache_clean PG_arch_1
|
|
|
|
|
2018-06-06 01:40:08 +00:00
|
|
|
#ifdef CONFIG_PPC_BOOK3S_64
|
2018-06-01 10:01:19 +00:00
|
|
|
/*
|
|
|
|
* Book3s has no ptesync after setting a pte, so without this ptesync it's
|
|
|
|
* possible for a kernel virtual mapping access to return a spurious fault
|
|
|
|
* if it's accessed right after the pte is set. The page fault handler does
|
|
|
|
* not expect this type of fault. flush_cache_vmap is not exactly the right
|
|
|
|
* place to put this, but it seems to work well enough.
|
|
|
|
*/
|
2019-06-06 13:58:13 +00:00
|
|
|
static inline void flush_cache_vmap(unsigned long start, unsigned long end)
|
|
|
|
{
|
|
|
|
asm volatile("ptesync" ::: "memory");
|
|
|
|
}
|
2020-06-08 04:42:12 +00:00
|
|
|
#define flush_cache_vmap flush_cache_vmap
|
|
|
|
#endif /* CONFIG_PPC_BOOK3S_64 */
|
2018-06-01 10:01:19 +00:00
|
|
|
|
2009-11-26 08:16:19 +00:00
|
|
|
#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
|
2021-04-08 15:30:32 +00:00
|
|
|
/*
|
|
|
|
* This is called when a page has been modified by the kernel.
|
|
|
|
* It just marks the page as not i-cache clean. We do the i-cache
|
|
|
|
* flush later when the page is given to a user process, if necessary.
|
|
|
|
*/
|
|
|
|
static inline void flush_dcache_page(struct page *page)
|
|
|
|
{
|
|
|
|
if (cpu_has_feature(CPU_FTR_COHERENT_ICACHE))
|
|
|
|
return;
|
|
|
|
/* avoid an atomic op if possible */
|
|
|
|
if (test_bit(PG_dcache_clean, &page->flags))
|
|
|
|
clear_bit(PG_dcache_clean, &page->flags);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2019-11-04 02:32:56 +00:00
|
|
|
void flush_icache_range(unsigned long start, unsigned long stop);
|
2020-06-08 04:42:12 +00:00
|
|
|
#define flush_icache_range flush_icache_range
|
|
|
|
|
2020-06-08 04:42:22 +00:00
|
|
|
void flush_icache_user_page(struct vm_area_struct *vma, struct page *page,
|
2020-06-08 04:42:12 +00:00
|
|
|
unsigned long addr, int len);
|
2020-06-08 04:42:22 +00:00
|
|
|
#define flush_icache_user_page flush_icache_user_page
|
2020-06-08 04:42:12 +00:00
|
|
|
|
|
|
|
void flush_dcache_icache_page(struct page *page);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2019-11-04 02:32:56 +00:00
|
|
|
/**
|
|
|
|
* flush_dcache_range(): Write any modified data cache blocks out to memory and
|
|
|
|
* invalidate them. Does not invalidate the corresponding instruction cache
|
|
|
|
* blocks.
|
|
|
|
*
|
|
|
|
* @start: the start address
|
|
|
|
* @stop: the stop address (exclusive)
|
2016-02-09 16:08:27 +00:00
|
|
|
*/
|
|
|
|
static inline void flush_dcache_range(unsigned long start, unsigned long stop)
|
|
|
|
{
|
2019-11-04 02:32:55 +00:00
|
|
|
unsigned long shift = l1_dcache_shift();
|
|
|
|
unsigned long bytes = l1_dcache_bytes();
|
2019-05-14 09:05:15 +00:00
|
|
|
void *addr = (void *)(start & ~(bytes - 1));
|
|
|
|
unsigned long size = stop - (unsigned long)addr + (bytes - 1);
|
2016-02-09 16:08:27 +00:00
|
|
|
unsigned long i;
|
|
|
|
|
2020-03-20 10:32:42 +00:00
|
|
|
if (IS_ENABLED(CONFIG_PPC64))
|
powerpc/64: reuse PPC32 static inline flush_dcache_range()
This patch drops the assembly PPC64 version of flush_dcache_range()
and re-uses the PPC32 static inline version.
With GCC 8.1, the following code is generated:
void flush_test(unsigned long start, unsigned long stop)
{
flush_dcache_range(start, stop);
}
0000000000000130 <.flush_test>:
130: 3d 22 00 00 addis r9,r2,0
132: R_PPC64_TOC16_HA .data+0x8
134: 81 09 00 00 lwz r8,0(r9)
136: R_PPC64_TOC16_LO .data+0x8
138: 3d 22 00 00 addis r9,r2,0
13a: R_PPC64_TOC16_HA .data+0xc
13c: 80 e9 00 00 lwz r7,0(r9)
13e: R_PPC64_TOC16_LO .data+0xc
140: 7d 48 00 d0 neg r10,r8
144: 7d 43 18 38 and r3,r10,r3
148: 7c 00 04 ac hwsync
14c: 4c 00 01 2c isync
150: 39 28 ff ff addi r9,r8,-1
154: 7c 89 22 14 add r4,r9,r4
158: 7c 83 20 50 subf r4,r3,r4
15c: 7c 89 3c 37 srd. r9,r4,r7
160: 41 82 00 1c beq 17c <.flush_test+0x4c>
164: 7d 29 03 a6 mtctr r9
168: 60 00 00 00 nop
16c: 60 00 00 00 nop
170: 7c 00 18 ac dcbf 0,r3
174: 7c 63 42 14 add r3,r3,r8
178: 42 00 ff f8 bdnz 170 <.flush_test+0x40>
17c: 7c 00 04 ac hwsync
180: 4c 00 01 2c isync
184: 4e 80 00 20 blr
188: 60 00 00 00 nop
18c: 60 00 00 00 nop
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-05-14 09:05:16 +00:00
|
|
|
mb(); /* sync */
|
|
|
|
|
2019-05-14 09:05:15 +00:00
|
|
|
for (i = 0; i < size >> shift; i++, addr += bytes)
|
2016-02-09 16:08:27 +00:00
|
|
|
dcbf(addr);
|
|
|
|
mb(); /* sync */
|
powerpc/64: reuse PPC32 static inline flush_dcache_range()
This patch drops the assembly PPC64 version of flush_dcache_range()
and re-uses the PPC32 static inline version.
With GCC 8.1, the following code is generated:
void flush_test(unsigned long start, unsigned long stop)
{
flush_dcache_range(start, stop);
}
0000000000000130 <.flush_test>:
130: 3d 22 00 00 addis r9,r2,0
132: R_PPC64_TOC16_HA .data+0x8
134: 81 09 00 00 lwz r8,0(r9)
136: R_PPC64_TOC16_LO .data+0x8
138: 3d 22 00 00 addis r9,r2,0
13a: R_PPC64_TOC16_HA .data+0xc
13c: 80 e9 00 00 lwz r7,0(r9)
13e: R_PPC64_TOC16_LO .data+0xc
140: 7d 48 00 d0 neg r10,r8
144: 7d 43 18 38 and r3,r10,r3
148: 7c 00 04 ac hwsync
14c: 4c 00 01 2c isync
150: 39 28 ff ff addi r9,r8,-1
154: 7c 89 22 14 add r4,r9,r4
158: 7c 83 20 50 subf r4,r3,r4
15c: 7c 89 3c 37 srd. r9,r4,r7
160: 41 82 00 1c beq 17c <.flush_test+0x4c>
164: 7d 29 03 a6 mtctr r9
168: 60 00 00 00 nop
16c: 60 00 00 00 nop
170: 7c 00 18 ac dcbf 0,r3
174: 7c 63 42 14 add r3,r3,r8
178: 42 00 ff f8 bdnz 170 <.flush_test+0x40>
17c: 7c 00 04 ac hwsync
180: 4c 00 01 2c isync
184: 4e 80 00 20 blr
188: 60 00 00 00 nop
18c: 60 00 00 00 nop
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-05-14 09:05:16 +00:00
|
|
|
|
2016-02-09 16:08:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write any modified data cache blocks out to memory.
|
|
|
|
* Does not invalidate the corresponding cache lines (especially for
|
|
|
|
* any corresponding instruction cache).
|
|
|
|
*/
|
|
|
|
static inline void clean_dcache_range(unsigned long start, unsigned long stop)
|
|
|
|
{
|
2019-11-04 02:32:55 +00:00
|
|
|
unsigned long shift = l1_dcache_shift();
|
|
|
|
unsigned long bytes = l1_dcache_bytes();
|
2019-05-14 09:05:15 +00:00
|
|
|
void *addr = (void *)(start & ~(bytes - 1));
|
|
|
|
unsigned long size = stop - (unsigned long)addr + (bytes - 1);
|
2016-02-09 16:08:27 +00:00
|
|
|
unsigned long i;
|
|
|
|
|
2019-05-14 09:05:15 +00:00
|
|
|
for (i = 0; i < size >> shift; i++, addr += bytes)
|
2016-02-09 16:08:27 +00:00
|
|
|
dcbst(addr);
|
|
|
|
mb(); /* sync */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Like above, but invalidate the D-cache. This is used by the 8xx
|
|
|
|
* to invalidate the cache so the PPC core doesn't get stale data
|
|
|
|
* from the CPM (no cache snooping here :-).
|
|
|
|
*/
|
|
|
|
static inline void invalidate_dcache_range(unsigned long start,
|
|
|
|
unsigned long stop)
|
|
|
|
{
|
2019-11-04 02:32:55 +00:00
|
|
|
unsigned long shift = l1_dcache_shift();
|
|
|
|
unsigned long bytes = l1_dcache_bytes();
|
2019-05-14 09:05:15 +00:00
|
|
|
void *addr = (void *)(start & ~(bytes - 1));
|
|
|
|
unsigned long size = stop - (unsigned long)addr + (bytes - 1);
|
2016-02-09 16:08:27 +00:00
|
|
|
unsigned long i;
|
|
|
|
|
2019-05-14 09:05:15 +00:00
|
|
|
for (i = 0; i < size >> shift; i++, addr += bytes)
|
2016-02-09 16:08:27 +00:00
|
|
|
dcbi(addr);
|
|
|
|
mb(); /* sync */
|
|
|
|
}
|
|
|
|
|
2020-08-14 05:56:26 +00:00
|
|
|
#ifdef CONFIG_4xx
|
|
|
|
static inline void flush_instruction_cache(void)
|
|
|
|
{
|
|
|
|
iccci((void *)KERNELBASE);
|
|
|
|
isync();
|
|
|
|
}
|
|
|
|
#else
|
2020-08-14 05:56:25 +00:00
|
|
|
void flush_instruction_cache(void);
|
2020-08-14 05:56:26 +00:00
|
|
|
#endif
|
2020-08-14 05:56:25 +00:00
|
|
|
|
2020-06-08 04:42:12 +00:00
|
|
|
#include <asm-generic/cacheflush.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
[PATCH] powerpc: Merge cacheflush.h and cache.h
The ppc32 and ppc64 versions of cacheflush.h were almost identical.
The two versions of cache.h are fairly similar, except for a bunch of
register definitions in the ppc32 version which probably belong better
elsewhere. This patch, therefore, merges both headers. Notable
points:
- there are several functions in cacheflush.h which exist only
on ppc32 or only on ppc64. These are handled by #ifdef for now, but
these should probably be consolidated, along with the actual code
behind them later.
- Confusingly, both ppc32 and ppc64 have a
flush_dcache_range(), but they're subtly different: it uses dcbf on
ppc32 and dcbst on ppc64, ppc64 has a flush_inval_dcache_range() which
uses dcbf. These too should be merged and consolidated later.
- Also flush_dcache_range() was defined in cacheflush.h on
ppc64, and in cache.h on ppc32. In the merged version it's in
cacheflush.h
- On ppc32 flush_icache_range() is a normal function from
misc.S. On ppc64, it was wrapper, testing a feature bit before
calling __flush_icache_range() which does the actual flush. This
patch takes the ppc64 approach, which amounts to no change on ppc32,
since CPU_FTR_COHERENT_ICACHE will never be set there, but does mean
renaming flush_icache_range() to __flush_icache_range() in
arch/ppc/kernel/misc.S and arch/powerpc/kernel/misc_32.S
- The PReP register info from asm-ppc/cache.h has moved to
arch/ppc/platforms/prep_setup.c
- The 8xx register info from asm-ppc/cache.h has moved to a
new asm-powerpc/reg_8xx.h, included from reg.h
- flush_dcache_all() was defined on ppc32 (only), but was
never called (although it was exported). Thus this patch removes it
from cacheflush.h and from ARCH=powerpc (misc_32.S) entirely. It's
left in ARCH=ppc for now, with the prototype moved to ppc_ksyms.c.
Built for Walnut (ARCH=ppc), 32-bit multiplatform (pmac, CHRP and PReP
ARCH=ppc, pmac and CHRP ARCH=powerpc). Built and booted on POWER5
LPAR (ARCH=powerpc and ARCH=ppc64).
Built for 32-bit powermac (ARCH=ppc and ARCH=powerpc). Built and
booted on POWER5 LPAR (ARCH=powerpc and ARCH=ppc64). Built and booted
on G5 (ARCH=powerpc)
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-10 00:50:16 +00:00
|
|
|
#endif /* _ASM_POWERPC_CACHEFLUSH_H */
|