Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/sh/mm/cache-sh4.c |
| 3 | * |
| 4 | * Copyright (C) 1999, 2000, 2002 Niibe Yutaka |
Paul Mundt | deaef20 | 2009-09-09 16:06:39 +0900 | [diff] [blame] | 5 | * Copyright (C) 2001 - 2009 Paul Mundt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Copyright (C) 2003 Richard Curnow |
Chris Smith | 09b5a10 | 2008-07-02 15:17:11 +0900 | [diff] [blame] | 7 | * Copyright (c) 2007 STMicroelectronics (R&D) Ltd. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * This file is subject to the terms and conditions of the GNU General Public |
| 10 | * License. See the file "COPYING" in the main directory of this archive |
| 11 | * for more details. |
| 12 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/mm.h> |
Paul Mundt | 52e2778 | 2006-11-21 11:09:41 +0900 | [diff] [blame] | 15 | #include <linux/io.h> |
| 16 | #include <linux/mutex.h> |
Paul Mundt | 2277ab4 | 2009-07-22 19:20:49 +0900 | [diff] [blame] | 17 | #include <linux/fs.h> |
Paul Mundt | deaef20 | 2009-09-09 16:06:39 +0900 | [diff] [blame] | 18 | #include <linux/highmem.h> |
| 19 | #include <asm/pgtable.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <asm/mmu_context.h> |
| 21 | #include <asm/cacheflush.h> |
| 22 | |
Paul Mundt | 28ccf7f | 2006-09-27 18:30:07 +0900 | [diff] [blame] | 23 | /* |
| 24 | * The maximum number of pages we support up to when doing ranged dcache |
| 25 | * flushing. Anything exceeding this will simply flush the dcache in its |
| 26 | * entirety. |
| 27 | */ |
Chris Smith | 09b5a10 | 2008-07-02 15:17:11 +0900 | [diff] [blame] | 28 | #define MAX_ICACHE_PAGES 32 |
Paul Mundt | 28ccf7f | 2006-09-27 18:30:07 +0900 | [diff] [blame] | 29 | |
Valentin Sitdikov | a7a7c0e | 2009-10-16 14:15:38 +0900 | [diff] [blame] | 30 | static void __flush_cache_one(unsigned long addr, unsigned long phys, |
Paul Mundt | a252710 | 2006-09-27 11:29:55 +0900 | [diff] [blame] | 31 | unsigned long exec_offset); |
Richard Curnow | b638d0b | 2006-09-27 14:09:26 +0900 | [diff] [blame] | 32 | |
| 33 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | * Write back the range of D-cache, and purge the I-cache. |
| 35 | * |
Chris Smith | 09b5a10 | 2008-07-02 15:17:11 +0900 | [diff] [blame] | 36 | * Called from kernel/module.c:sys_init_module and routine for a.out format, |
| 37 | * signal handler code and kprobes code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | */ |
Matt Fleming | a632524 | 2009-10-06 21:22:21 +0000 | [diff] [blame] | 39 | static void __uses_jump_to_uncached sh4_flush_icache_range(void *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { |
Paul Mundt | f26b2a5 | 2009-08-21 17:23:14 +0900 | [diff] [blame] | 41 | struct flusher_data *data = args; |
Paul Mundt | f26b2a5 | 2009-08-21 17:23:14 +0900 | [diff] [blame] | 42 | unsigned long start, end; |
Paul Mundt | 983f4c5 | 2009-09-01 21:12:55 +0900 | [diff] [blame] | 43 | unsigned long flags, v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | int i; |
| 45 | |
Paul Mundt | f26b2a5 | 2009-08-21 17:23:14 +0900 | [diff] [blame] | 46 | start = data->addr1; |
| 47 | end = data->addr2; |
| 48 | |
Paul Mundt | 682f88a | 2009-09-09 13:19:46 +0900 | [diff] [blame] | 49 | /* If there are too many pages then just blow away the caches */ |
| 50 | if (((end - start) >> PAGE_SHIFT) >= MAX_ICACHE_PAGES) { |
| 51 | local_flush_cache_all(NULL); |
| 52 | return; |
Chris Smith | 09b5a10 | 2008-07-02 15:17:11 +0900 | [diff] [blame] | 53 | } |
Paul Mundt | 682f88a | 2009-09-09 13:19:46 +0900 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | * Selectively flush d-cache then invalidate the i-cache. |
| 57 | * This is inefficient, so only use this for small ranges. |
| 58 | */ |
| 59 | start &= ~(L1_CACHE_BYTES-1); |
| 60 | end += L1_CACHE_BYTES-1; |
| 61 | end &= ~(L1_CACHE_BYTES-1); |
| 62 | |
| 63 | local_irq_save(flags); |
| 64 | jump_to_uncached(); |
| 65 | |
| 66 | for (v = start; v < end; v += L1_CACHE_BYTES) { |
| 67 | unsigned long icacheaddr; |
| 68 | |
| 69 | __ocbwb(v); |
| 70 | |
| 71 | icacheaddr = CACHE_IC_ADDRESS_ARRAY | (v & |
| 72 | cpu_data->icache.entry_mask); |
| 73 | |
| 74 | /* Clear i-cache line valid-bit */ |
| 75 | for (i = 0; i < cpu_data->icache.ways; i++) { |
| 76 | __raw_writel(0, icacheaddr); |
| 77 | icacheaddr += cpu_data->icache.way_incr; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | back_to_cached(); |
| 82 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Valentin Sitdikov | a7a7c0e | 2009-10-16 14:15:38 +0900 | [diff] [blame] | 85 | static inline void flush_cache_one(unsigned long start, unsigned long phys) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
Paul Mundt | 983f4c5 | 2009-09-01 21:12:55 +0900 | [diff] [blame] | 87 | unsigned long flags, exec_offset = 0; |
Paul Mundt | 33573c0 | 2006-09-27 18:37:30 +0900 | [diff] [blame] | 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | /* |
Matt Fleming | 1f69b6a | 2009-10-06 21:22:25 +0000 | [diff] [blame] | 90 | * All types of SH-4 require PC to be uncached to operate on the I-cache. |
| 91 | * Some types of SH-4 require PC to be uncached to operate on the D-cache. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | */ |
Paul Mundt | 7ec9d6f | 2007-09-21 18:05:20 +0900 | [diff] [blame] | 93 | if ((boot_cpu_data.flags & CPU_HAS_P2_FLUSH_BUG) || |
Paul Mundt | 33573c0 | 2006-09-27 18:37:30 +0900 | [diff] [blame] | 94 | (start < CACHE_OC_ADDRESS_ARRAY)) |
Matt Fleming | 1f69b6a | 2009-10-06 21:22:25 +0000 | [diff] [blame] | 95 | exec_offset = cached_to_uncached; |
Paul Mundt | 28ccf7f | 2006-09-27 18:30:07 +0900 | [diff] [blame] | 96 | |
Paul Mundt | 983f4c5 | 2009-09-01 21:12:55 +0900 | [diff] [blame] | 97 | local_irq_save(flags); |
Paul Mundt | abeaf33 | 2009-10-16 15:14:50 +0900 | [diff] [blame^] | 98 | __flush_cache_one(start | SH_CACHE_ASSOC, |
| 99 | virt_to_phys(phys), exec_offset); |
Paul Mundt | 983f4c5 | 2009-09-01 21:12:55 +0900 | [diff] [blame] | 100 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /* |
| 104 | * Write back & invalidate the D-cache of the page. |
| 105 | * (To avoid "alias" issues) |
| 106 | */ |
Paul Mundt | e76a013 | 2009-08-27 11:31:16 +0900 | [diff] [blame] | 107 | static void sh4_flush_dcache_page(void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | { |
Paul Mundt | e76a013 | 2009-08-27 11:31:16 +0900 | [diff] [blame] | 109 | struct page *page = arg; |
Paul Mundt | c139a59 | 2009-08-20 15:24:41 +0900 | [diff] [blame] | 110 | #ifndef CONFIG_SMP |
Paul Mundt | 2277ab4 | 2009-07-22 19:20:49 +0900 | [diff] [blame] | 111 | struct address_space *mapping = page_mapping(page); |
| 112 | |
Paul Mundt | 2277ab4 | 2009-07-22 19:20:49 +0900 | [diff] [blame] | 113 | if (mapping && !mapping_mapped(mapping)) |
| 114 | set_bit(PG_dcache_dirty, &page->flags); |
| 115 | else |
| 116 | #endif |
| 117 | { |
Paul Mundt | 31c9efd | 2009-09-09 14:10:28 +0900 | [diff] [blame] | 118 | unsigned long phys = page_to_phys(page); |
Richard Curnow | b638d0b | 2006-09-27 14:09:26 +0900 | [diff] [blame] | 119 | unsigned long addr = CACHE_OC_ADDRESS_ARRAY; |
| 120 | int i, n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | /* Loop all the D-cache */ |
Paul Mundt | 7ec9d6f | 2007-09-21 18:05:20 +0900 | [diff] [blame] | 123 | n = boot_cpu_data.dcache.n_aliases; |
Paul Mundt | abeaf33 | 2009-10-16 15:14:50 +0900 | [diff] [blame^] | 124 | for (i = 0; i <= n; i++, addr += PAGE_SIZE) |
Valentin Sitdikov | a7a7c0e | 2009-10-16 14:15:38 +0900 | [diff] [blame] | 125 | flush_cache_one(addr, phys); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | } |
Paul Mundt | fdfc74f | 2006-09-27 14:05:52 +0900 | [diff] [blame] | 127 | |
| 128 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Paul Mundt | 28ccf7f | 2006-09-27 18:30:07 +0900 | [diff] [blame] | 131 | /* TODO: Selective icache invalidation through IC address array.. */ |
Paul Mundt | 205a3b4 | 2008-09-05 18:00:29 +0900 | [diff] [blame] | 132 | static void __uses_jump_to_uncached flush_icache_all(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | { |
Paul Mundt | 983f4c5 | 2009-09-01 21:12:55 +0900 | [diff] [blame] | 134 | unsigned long flags, ccr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Paul Mundt | 983f4c5 | 2009-09-01 21:12:55 +0900 | [diff] [blame] | 136 | local_irq_save(flags); |
Stuart Menefy | cbaa118 | 2007-11-30 17:06:36 +0900 | [diff] [blame] | 137 | jump_to_uncached(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
| 139 | /* Flush I-cache */ |
| 140 | ccr = ctrl_inl(CCR); |
| 141 | ccr |= CCR_CACHE_ICI; |
| 142 | ctrl_outl(ccr, CCR); |
| 143 | |
Paul Mundt | 2984762 | 2006-09-27 14:57:44 +0900 | [diff] [blame] | 144 | /* |
Stuart Menefy | cbaa118 | 2007-11-30 17:06:36 +0900 | [diff] [blame] | 145 | * back_to_cached() will take care of the barrier for us, don't add |
Paul Mundt | 2984762 | 2006-09-27 14:57:44 +0900 | [diff] [blame] | 146 | * another one! |
| 147 | */ |
Paul Mundt | 983f4c5 | 2009-09-01 21:12:55 +0900 | [diff] [blame] | 148 | |
Stuart Menefy | cbaa118 | 2007-11-30 17:06:36 +0900 | [diff] [blame] | 149 | back_to_cached(); |
Paul Mundt | 983f4c5 | 2009-09-01 21:12:55 +0900 | [diff] [blame] | 150 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Paul Mundt | bd6df57 | 2009-09-09 14:22:15 +0900 | [diff] [blame] | 153 | static void flush_dcache_all(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
Paul Mundt | bd6df57 | 2009-09-09 14:22:15 +0900 | [diff] [blame] | 155 | unsigned long addr, end_addr, entry_offset; |
| 156 | |
| 157 | end_addr = CACHE_OC_ADDRESS_ARRAY + |
| 158 | (current_cpu_data.dcache.sets << |
| 159 | current_cpu_data.dcache.entry_shift) * |
| 160 | current_cpu_data.dcache.ways; |
| 161 | |
| 162 | entry_offset = 1 << current_cpu_data.dcache.entry_shift; |
| 163 | |
| 164 | for (addr = CACHE_OC_ADDRESS_ARRAY; addr < end_addr; ) { |
| 165 | __raw_writel(0, addr); addr += entry_offset; |
| 166 | __raw_writel(0, addr); addr += entry_offset; |
| 167 | __raw_writel(0, addr); addr += entry_offset; |
| 168 | __raw_writel(0, addr); addr += entry_offset; |
| 169 | __raw_writel(0, addr); addr += entry_offset; |
| 170 | __raw_writel(0, addr); addr += entry_offset; |
| 171 | __raw_writel(0, addr); addr += entry_offset; |
| 172 | __raw_writel(0, addr); addr += entry_offset; |
| 173 | } |
Paul Mundt | a252710 | 2006-09-27 11:29:55 +0900 | [diff] [blame] | 174 | } |
| 175 | |
Paul Mundt | f26b2a5 | 2009-08-21 17:23:14 +0900 | [diff] [blame] | 176 | static void sh4_flush_cache_all(void *unused) |
Paul Mundt | a252710 | 2006-09-27 11:29:55 +0900 | [diff] [blame] | 177 | { |
| 178 | flush_dcache_all(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | flush_icache_all(); |
| 180 | } |
| 181 | |
Paul Mundt | 28ccf7f | 2006-09-27 18:30:07 +0900 | [diff] [blame] | 182 | /* |
| 183 | * Note : (RPC) since the caches are physically tagged, the only point |
| 184 | * of flush_cache_mm for SH-4 is to get rid of aliases from the |
| 185 | * D-cache. The assumption elsewhere, e.g. flush_cache_range, is that |
| 186 | * lines can stay resident so long as the virtual address they were |
| 187 | * accessed with (hence cache set) is in accord with the physical |
Paul Mundt | 654d364 | 2009-09-09 14:04:06 +0900 | [diff] [blame] | 188 | * address (i.e. tag). It's no different here. |
Paul Mundt | 28ccf7f | 2006-09-27 18:30:07 +0900 | [diff] [blame] | 189 | * |
| 190 | * Caller takes mm->mmap_sem. |
| 191 | */ |
Paul Mundt | f26b2a5 | 2009-08-21 17:23:14 +0900 | [diff] [blame] | 192 | static void sh4_flush_cache_mm(void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
Paul Mundt | f26b2a5 | 2009-08-21 17:23:14 +0900 | [diff] [blame] | 194 | struct mm_struct *mm = arg; |
| 195 | |
Paul Mundt | e7b8b7f | 2009-08-15 02:21:16 +0900 | [diff] [blame] | 196 | if (cpu_context(smp_processor_id(), mm) == NO_CONTEXT) |
| 197 | return; |
| 198 | |
Paul Mundt | 654d364 | 2009-09-09 14:04:06 +0900 | [diff] [blame] | 199 | flush_dcache_all(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | /* |
| 203 | * Write back and invalidate I/D-caches for the page. |
| 204 | * |
| 205 | * ADDR: Virtual Address (U0 address) |
| 206 | * PFN: Physical page number |
| 207 | */ |
Paul Mundt | f26b2a5 | 2009-08-21 17:23:14 +0900 | [diff] [blame] | 208 | static void sh4_flush_cache_page(void *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
Paul Mundt | f26b2a5 | 2009-08-21 17:23:14 +0900 | [diff] [blame] | 210 | struct flusher_data *data = args; |
| 211 | struct vm_area_struct *vma; |
Paul Mundt | deaef20 | 2009-09-09 16:06:39 +0900 | [diff] [blame] | 212 | struct page *page; |
Paul Mundt | f26b2a5 | 2009-08-21 17:23:14 +0900 | [diff] [blame] | 213 | unsigned long address, pfn, phys; |
Paul Mundt | deaef20 | 2009-09-09 16:06:39 +0900 | [diff] [blame] | 214 | int map_coherent = 0; |
| 215 | pgd_t *pgd; |
| 216 | pud_t *pud; |
| 217 | pmd_t *pmd; |
| 218 | pte_t *pte; |
| 219 | void *vaddr; |
Richard Curnow | b638d0b | 2006-09-27 14:09:26 +0900 | [diff] [blame] | 220 | |
Paul Mundt | f26b2a5 | 2009-08-21 17:23:14 +0900 | [diff] [blame] | 221 | vma = data->vma; |
Paul Mundt | abeaf33 | 2009-10-16 15:14:50 +0900 | [diff] [blame^] | 222 | address = data->addr1 & PAGE_MASK; |
Paul Mundt | f26b2a5 | 2009-08-21 17:23:14 +0900 | [diff] [blame] | 223 | pfn = data->addr2; |
| 224 | phys = pfn << PAGE_SHIFT; |
Paul Mundt | deaef20 | 2009-09-09 16:06:39 +0900 | [diff] [blame] | 225 | page = pfn_to_page(pfn); |
Paul Mundt | f26b2a5 | 2009-08-21 17:23:14 +0900 | [diff] [blame] | 226 | |
Paul Mundt | e7b8b7f | 2009-08-15 02:21:16 +0900 | [diff] [blame] | 227 | if (cpu_context(smp_processor_id(), vma->vm_mm) == NO_CONTEXT) |
| 228 | return; |
| 229 | |
Paul Mundt | deaef20 | 2009-09-09 16:06:39 +0900 | [diff] [blame] | 230 | pgd = pgd_offset(vma->vm_mm, address); |
| 231 | pud = pud_offset(pgd, address); |
| 232 | pmd = pmd_offset(pud, address); |
| 233 | pte = pte_offset_kernel(pmd, address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Paul Mundt | deaef20 | 2009-09-09 16:06:39 +0900 | [diff] [blame] | 235 | /* If the page isn't present, there is nothing to do here. */ |
| 236 | if (!(pte_val(*pte) & _PAGE_PRESENT)) |
| 237 | return; |
| 238 | |
| 239 | if ((vma->vm_mm == current->active_mm)) |
| 240 | vaddr = NULL; |
| 241 | else { |
| 242 | /* |
| 243 | * Use kmap_coherent or kmap_atomic to do flushes for |
| 244 | * another ASID than the current one. |
| 245 | */ |
| 246 | map_coherent = (current_cpu_data.dcache.n_aliases && |
| 247 | !test_bit(PG_dcache_dirty, &page->flags) && |
| 248 | page_mapped(page)); |
| 249 | if (map_coherent) |
| 250 | vaddr = kmap_coherent(page, address); |
| 251 | else |
| 252 | vaddr = kmap_atomic(page, KM_USER0); |
| 253 | |
| 254 | address = (unsigned long)vaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Paul Mundt | deaef20 | 2009-09-09 16:06:39 +0900 | [diff] [blame] | 257 | if (pages_do_alias(address, phys)) |
Paul Mundt | abeaf33 | 2009-10-16 15:14:50 +0900 | [diff] [blame^] | 258 | flush_cache_one(CACHE_OC_ADDRESS_ARRAY | |
Paul Mundt | deaef20 | 2009-09-09 16:06:39 +0900 | [diff] [blame] | 259 | (address & shm_align_mask), phys); |
| 260 | |
| 261 | if (vma->vm_flags & VM_EXEC) |
| 262 | flush_icache_all(); |
| 263 | |
| 264 | if (vaddr) { |
| 265 | if (map_coherent) |
| 266 | kunmap_coherent(vaddr); |
| 267 | else |
| 268 | kunmap_atomic(vaddr, KM_USER0); |
Richard Curnow | b638d0b | 2006-09-27 14:09:26 +0900 | [diff] [blame] | 269 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /* |
| 273 | * Write back and invalidate D-caches. |
| 274 | * |
| 275 | * START, END: Virtual Address (U0 address) |
| 276 | * |
| 277 | * NOTE: We need to flush the _physical_ page entry. |
| 278 | * Flushing the cache lines for U0 only isn't enough. |
| 279 | * We need to flush for P1 too, which may contain aliases. |
| 280 | */ |
Paul Mundt | f26b2a5 | 2009-08-21 17:23:14 +0900 | [diff] [blame] | 281 | static void sh4_flush_cache_range(void *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | { |
Paul Mundt | f26b2a5 | 2009-08-21 17:23:14 +0900 | [diff] [blame] | 283 | struct flusher_data *data = args; |
| 284 | struct vm_area_struct *vma; |
| 285 | unsigned long start, end; |
| 286 | |
| 287 | vma = data->vma; |
| 288 | start = data->addr1; |
| 289 | end = data->addr2; |
| 290 | |
Paul Mundt | e7b8b7f | 2009-08-15 02:21:16 +0900 | [diff] [blame] | 291 | if (cpu_context(smp_processor_id(), vma->vm_mm) == NO_CONTEXT) |
| 292 | return; |
| 293 | |
Richard Curnow | b638d0b | 2006-09-27 14:09:26 +0900 | [diff] [blame] | 294 | /* |
| 295 | * If cache is only 4k-per-way, there are never any 'aliases'. Since |
| 296 | * the cache is physically tagged, the data can just be left in there. |
| 297 | */ |
Paul Mundt | 7ec9d6f | 2007-09-21 18:05:20 +0900 | [diff] [blame] | 298 | if (boot_cpu_data.dcache.n_aliases == 0) |
Richard Curnow | b638d0b | 2006-09-27 14:09:26 +0900 | [diff] [blame] | 299 | return; |
| 300 | |
Paul Mundt | 654d364 | 2009-09-09 14:04:06 +0900 | [diff] [blame] | 301 | flush_dcache_all(); |
Richard Curnow | b638d0b | 2006-09-27 14:09:26 +0900 | [diff] [blame] | 302 | |
Paul Mundt | 654d364 | 2009-09-09 14:04:06 +0900 | [diff] [blame] | 303 | if (vma->vm_flags & VM_EXEC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | flush_icache_all(); |
| 305 | } |
| 306 | |
Richard Curnow | b638d0b | 2006-09-27 14:09:26 +0900 | [diff] [blame] | 307 | /** |
Valentin Sitdikov | a7a7c0e | 2009-10-16 14:15:38 +0900 | [diff] [blame] | 308 | * __flush_cache_one |
Richard Curnow | b638d0b | 2006-09-27 14:09:26 +0900 | [diff] [blame] | 309 | * |
| 310 | * @addr: address in memory mapped cache array |
| 311 | * @phys: P1 address to flush (has to match tags if addr has 'A' bit |
| 312 | * set i.e. associative write) |
| 313 | * @exec_offset: set to 0x20000000 if flush has to be executed from P2 |
| 314 | * region else 0x0 |
| 315 | * |
| 316 | * The offset into the cache array implied by 'addr' selects the |
| 317 | * 'colour' of the virtual address range that will be flushed. The |
| 318 | * operation (purge/write-back) is selected by the lower 2 bits of |
| 319 | * 'phys'. |
| 320 | */ |
Valentin Sitdikov | a7a7c0e | 2009-10-16 14:15:38 +0900 | [diff] [blame] | 321 | static void __flush_cache_one(unsigned long addr, unsigned long phys, |
Richard Curnow | b638d0b | 2006-09-27 14:09:26 +0900 | [diff] [blame] | 322 | unsigned long exec_offset) |
| 323 | { |
| 324 | int way_count; |
| 325 | unsigned long base_addr = addr; |
| 326 | struct cache_info *dcache; |
| 327 | unsigned long way_incr; |
| 328 | unsigned long a, ea, p; |
| 329 | unsigned long temp_pc; |
| 330 | |
Paul Mundt | 7ec9d6f | 2007-09-21 18:05:20 +0900 | [diff] [blame] | 331 | dcache = &boot_cpu_data.dcache; |
Richard Curnow | b638d0b | 2006-09-27 14:09:26 +0900 | [diff] [blame] | 332 | /* Write this way for better assembly. */ |
| 333 | way_count = dcache->ways; |
| 334 | way_incr = dcache->way_incr; |
| 335 | |
| 336 | /* |
| 337 | * Apply exec_offset (i.e. branch to P2 if required.). |
| 338 | * |
| 339 | * FIXME: |
| 340 | * |
| 341 | * If I write "=r" for the (temp_pc), it puts this in r6 hence |
| 342 | * trashing exec_offset before it's been added on - why? Hence |
| 343 | * "=&r" as a 'workaround' |
| 344 | */ |
| 345 | asm volatile("mov.l 1f, %0\n\t" |
| 346 | "add %1, %0\n\t" |
| 347 | "jmp @%0\n\t" |
| 348 | "nop\n\t" |
| 349 | ".balign 4\n\t" |
| 350 | "1: .long 2f\n\t" |
| 351 | "2:\n" : "=&r" (temp_pc) : "r" (exec_offset)); |
| 352 | |
| 353 | /* |
| 354 | * We know there will be >=1 iteration, so write as do-while to avoid |
| 355 | * pointless nead-of-loop check for 0 iterations. |
| 356 | */ |
| 357 | do { |
| 358 | ea = base_addr + PAGE_SIZE; |
| 359 | a = base_addr; |
| 360 | p = phys; |
| 361 | |
| 362 | do { |
| 363 | *(volatile unsigned long *)a = p; |
| 364 | /* |
| 365 | * Next line: intentionally not p+32, saves an add, p |
| 366 | * will do since only the cache tag bits need to |
| 367 | * match. |
| 368 | */ |
| 369 | *(volatile unsigned long *)(a+32) = p; |
| 370 | a += 64; |
| 371 | p += 64; |
| 372 | } while (a < ea); |
| 373 | |
| 374 | base_addr += way_incr; |
| 375 | } while (--way_count != 0); |
| 376 | } |
| 377 | |
Paul Mundt | 37443ef | 2009-08-15 12:29:49 +0900 | [diff] [blame] | 378 | extern void __weak sh4__flush_region_init(void); |
| 379 | |
| 380 | /* |
| 381 | * SH-4 has virtually indexed and physically tagged cache. |
| 382 | */ |
| 383 | void __init sh4_cache_init(void) |
| 384 | { |
| 385 | printk("PVR=%08x CVR=%08x PRR=%08x\n", |
| 386 | ctrl_inl(CCN_PVR), |
| 387 | ctrl_inl(CCN_CVR), |
| 388 | ctrl_inl(CCN_PRR)); |
| 389 | |
Paul Mundt | f26b2a5 | 2009-08-21 17:23:14 +0900 | [diff] [blame] | 390 | local_flush_icache_range = sh4_flush_icache_range; |
| 391 | local_flush_dcache_page = sh4_flush_dcache_page; |
| 392 | local_flush_cache_all = sh4_flush_cache_all; |
| 393 | local_flush_cache_mm = sh4_flush_cache_mm; |
| 394 | local_flush_cache_dup_mm = sh4_flush_cache_mm; |
| 395 | local_flush_cache_page = sh4_flush_cache_page; |
| 396 | local_flush_cache_range = sh4_flush_cache_range; |
Paul Mundt | 37443ef | 2009-08-15 12:29:49 +0900 | [diff] [blame] | 397 | |
| 398 | sh4__flush_region_init(); |
| 399 | } |