1 // SPDX-License-Identifier: GPL-2.0-only
3 * arch/sh/mm/cache-sh2.c
5 * Copyright (C) 2002 Paul Mundt
6 * Copyright (C) 2008 Yoshinori Sato
9 #include <linux/init.h>
12 #include <asm/cache.h>
13 #include <asm/addrspace.h>
14 #include <asm/processor.h>
15 #include <asm/cacheflush.h>
18 static void sh2__flush_wback_region(void *start
, int size
)
21 unsigned long begin
, end
;
23 begin
= (unsigned long)start
& ~(L1_CACHE_BYTES
-1);
24 end
= ((unsigned long)start
+ size
+ L1_CACHE_BYTES
-1)
25 & ~(L1_CACHE_BYTES
-1);
26 for (v
= begin
; v
< end
; v
+=L1_CACHE_BYTES
) {
27 unsigned long addr
= CACHE_OC_ADDRESS_ARRAY
| (v
& 0x00000ff0);
29 for (way
= 0; way
< 4; way
++) {
30 unsigned long data
= __raw_readl(addr
| (way
<< 12));
31 if ((data
& CACHE_PHYSADDR_MASK
) == (v
& CACHE_PHYSADDR_MASK
)) {
32 data
&= ~SH_CACHE_UPDATED
;
33 __raw_writel(data
, addr
| (way
<< 12));
39 static void sh2__flush_purge_region(void *start
, int size
)
42 unsigned long begin
, end
;
44 begin
= (unsigned long)start
& ~(L1_CACHE_BYTES
-1);
45 end
= ((unsigned long)start
+ size
+ L1_CACHE_BYTES
-1)
46 & ~(L1_CACHE_BYTES
-1);
48 for (v
= begin
; v
< end
; v
+=L1_CACHE_BYTES
)
49 __raw_writel((v
& CACHE_PHYSADDR_MASK
),
50 CACHE_OC_ADDRESS_ARRAY
| (v
& 0x00000ff0) | 0x00000008);
53 static void sh2__flush_invalidate_region(void *start
, int size
)
55 #ifdef CONFIG_CACHE_WRITEBACK
57 * SH-2 does not support individual line invalidation, only a
62 local_irq_save(flags
);
65 ccr
= __raw_readl(SH_CCR
);
66 ccr
|= CCR_CACHE_INVALIDATE
;
67 __raw_writel(ccr
, SH_CCR
);
70 local_irq_restore(flags
);
73 unsigned long begin
, end
;
75 begin
= (unsigned long)start
& ~(L1_CACHE_BYTES
-1);
76 end
= ((unsigned long)start
+ size
+ L1_CACHE_BYTES
-1)
77 & ~(L1_CACHE_BYTES
-1);
79 for (v
= begin
; v
< end
; v
+=L1_CACHE_BYTES
)
80 __raw_writel((v
& CACHE_PHYSADDR_MASK
),
81 CACHE_OC_ADDRESS_ARRAY
| (v
& 0x00000ff0) | 0x00000008);
85 void __init
sh2_cache_init(void)
87 __flush_wback_region
= sh2__flush_wback_region
;
88 __flush_purge_region
= sh2__flush_purge_region
;
89 __flush_invalidate_region
= sh2__flush_invalidate_region
;