2 * arch/sh/mm/cache-sh7705.c
4 * Copyright (C) 1999, 2000 Niibe Yutaka
5 * Copyright (C) 2004 Alex Song
6 * Copyright (C) 2006 Paul Mundt
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
12 #include <linux/init.h>
13 #include <linux/mman.h>
15 #include <linux/threads.h>
16 #include <asm/addrspace.h>
18 #include <asm/pgtable.h>
19 #include <asm/processor.h>
20 #include <asm/cache.h>
22 #include <asm/uaccess.h>
23 #include <asm/pgalloc.h>
24 #include <asm/mmu_context.h>
25 #include <asm/cacheflush.h>
28 * The 32KB cache on the SH7705 suffers from the same synonym problem
31 static inline void cache_wback_all(void)
33 unsigned long ways
, waysize
, addrstart
;
35 ways
= current_cpu_data
.dcache
.ways
;
36 waysize
= current_cpu_data
.dcache
.sets
;
37 waysize
<<= current_cpu_data
.dcache
.entry_shift
;
39 addrstart
= CACHE_OC_ADDRESS_ARRAY
;
44 for (addr
= addrstart
;
45 addr
< addrstart
+ waysize
;
46 addr
+= current_cpu_data
.dcache
.linesz
) {
48 int v
= SH_CACHE_UPDATED
| SH_CACHE_VALID
;
50 data
= ctrl_inl(addr
);
53 ctrl_outl(data
& ~v
, addr
);
56 addrstart
+= current_cpu_data
.dcache
.way_incr
;
61 * Write back the range of D-cache, and purge the I-cache.
63 * Called from kernel/module.c:sys_init_module and routine for a.out format.
65 void flush_icache_range(unsigned long start
, unsigned long end
)
67 __flush_wback_region((void *)start
, end
- start
);
71 * Writeback&Invalidate the D-cache of the page
73 static void __flush_dcache_page(unsigned long phys
)
75 unsigned long ways
, waysize
, addrstart
;
78 phys
|= SH_CACHE_VALID
;
81 * Here, phys is the physical address of the page. We check all the
82 * tags in the cache for those with the same page number as this page
83 * (by masking off the lowest 2 bits of the 19-bit tag; these bits are
84 * derived from the offset within in the 4k page). Matching valid
85 * entries are invalidated.
87 * Since 2 bits of the cache index are derived from the virtual page
88 * number, knowing this would reduce the number of cache entries to be
89 * searched by a factor of 4. However this function exists to deal with
90 * potential cache aliasing, therefore the optimisation is probably not
93 local_irq_save(flags
);
96 ways
= current_cpu_data
.dcache
.ways
;
97 waysize
= current_cpu_data
.dcache
.sets
;
98 waysize
<<= current_cpu_data
.dcache
.entry_shift
;
100 addrstart
= CACHE_OC_ADDRESS_ARRAY
;
105 for (addr
= addrstart
;
106 addr
< addrstart
+ waysize
;
107 addr
+= current_cpu_data
.dcache
.linesz
) {
110 data
= ctrl_inl(addr
) & (0x1ffffC00 | SH_CACHE_VALID
);
112 data
&= ~(SH_CACHE_VALID
| SH_CACHE_UPDATED
);
113 ctrl_outl(data
, addr
);
117 addrstart
+= current_cpu_data
.dcache
.way_incr
;
121 local_irq_restore(flags
);
125 * Write back & invalidate the D-cache of the page.
126 * (To avoid "alias" issues)
128 void flush_dcache_page(struct page
*page
)
130 struct address_space
*mapping
= page_mapping(page
);
132 if (mapping
&& !mapping_mapped(mapping
))
133 set_bit(PG_dcache_dirty
, &page
->flags
);
135 __flush_dcache_page(PHYSADDR(page_address(page
)));
138 void flush_cache_all(void)
142 local_irq_save(flags
);
147 local_irq_restore(flags
);
150 void flush_cache_mm(struct mm_struct
*mm
)
152 /* Is there any good way? */
153 /* XXX: possibly call flush_cache_range for each vm area */
158 * Write back and invalidate D-caches.
160 * START, END: Virtual Address (U0 address)
162 * NOTE: We need to flush the _physical_ page entry.
163 * Flushing the cache lines for U0 only isn't enough.
164 * We need to flush for P1 too, which may contain aliases.
166 void flush_cache_range(struct vm_area_struct
*vma
, unsigned long start
,
171 * We could call flush_cache_page for the pages of these range,
172 * but it's not efficient (scan the caches all the time...).
174 * We can't use A-bit magic, as there's the case we don't have
175 * valid entry on TLB.
181 * Write back and invalidate I/D-caches for the page.
183 * ADDRESS: Virtual Address (U0 address)
185 void flush_cache_page(struct vm_area_struct
*vma
, unsigned long address
,
188 __flush_dcache_page(pfn
<< PAGE_SHIFT
);
192 * This is called when a page-cache page is about to be mapped into a
193 * user process' address space. It offers an opportunity for a
194 * port to ensure d-cache/i-cache coherency if necessary.
196 * Not entirely sure why this is necessary on SH3 with 32K cache but
197 * without it we get occasional "Memory fault" when loading a program.
199 void flush_icache_page(struct vm_area_struct
*vma
, struct page
*page
)
201 __flush_purge_region(page_address(page
), PAGE_SIZE
);