2 * arch/sh/mm/cache-sh7705.c
4 * Copyright (C) 1999, 2000 Niibe Yutaka
5 * Copyright (C) 2004 Alex Song
7 * This file is subject to the terms and conditions of the GNU General Public
8 * 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 = cpu_data->dcache.ways;
36 waysize = cpu_data->dcache.sets;
37 waysize <<= cpu_data->dcache.entry_shift;
39 addrstart = CACHE_OC_ADDRESS_ARRAY;
44 for (addr = addrstart;
45 addr < addrstart + waysize;
46 addr += cpu_data->dcache.linesz) {
48 int v = SH_CACHE_UPDATED | SH_CACHE_VALID;
50 data = ctrl_inl(addr);
53 ctrl_outl(data & ~v, addr);
57 addrstart += cpu_data->dcache.way_incr;
62 * Write back the range of D-cache, and purge the I-cache.
64 * Called from kernel/module.c:sys_init_module and routine for a.out format.
66 void flush_icache_range(unsigned long start, unsigned long end)
68 __flush_wback_region((void *)start, end - start);
72 * Writeback&Invalidate the D-cache of the page
74 static void __flush_dcache_page(unsigned long phys)
76 unsigned long ways, waysize, addrstart;
79 phys |= SH_CACHE_VALID;
82 * Here, phys is the physical address of the page. We check all the
83 * tags in the cache for those with the same page number as this page
84 * (by masking off the lowest 2 bits of the 19-bit tag; these bits are
85 * derived from the offset within in the 4k page). Matching valid
86 * entries are invalidated.
88 * Since 2 bits of the cache index are derived from the virtual page
89 * number, knowing this would reduce the number of cache entries to be
90 * searched by a factor of 4. However this function exists to deal with
91 * potential cache aliasing, therefore the optimisation is probably not
94 local_irq_save(flags);
97 ways = cpu_data->dcache.ways;
98 waysize = cpu_data->dcache.sets;
99 waysize <<= cpu_data->dcache.entry_shift;
101 addrstart = CACHE_OC_ADDRESS_ARRAY;
106 for (addr = addrstart;
107 addr < addrstart + waysize;
108 addr += cpu_data->dcache.linesz) {
111 data = ctrl_inl(addr) & (0x1ffffC00 | SH_CACHE_VALID);
113 data &= ~(SH_CACHE_VALID | SH_CACHE_UPDATED);
114 ctrl_outl(data, addr);
118 addrstart += cpu_data->dcache.way_incr;
122 local_irq_restore(flags);
126 * Write back & invalidate the D-cache of the page.
127 * (To avoid "alias" issues)
129 void flush_dcache_page(struct page *page)
131 if (test_bit(PG_mapped, &page->flags))
132 __flush_dcache_page(PHYSADDR(page_address(page)));
135 void flush_cache_all(void)
139 local_irq_save(flags);
144 local_irq_restore(flags);
147 void flush_cache_mm(struct mm_struct *mm)
149 /* Is there any good way? */
150 /* XXX: possibly call flush_cache_range for each vm area */
155 * Write back and invalidate D-caches.
157 * START, END: Virtual Address (U0 address)
159 * NOTE: We need to flush the _physical_ page entry.
160 * Flushing the cache lines for U0 only isn't enough.
161 * We need to flush for P1 too, which may contain aliases.
163 void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
168 * We could call flush_cache_page for the pages of these range,
169 * but it's not efficient (scan the caches all the time...).
171 * We can't use A-bit magic, as there's the case we don't have
172 * valid entry on TLB.
178 * Write back and invalidate I/D-caches for the page.
180 * ADDRESS: Virtual Address (U0 address)
182 void flush_cache_page(struct vm_area_struct *vma, unsigned long address,
185 __flush_dcache_page(pfn << PAGE_SHIFT);
189 * This is called when a page-cache page is about to be mapped into a
190 * user process' address space. It offers an opportunity for a
191 * port to ensure d-cache/i-cache coherency if necessary.
193 * Not entirely sure why this is necessary on SH3 with 32K cache but
194 * without it we get occasional "Memory fault" when loading a program.
196 void flush_icache_page(struct vm_area_struct *vma, struct page *page)
198 __flush_purge_region(page_address(page), PAGE_SIZE);