Linux 2.6.28-rc5
[cris-mirror.git] / arch / sh / mm / cache-sh2a.c
blob24d86a794065f70d4ecb35cc4330ed982c0bfe56
1 /*
2 * arch/sh/mm/cache-sh2a.c
4 * Copyright (C) 2008 Yoshinori Sato
6 * Released under the terms of the GNU GPL v2.0.
7 */
9 #include <linux/init.h>
10 #include <linux/mm.h>
12 #include <asm/cache.h>
13 #include <asm/addrspace.h>
14 #include <asm/processor.h>
15 #include <asm/cacheflush.h>
16 #include <asm/io.h>
18 void __flush_wback_region(void *start, int size)
20 unsigned long v;
21 unsigned long begin, end;
22 unsigned long flags;
24 begin = (unsigned long)start & ~(L1_CACHE_BYTES-1);
25 end = ((unsigned long)start + size + L1_CACHE_BYTES-1)
26 & ~(L1_CACHE_BYTES-1);
28 local_irq_save(flags);
29 jump_to_uncached();
31 for (v = begin; v < end; v+=L1_CACHE_BYTES) {
32 unsigned long addr = CACHE_OC_ADDRESS_ARRAY | (v & 0x000007f0);
33 int way;
34 for (way = 0; way < 4; way++) {
35 unsigned long data = ctrl_inl(addr | (way << 11));
36 if ((data & CACHE_PHYSADDR_MASK) == (v & CACHE_PHYSADDR_MASK)) {
37 data &= ~SH_CACHE_UPDATED;
38 ctrl_outl(data, addr | (way << 11));
43 back_to_cached();
44 local_irq_restore(flags);
47 void __flush_purge_region(void *start, int size)
49 unsigned long v;
50 unsigned long begin, end;
51 unsigned long flags;
53 begin = (unsigned long)start & ~(L1_CACHE_BYTES-1);
54 end = ((unsigned long)start + size + L1_CACHE_BYTES-1)
55 & ~(L1_CACHE_BYTES-1);
57 local_irq_save(flags);
58 jump_to_uncached();
60 for (v = begin; v < end; v+=L1_CACHE_BYTES) {
61 ctrl_outl((v & CACHE_PHYSADDR_MASK),
62 CACHE_OC_ADDRESS_ARRAY | (v & 0x000007f0) | 0x00000008);
64 back_to_cached();
65 local_irq_restore(flags);
68 void __flush_invalidate_region(void *start, int size)
70 unsigned long v;
71 unsigned long begin, end;
72 unsigned long flags;
74 begin = (unsigned long)start & ~(L1_CACHE_BYTES-1);
75 end = ((unsigned long)start + size + L1_CACHE_BYTES-1)
76 & ~(L1_CACHE_BYTES-1);
77 local_irq_save(flags);
78 jump_to_uncached();
80 #ifdef CONFIG_CACHE_WRITEBACK
81 ctrl_outl(ctrl_inl(CCR) | CCR_OCACHE_INVALIDATE, CCR);
82 /* I-cache invalidate */
83 for (v = begin; v < end; v+=L1_CACHE_BYTES) {
84 ctrl_outl((v & CACHE_PHYSADDR_MASK),
85 CACHE_IC_ADDRESS_ARRAY | (v & 0x000007f0) | 0x00000008);
87 #else
88 for (v = begin; v < end; v+=L1_CACHE_BYTES) {
89 ctrl_outl((v & CACHE_PHYSADDR_MASK),
90 CACHE_IC_ADDRESS_ARRAY | (v & 0x000007f0) | 0x00000008);
91 ctrl_outl((v & CACHE_PHYSADDR_MASK),
92 CACHE_OC_ADDRESS_ARRAY | (v & 0x000007f0) | 0x00000008);
94 #endif
95 back_to_cached();
96 local_irq_restore(flags);
99 /* WBack O-Cache and flush I-Cache */
100 void flush_icache_range(unsigned long start, unsigned long end)
102 unsigned long v;
103 unsigned long flags;
105 start = start & ~(L1_CACHE_BYTES-1);
106 end = (end + L1_CACHE_BYTES-1) & ~(L1_CACHE_BYTES-1);
108 local_irq_save(flags);
109 jump_to_uncached();
111 for (v = start; v < end; v+=L1_CACHE_BYTES) {
112 unsigned long addr = (v & 0x000007f0);
113 int way;
114 /* O-Cache writeback */
115 for (way = 0; way < 4; way++) {
116 unsigned long data = ctrl_inl(CACHE_OC_ADDRESS_ARRAY | addr | (way << 11));
117 if ((data & CACHE_PHYSADDR_MASK) == (v & CACHE_PHYSADDR_MASK)) {
118 data &= ~SH_CACHE_UPDATED;
119 ctrl_outl(data, CACHE_OC_ADDRESS_ARRAY | addr | (way << 11));
122 /* I-Cache invalidate */
123 ctrl_outl(addr,
124 CACHE_IC_ADDRESS_ARRAY | addr | 0x00000008);
127 back_to_cached();
128 local_irq_restore(flags);