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