diff options
Diffstat (limited to 'arch/sh/mm/cache-sh4.c')
| -rw-r--r-- | arch/sh/mm/cache-sh4.c | 501 |
1 files changed, 77 insertions, 424 deletions
diff --git a/arch/sh/mm/cache-sh4.c b/arch/sh/mm/cache-sh4.c index b7f235c74d66..f36a08bf3d5c 100644 --- a/arch/sh/mm/cache-sh4.c +++ b/arch/sh/mm/cache-sh4.c | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | * arch/sh/mm/cache-sh4.c | 2 | * arch/sh/mm/cache-sh4.c |
| 3 | * | 3 | * |
| 4 | * Copyright (C) 1999, 2000, 2002 Niibe Yutaka | 4 | * Copyright (C) 1999, 2000, 2002 Niibe Yutaka |
| 5 | * Copyright (C) 2001 - 2007 Paul Mundt | 5 | * Copyright (C) 2001 - 2009 Paul Mundt |
| 6 | * Copyright (C) 2003 Richard Curnow | 6 | * Copyright (C) 2003 Richard Curnow |
| 7 | * Copyright (c) 2007 STMicroelectronics (R&D) Ltd. | 7 | * Copyright (c) 2007 STMicroelectronics (R&D) Ltd. |
| 8 | * | 8 | * |
| @@ -15,6 +15,8 @@ | |||
| 15 | #include <linux/io.h> | 15 | #include <linux/io.h> |
| 16 | #include <linux/mutex.h> | 16 | #include <linux/mutex.h> |
| 17 | #include <linux/fs.h> | 17 | #include <linux/fs.h> |
| 18 | #include <linux/highmem.h> | ||
| 19 | #include <asm/pgtable.h> | ||
| 18 | #include <asm/mmu_context.h> | 20 | #include <asm/mmu_context.h> |
| 19 | #include <asm/cacheflush.h> | 21 | #include <asm/cacheflush.h> |
| 20 | 22 | ||
| @@ -23,21 +25,12 @@ | |||
| 23 | * flushing. Anything exceeding this will simply flush the dcache in its | 25 | * flushing. Anything exceeding this will simply flush the dcache in its |
| 24 | * entirety. | 26 | * entirety. |
| 25 | */ | 27 | */ |
| 26 | #define MAX_DCACHE_PAGES 64 /* XXX: Tune for ways */ | ||
| 27 | #define MAX_ICACHE_PAGES 32 | 28 | #define MAX_ICACHE_PAGES 32 |
| 28 | 29 | ||
| 29 | static void __flush_cache_one(unsigned long addr, unsigned long phys, | 30 | static void __flush_cache_one(unsigned long addr, unsigned long phys, |
| 30 | unsigned long exec_offset); | 31 | unsigned long exec_offset); |
| 31 | 32 | ||
| 32 | /* | 33 | /* |
| 33 | * This is initialised here to ensure that it is not placed in the BSS. If | ||
| 34 | * that were to happen, note that cache_init gets called before the BSS is | ||
| 35 | * cleared, so this would get nulled out which would be hopeless. | ||
| 36 | */ | ||
| 37 | static void (*__flush_dcache_segment_fn)(unsigned long, unsigned long) = | ||
| 38 | (void (*)(unsigned long, unsigned long))0xdeadbeef; | ||
| 39 | |||
| 40 | /* | ||
| 41 | * Write back the range of D-cache, and purge the I-cache. | 34 | * Write back the range of D-cache, and purge the I-cache. |
| 42 | * | 35 | * |
| 43 | * Called from kernel/module.c:sys_init_module and routine for a.out format, | 36 | * Called from kernel/module.c:sys_init_module and routine for a.out format, |
| @@ -97,15 +90,15 @@ static inline void flush_cache_one(unsigned long start, unsigned long phys) | |||
| 97 | unsigned long flags, exec_offset = 0; | 90 | unsigned long flags, exec_offset = 0; |
| 98 | 91 | ||
| 99 | /* | 92 | /* |
| 100 | * All types of SH-4 require PC to be in P2 to operate on the I-cache. | 93 | * All types of SH-4 require PC to be uncached to operate on the I-cache. |
| 101 | * Some types of SH-4 require PC to be in P2 to operate on the D-cache. | 94 | * Some types of SH-4 require PC to be uncached to operate on the D-cache. |
| 102 | */ | 95 | */ |
| 103 | if ((boot_cpu_data.flags & CPU_HAS_P2_FLUSH_BUG) || | 96 | if ((boot_cpu_data.flags & CPU_HAS_P2_FLUSH_BUG) || |
| 104 | (start < CACHE_OC_ADDRESS_ARRAY)) | 97 | (start < CACHE_OC_ADDRESS_ARRAY)) |
| 105 | exec_offset = 0x20000000; | 98 | exec_offset = cached_to_uncached; |
| 106 | 99 | ||
| 107 | local_irq_save(flags); | 100 | local_irq_save(flags); |
| 108 | __flush_cache_one(start | SH_CACHE_ASSOC, P1SEGADDR(phys), exec_offset); | 101 | __flush_cache_one(start, phys, exec_offset); |
| 109 | local_irq_restore(flags); | 102 | local_irq_restore(flags); |
| 110 | } | 103 | } |
| 111 | 104 | ||
| @@ -124,7 +117,7 @@ static void sh4_flush_dcache_page(void *arg) | |||
| 124 | else | 117 | else |
| 125 | #endif | 118 | #endif |
| 126 | { | 119 | { |
| 127 | unsigned long phys = PHYSADDR(page_address(page)); | 120 | unsigned long phys = page_to_phys(page); |
| 128 | unsigned long addr = CACHE_OC_ADDRESS_ARRAY; | 121 | unsigned long addr = CACHE_OC_ADDRESS_ARRAY; |
| 129 | int i, n; | 122 | int i, n; |
| 130 | 123 | ||
| @@ -159,10 +152,27 @@ static void __uses_jump_to_uncached flush_icache_all(void) | |||
| 159 | local_irq_restore(flags); | 152 | local_irq_restore(flags); |
| 160 | } | 153 | } |
| 161 | 154 | ||
| 162 | static inline void flush_dcache_all(void) | 155 | static void flush_dcache_all(void) |
| 163 | { | 156 | { |
| 164 | (*__flush_dcache_segment_fn)(0UL, boot_cpu_data.dcache.way_size); | 157 | unsigned long addr, end_addr, entry_offset; |
| 165 | wmb(); | 158 | |
| 159 | end_addr = CACHE_OC_ADDRESS_ARRAY + | ||
| 160 | (current_cpu_data.dcache.sets << | ||
| 161 | current_cpu_data.dcache.entry_shift) * | ||
| 162 | current_cpu_data.dcache.ways; | ||
| 163 | |||
| 164 | entry_offset = 1 << current_cpu_data.dcache.entry_shift; | ||
| 165 | |||
| 166 | for (addr = CACHE_OC_ADDRESS_ARRAY; addr < end_addr; ) { | ||
| 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 | __raw_writel(0, addr); addr += entry_offset; | ||
| 174 | __raw_writel(0, addr); addr += entry_offset; | ||
| 175 | } | ||
| 166 | } | 176 | } |
| 167 | 177 | ||
| 168 | static void sh4_flush_cache_all(void *unused) | 178 | static void sh4_flush_cache_all(void *unused) |
| @@ -171,89 +181,13 @@ static void sh4_flush_cache_all(void *unused) | |||
| 171 | flush_icache_all(); | 181 | flush_icache_all(); |
| 172 | } | 182 | } |
| 173 | 183 | ||
| 174 | static void __flush_cache_mm(struct mm_struct *mm, unsigned long start, | ||
| 175 | unsigned long end) | ||
| 176 | { | ||
| 177 | unsigned long d = 0, p = start & PAGE_MASK; | ||
| 178 | unsigned long alias_mask = boot_cpu_data.dcache.alias_mask; | ||
| 179 | unsigned long n_aliases = boot_cpu_data.dcache.n_aliases; | ||
| 180 | unsigned long select_bit; | ||
| 181 | unsigned long all_aliases_mask; | ||
| 182 | unsigned long addr_offset; | ||
| 183 | pgd_t *dir; | ||
| 184 | pmd_t *pmd; | ||
| 185 | pud_t *pud; | ||
| 186 | pte_t *pte; | ||
| 187 | int i; | ||
| 188 | |||
| 189 | dir = pgd_offset(mm, p); | ||
| 190 | pud = pud_offset(dir, p); | ||
| 191 | pmd = pmd_offset(pud, p); | ||
| 192 | end = PAGE_ALIGN(end); | ||
| 193 | |||
| 194 | all_aliases_mask = (1 << n_aliases) - 1; | ||
| 195 | |||
| 196 | do { | ||
| 197 | if (pmd_none(*pmd) || unlikely(pmd_bad(*pmd))) { | ||
| 198 | p &= PMD_MASK; | ||
| 199 | p += PMD_SIZE; | ||
| 200 | pmd++; | ||
| 201 | |||
| 202 | continue; | ||
| 203 | } | ||
| 204 | |||
| 205 | pte = pte_offset_kernel(pmd, p); | ||
| 206 | |||
| 207 | do { | ||
| 208 | unsigned long phys; | ||
| 209 | pte_t entry = *pte; | ||
| 210 | |||
| 211 | if (!(pte_val(entry) & _PAGE_PRESENT)) { | ||
| 212 | pte++; | ||
| 213 | p += PAGE_SIZE; | ||
| 214 | continue; | ||
| 215 | } | ||
| 216 | |||
| 217 | phys = pte_val(entry) & PTE_PHYS_MASK; | ||
| 218 | |||
| 219 | if ((p ^ phys) & alias_mask) { | ||
| 220 | d |= 1 << ((p & alias_mask) >> PAGE_SHIFT); | ||
| 221 | d |= 1 << ((phys & alias_mask) >> PAGE_SHIFT); | ||
| 222 | |||
| 223 | if (d == all_aliases_mask) | ||
| 224 | goto loop_exit; | ||
| 225 | } | ||
| 226 | |||
| 227 | pte++; | ||
| 228 | p += PAGE_SIZE; | ||
| 229 | } while (p < end && ((unsigned long)pte & ~PAGE_MASK)); | ||
| 230 | pmd++; | ||
| 231 | } while (p < end); | ||
| 232 | |||
| 233 | loop_exit: | ||
| 234 | addr_offset = 0; | ||
| 235 | select_bit = 1; | ||
| 236 | |||
| 237 | for (i = 0; i < n_aliases; i++) { | ||
| 238 | if (d & select_bit) { | ||
| 239 | (*__flush_dcache_segment_fn)(addr_offset, PAGE_SIZE); | ||
| 240 | wmb(); | ||
| 241 | } | ||
| 242 | |||
| 243 | select_bit <<= 1; | ||
| 244 | addr_offset += PAGE_SIZE; | ||
| 245 | } | ||
| 246 | } | ||
| 247 | |||
| 248 | /* | 184 | /* |
| 249 | * Note : (RPC) since the caches are physically tagged, the only point | 185 | * Note : (RPC) since the caches are physically tagged, the only point |
| 250 | * of flush_cache_mm for SH-4 is to get rid of aliases from the | 186 | * of flush_cache_mm for SH-4 is to get rid of aliases from the |
| 251 | * D-cache. The assumption elsewhere, e.g. flush_cache_range, is that | 187 | * D-cache. The assumption elsewhere, e.g. flush_cache_range, is that |
| 252 | * lines can stay resident so long as the virtual address they were | 188 | * lines can stay resident so long as the virtual address they were |
| 253 | * accessed with (hence cache set) is in accord with the physical | 189 | * accessed with (hence cache set) is in accord with the physical |
| 254 | * address (i.e. tag). It's no different here. So I reckon we don't | 190 | * address (i.e. tag). It's no different here. |
| 255 | * need to flush the I-cache, since aliases don't matter for that. We | ||
| 256 | * should try that. | ||
| 257 | * | 191 | * |
| 258 | * Caller takes mm->mmap_sem. | 192 | * Caller takes mm->mmap_sem. |
| 259 | */ | 193 | */ |
| @@ -264,33 +198,7 @@ static void sh4_flush_cache_mm(void *arg) | |||
| 264 | if (cpu_context(smp_processor_id(), mm) == NO_CONTEXT) | 198 | if (cpu_context(smp_processor_id(), mm) == NO_CONTEXT) |
| 265 | return; | 199 | return; |
| 266 | 200 | ||
| 267 | /* | 201 | flush_dcache_all(); |
| 268 | * If cache is only 4k-per-way, there are never any 'aliases'. Since | ||
| 269 | * the cache is physically tagged, the data can just be left in there. | ||
| 270 | */ | ||
| 271 | if (boot_cpu_data.dcache.n_aliases == 0) | ||
| 272 | return; | ||
| 273 | |||
| 274 | /* | ||
| 275 | * Don't bother groveling around the dcache for the VMA ranges | ||
| 276 | * if there are too many PTEs to make it worthwhile. | ||
| 277 | */ | ||
| 278 | if (mm->nr_ptes >= MAX_DCACHE_PAGES) | ||
| 279 | flush_dcache_all(); | ||
| 280 | else { | ||
| 281 | struct vm_area_struct *vma; | ||
| 282 | |||
| 283 | /* | ||
| 284 | * In this case there are reasonably sized ranges to flush, | ||
| 285 | * iterate through the VMA list and take care of any aliases. | ||
| 286 | */ | ||
| 287 | for (vma = mm->mmap; vma; vma = vma->vm_next) | ||
| 288 | __flush_cache_mm(mm, vma->vm_start, vma->vm_end); | ||
| 289 | } | ||
| 290 | |||
| 291 | /* Only touch the icache if one of the VMAs has VM_EXEC set. */ | ||
| 292 | if (mm->exec_vm) | ||
| 293 | flush_icache_all(); | ||
| 294 | } | 202 | } |
| 295 | 203 | ||
| 296 | /* | 204 | /* |
| @@ -303,44 +211,63 @@ static void sh4_flush_cache_page(void *args) | |||
| 303 | { | 211 | { |
| 304 | struct flusher_data *data = args; | 212 | struct flusher_data *data = args; |
| 305 | struct vm_area_struct *vma; | 213 | struct vm_area_struct *vma; |
| 214 | struct page *page; | ||
| 306 | unsigned long address, pfn, phys; | 215 | unsigned long address, pfn, phys; |
| 307 | unsigned int alias_mask; | 216 | int map_coherent = 0; |
| 217 | pgd_t *pgd; | ||
| 218 | pud_t *pud; | ||
| 219 | pmd_t *pmd; | ||
| 220 | pte_t *pte; | ||
| 221 | void *vaddr; | ||
| 308 | 222 | ||
| 309 | vma = data->vma; | 223 | vma = data->vma; |
| 310 | address = data->addr1; | 224 | address = data->addr1 & PAGE_MASK; |
| 311 | pfn = data->addr2; | 225 | pfn = data->addr2; |
| 312 | phys = pfn << PAGE_SHIFT; | 226 | phys = pfn << PAGE_SHIFT; |
| 227 | page = pfn_to_page(pfn); | ||
| 313 | 228 | ||
| 314 | if (cpu_context(smp_processor_id(), vma->vm_mm) == NO_CONTEXT) | 229 | if (cpu_context(smp_processor_id(), vma->vm_mm) == NO_CONTEXT) |
| 315 | return; | 230 | return; |
| 316 | 231 | ||
| 317 | alias_mask = boot_cpu_data.dcache.alias_mask; | 232 | pgd = pgd_offset(vma->vm_mm, address); |
| 318 | 233 | pud = pud_offset(pgd, address); | |
| 319 | /* We only need to flush D-cache when we have alias */ | 234 | pmd = pmd_offset(pud, address); |
| 320 | if ((address^phys) & alias_mask) { | 235 | pte = pte_offset_kernel(pmd, address); |
| 321 | /* Loop 4K of the D-cache */ | 236 | |
| 322 | flush_cache_one( | 237 | /* If the page isn't present, there is nothing to do here. */ |
| 323 | CACHE_OC_ADDRESS_ARRAY | (address & alias_mask), | 238 | if (!(pte_val(*pte) & _PAGE_PRESENT)) |
| 324 | phys); | 239 | return; |
| 325 | /* Loop another 4K of the D-cache */ | ||
| 326 | flush_cache_one( | ||
| 327 | CACHE_OC_ADDRESS_ARRAY | (phys & alias_mask), | ||
| 328 | phys); | ||
| 329 | } | ||
| 330 | 240 | ||
| 331 | alias_mask = boot_cpu_data.icache.alias_mask; | 241 | if ((vma->vm_mm == current->active_mm)) |
| 332 | if (vma->vm_flags & VM_EXEC) { | 242 | vaddr = NULL; |
| 243 | else { | ||
| 333 | /* | 244 | /* |
| 334 | * Evict entries from the portion of the cache from which code | 245 | * Use kmap_coherent or kmap_atomic to do flushes for |
| 335 | * may have been executed at this address (virtual). There's | 246 | * another ASID than the current one. |
| 336 | * no need to evict from the portion corresponding to the | ||
| 337 | * physical address as for the D-cache, because we know the | ||
| 338 | * kernel has never executed the code through its identity | ||
| 339 | * translation. | ||
| 340 | */ | 247 | */ |
| 341 | flush_cache_one( | 248 | map_coherent = (current_cpu_data.dcache.n_aliases && |
| 342 | CACHE_IC_ADDRESS_ARRAY | (address & alias_mask), | 249 | !test_bit(PG_dcache_dirty, &page->flags) && |
| 343 | phys); | 250 | page_mapped(page)); |
| 251 | if (map_coherent) | ||
| 252 | vaddr = kmap_coherent(page, address); | ||
| 253 | else | ||
| 254 | vaddr = kmap_atomic(page, KM_USER0); | ||
| 255 | |||
| 256 | address = (unsigned long)vaddr; | ||
| 257 | } | ||
| 258 | |||
| 259 | if (pages_do_alias(address, phys)) | ||
| 260 | flush_cache_one(CACHE_OC_ADDRESS_ARRAY | | ||
| 261 | (address & shm_align_mask), phys); | ||
| 262 | |||
| 263 | if (vma->vm_flags & VM_EXEC) | ||
| 264 | flush_icache_all(); | ||
| 265 | |||
| 266 | if (vaddr) { | ||
| 267 | if (map_coherent) | ||
| 268 | kunmap_coherent(vaddr); | ||
| 269 | else | ||
| 270 | kunmap_atomic(vaddr, KM_USER0); | ||
| 344 | } | 271 | } |
| 345 | } | 272 | } |
| 346 | 273 | ||
| @@ -373,24 +300,10 @@ static void sh4_flush_cache_range(void *args) | |||
| 373 | if (boot_cpu_data.dcache.n_aliases == 0) | 300 | if (boot_cpu_data.dcache.n_aliases == 0) |
| 374 | return; | 301 | return; |
| 375 | 302 | ||
| 376 | /* | 303 | flush_dcache_all(); |
| 377 | * Don't bother with the lookup and alias check if we have a | ||
| 378 | * wide range to cover, just blow away the dcache in its | ||
| 379 | * entirety instead. -- PFM. | ||
| 380 | */ | ||
| 381 | if (((end - start) >> PAGE_SHIFT) >= MAX_DCACHE_PAGES) | ||
| 382 | flush_dcache_all(); | ||
| 383 | else | ||
| 384 | __flush_cache_mm(vma->vm_mm, start, end); | ||
| 385 | 304 | ||
| 386 | if (vma->vm_flags & VM_EXEC) { | 305 | if (vma->vm_flags & VM_EXEC) |
| 387 | /* | ||
| 388 | * TODO: Is this required??? Need to look at how I-cache | ||
| 389 | * coherency is assured when new programs are loaded to see if | ||
| 390 | * this matters. | ||
| 391 | */ | ||
| 392 | flush_icache_all(); | 306 | flush_icache_all(); |
| 393 | } | ||
| 394 | } | 307 | } |
| 395 | 308 | ||
| 396 | /** | 309 | /** |
| @@ -464,245 +377,6 @@ static void __flush_cache_one(unsigned long addr, unsigned long phys, | |||
| 464 | } while (--way_count != 0); | 377 | } while (--way_count != 0); |
| 465 | } | 378 | } |
| 466 | 379 | ||
| 467 | /* | ||
| 468 | * Break the 1, 2 and 4 way variants of this out into separate functions to | ||
| 469 | * avoid nearly all the overhead of having the conditional stuff in the function | ||
| 470 | * bodies (+ the 1 and 2 way cases avoid saving any registers too). | ||
| 471 | * | ||
| 472 | * We want to eliminate unnecessary bus transactions, so this code uses | ||
| 473 | * a non-obvious technique. | ||
| 474 | * | ||
| 475 | * Loop over a cache way sized block of, one cache line at a time. For each | ||
| 476 | * line, use movca.a to cause the current cache line contents to be written | ||
| 477 | * back, but without reading anything from main memory. However this has the | ||
| 478 | * side effect that the cache is now caching that memory location. So follow | ||
| 479 | * this with a cache invalidate to mark the cache line invalid. And do all | ||
| 480 | * this with interrupts disabled, to avoid the cache line being accidently | ||
| 481 | * evicted while it is holding garbage. | ||
| 482 | * | ||
| 483 | * This also breaks in a number of circumstances: | ||
| 484 | * - if there are modifications to the region of memory just above | ||
| 485 | * empty_zero_page (for example because a breakpoint has been placed | ||
| 486 | * there), then these can be lost. | ||
| 487 | * | ||
| 488 | * This is because the the memory address which the cache temporarily | ||
| 489 | * caches in the above description is empty_zero_page. So the | ||
| 490 | * movca.l hits the cache (it is assumed that it misses, or at least | ||
| 491 | * isn't dirty), modifies the line and then invalidates it, losing the | ||
| 492 | * required change. | ||
| 493 | * | ||
| 494 | * - If caches are disabled or configured in write-through mode, then | ||
| 495 | * the movca.l writes garbage directly into memory. | ||
| 496 | */ | ||
| 497 | static void __flush_dcache_segment_writethrough(unsigned long start, | ||
| 498 | unsigned long extent_per_way) | ||
| 499 | { | ||
| 500 | unsigned long addr; | ||
| 501 | int i; | ||
| 502 | |||
| 503 | addr = CACHE_OC_ADDRESS_ARRAY | (start & cpu_data->dcache.entry_mask); | ||
| 504 | |||
| 505 | while (extent_per_way) { | ||
| 506 | for (i = 0; i < cpu_data->dcache.ways; i++) | ||
| 507 | __raw_writel(0, addr + cpu_data->dcache.way_incr * i); | ||
| 508 | |||
| 509 | addr += cpu_data->dcache.linesz; | ||
| 510 | extent_per_way -= cpu_data->dcache.linesz; | ||
| 511 | } | ||
| 512 | } | ||
| 513 | |||
| 514 | static void __flush_dcache_segment_1way(unsigned long start, | ||
| 515 | unsigned long extent_per_way) | ||
| 516 | { | ||
| 517 | unsigned long orig_sr, sr_with_bl; | ||
| 518 | unsigned long base_addr; | ||
| 519 | unsigned long way_incr, linesz, way_size; | ||
| 520 | struct cache_info *dcache; | ||
| 521 | register unsigned long a0, a0e; | ||
| 522 | |||
| 523 | asm volatile("stc sr, %0" : "=r" (orig_sr)); | ||
| 524 | sr_with_bl = orig_sr | (1<<28); | ||
| 525 | base_addr = ((unsigned long)&empty_zero_page[0]); | ||
| 526 | |||
| 527 | /* | ||
| 528 | * The previous code aligned base_addr to 16k, i.e. the way_size of all | ||
| 529 | * existing SH-4 D-caches. Whilst I don't see a need to have this | ||
| 530 | * aligned to any better than the cache line size (which it will be | ||
| 531 | * anyway by construction), let's align it to at least the way_size of | ||
| 532 | * any existing or conceivable SH-4 D-cache. -- RPC | ||
| 533 | */ | ||
| 534 | base_addr = ((base_addr >> 16) << 16); | ||
| 535 | base_addr |= start; | ||
| 536 | |||
| 537 | dcache = &boot_cpu_data.dcache; | ||
| 538 | linesz = dcache->linesz; | ||
| 539 | way_incr = dcache->way_incr; | ||
| 540 | way_size = dcache->way_size; | ||
| 541 | |||
| 542 | a0 = base_addr; | ||
| 543 | a0e = base_addr + extent_per_way; | ||
| 544 | do { | ||
| 545 | asm volatile("ldc %0, sr" : : "r" (sr_with_bl)); | ||
| 546 | asm volatile("movca.l r0, @%0\n\t" | ||
| 547 | "ocbi @%0" : : "r" (a0)); | ||
| 548 | a0 += linesz; | ||
| 549 | asm volatile("movca.l r0, @%0\n\t" | ||
| 550 | "ocbi @%0" : : "r" (a0)); | ||
| 551 | a0 += linesz; | ||
| 552 | asm volatile("movca.l r0, @%0\n\t" | ||
| 553 | "ocbi @%0" : : "r" (a0)); | ||
| 554 | a0 += linesz; | ||
| 555 | asm volatile("movca.l r0, @%0\n\t" | ||
| 556 | "ocbi @%0" : : "r" (a0)); | ||
| 557 | asm volatile("ldc %0, sr" : : "r" (orig_sr)); | ||
| 558 | a0 += linesz; | ||
| 559 | } while (a0 < a0e); | ||
| 560 | } | ||
| 561 | |||
| 562 | static void __flush_dcache_segment_2way(unsigned long start, | ||
| 563 | unsigned long extent_per_way) | ||
| 564 | { | ||
| 565 | unsigned long orig_sr, sr_with_bl; | ||
| 566 | unsigned long base_addr; | ||
| 567 | unsigned long way_incr, linesz, way_size; | ||
| 568 | struct cache_info *dcache; | ||
| 569 | register unsigned long a0, a1, a0e; | ||
| 570 | |||
| 571 | asm volatile("stc sr, %0" : "=r" (orig_sr)); | ||
| 572 | sr_with_bl = orig_sr | (1<<28); | ||
| 573 | base_addr = ((unsigned long)&empty_zero_page[0]); | ||
| 574 | |||
| 575 | /* See comment under 1-way above */ | ||
| 576 | base_addr = ((base_addr >> 16) << 16); | ||
| 577 | base_addr |= start; | ||
| 578 | |||
| 579 | dcache = &boot_cpu_data.dcache; | ||
| 580 | linesz = dcache->linesz; | ||
| 581 | way_incr = dcache->way_incr; | ||
| 582 | way_size = dcache->way_size; | ||
| 583 | |||
| 584 | a0 = base_addr; | ||
| 585 | a1 = a0 + way_incr; | ||
| 586 | a0e = base_addr + extent_per_way; | ||
| 587 | do { | ||
| 588 | asm volatile("ldc %0, sr" : : "r" (sr_with_bl)); | ||
| 589 | asm volatile("movca.l r0, @%0\n\t" | ||
| 590 | "movca.l r0, @%1\n\t" | ||
| 591 | "ocbi @%0\n\t" | ||
| 592 | "ocbi @%1" : : | ||
| 593 | "r" (a0), "r" (a1)); | ||
| 594 | a0 += linesz; | ||
| 595 | a1 += linesz; | ||
| 596 | asm volatile("movca.l r0, @%0\n\t" | ||
| 597 | "movca.l r0, @%1\n\t" | ||
| 598 | "ocbi @%0\n\t" | ||
| 599 | "ocbi @%1" : : | ||
| 600 | "r" (a0), "r" (a1)); | ||
| 601 | a0 += linesz; | ||
| 602 | a1 += linesz; | ||
| 603 | asm volatile("movca.l r0, @%0\n\t" | ||
| 604 | "movca.l r0, @%1\n\t" | ||
| 605 | "ocbi @%0\n\t" | ||
| 606 | "ocbi @%1" : : | ||
| 607 | "r" (a0), "r" (a1)); | ||
| 608 | a0 += linesz; | ||
| 609 | a1 += linesz; | ||
| 610 | asm volatile("movca.l r0, @%0\n\t" | ||
| 611 | "movca.l r0, @%1\n\t" | ||
| 612 | "ocbi @%0\n\t" | ||
| 613 | "ocbi @%1" : : | ||
| 614 | "r" (a0), "r" (a1)); | ||
| 615 | asm volatile("ldc %0, sr" : : "r" (orig_sr)); | ||
| 616 | a0 += linesz; | ||
| 617 | a1 += linesz; | ||
| 618 | } while (a0 < a0e); | ||
| 619 | } | ||
| 620 | |||
| 621 | static void __flush_dcache_segment_4way(unsigned long start, | ||
| 622 | unsigned long extent_per_way) | ||
| 623 | { | ||
| 624 | unsigned long orig_sr, sr_with_bl; | ||
| 625 | unsigned long base_addr; | ||
| 626 | unsigned long way_incr, linesz, way_size; | ||
| 627 | struct cache_info *dcache; | ||
| 628 | register unsigned long a0, a1, a2, a3, a0e; | ||
| 629 | |||
| 630 | asm volatile("stc sr, %0" : "=r" (orig_sr)); | ||
| 631 | sr_with_bl = orig_sr | (1<<28); | ||
| 632 | base_addr = ((unsigned long)&empty_zero_page[0]); | ||
| 633 | |||
| 634 | /* See comment under 1-way above */ | ||
| 635 | base_addr = ((base_addr >> 16) << 16); | ||
| 636 | base_addr |= start; | ||
| 637 | |||
| 638 | dcache = &boot_cpu_data.dcache; | ||
| 639 | linesz = dcache->linesz; | ||
| 640 | way_incr = dcache->way_incr; | ||
| 641 | way_size = dcache->way_size; | ||
| 642 | |||
| 643 | a0 = base_addr; | ||
| 644 | a1 = a0 + way_incr; | ||
| 645 | a2 = a1 + way_incr; | ||
| 646 | a3 = a2 + way_incr; | ||
| 647 | a0e = base_addr + extent_per_way; | ||
| 648 | do { | ||
| 649 | asm volatile("ldc %0, sr" : : "r" (sr_with_bl)); | ||
| 650 | asm volatile("movca.l r0, @%0\n\t" | ||
| 651 | "movca.l r0, @%1\n\t" | ||
| 652 | "movca.l r0, @%2\n\t" | ||
| 653 | "movca.l r0, @%3\n\t" | ||
| 654 | "ocbi @%0\n\t" | ||
| 655 | "ocbi @%1\n\t" | ||
| 656 | "ocbi @%2\n\t" | ||
| 657 | "ocbi @%3\n\t" : : | ||
| 658 | "r" (a0), "r" (a1), "r" (a2), "r" (a3)); | ||
| 659 | a0 += linesz; | ||
| 660 | a1 += linesz; | ||
| 661 | a2 += linesz; | ||
| 662 | a3 += linesz; | ||
| 663 | asm volatile("movca.l r0, @%0\n\t" | ||
| 664 | "movca.l r0, @%1\n\t" | ||
| 665 | "movca.l r0, @%2\n\t" | ||
| 666 | "movca.l r0, @%3\n\t" | ||
| 667 | "ocbi @%0\n\t" | ||
| 668 | "ocbi @%1\n\t" | ||
| 669 | "ocbi @%2\n\t" | ||
| 670 | "ocbi @%3\n\t" : : | ||
| 671 | "r" (a0), "r" (a1), "r" (a2), "r" (a3)); | ||
| 672 | a0 += linesz; | ||
| 673 | a1 += linesz; | ||
| 674 | a2 += linesz; | ||
| 675 | a3 += linesz; | ||
| 676 | asm volatile("movca.l r0, @%0\n\t" | ||
| 677 | "movca.l r0, @%1\n\t" | ||
| 678 | "movca.l r0, @%2\n\t" | ||
| 679 | "movca.l r0, @%3\n\t" | ||
| 680 | "ocbi @%0\n\t" | ||
| 681 | "ocbi @%1\n\t" | ||
| 682 | "ocbi @%2\n\t" | ||
| 683 | "ocbi @%3\n\t" : : | ||
| 684 | "r" (a0), "r" (a1), "r" (a2), "r" (a3)); | ||
| 685 | a0 += linesz; | ||
| 686 | a1 += linesz; | ||
| 687 | a2 += linesz; | ||
| 688 | a3 += linesz; | ||
| 689 | asm volatile("movca.l r0, @%0\n\t" | ||
| 690 | "movca.l r0, @%1\n\t" | ||
| 691 | "movca.l r0, @%2\n\t" | ||
| 692 | "movca.l r0, @%3\n\t" | ||
| 693 | "ocbi @%0\n\t" | ||
| 694 | "ocbi @%1\n\t" | ||
| 695 | "ocbi @%2\n\t" | ||
| 696 | "ocbi @%3\n\t" : : | ||
| 697 | "r" (a0), "r" (a1), "r" (a2), "r" (a3)); | ||
| 698 | asm volatile("ldc %0, sr" : : "r" (orig_sr)); | ||
| 699 | a0 += linesz; | ||
| 700 | a1 += linesz; | ||
| 701 | a2 += linesz; | ||
| 702 | a3 += linesz; | ||
| 703 | } while (a0 < a0e); | ||
| 704 | } | ||
| 705 | |||
| 706 | extern void __weak sh4__flush_region_init(void); | 380 | extern void __weak sh4__flush_region_init(void); |
| 707 | 381 | ||
| 708 | /* | 382 | /* |
| @@ -710,32 +384,11 @@ extern void __weak sh4__flush_region_init(void); | |||
| 710 | */ | 384 | */ |
| 711 | void __init sh4_cache_init(void) | 385 | void __init sh4_cache_init(void) |
| 712 | { | 386 | { |
| 713 | unsigned int wt_enabled = !!(__raw_readl(CCR) & CCR_CACHE_WT); | ||
| 714 | |||
| 715 | printk("PVR=%08x CVR=%08x PRR=%08x\n", | 387 | printk("PVR=%08x CVR=%08x PRR=%08x\n", |
| 716 | ctrl_inl(CCN_PVR), | 388 | ctrl_inl(CCN_PVR), |
| 717 | ctrl_inl(CCN_CVR), | 389 | ctrl_inl(CCN_CVR), |
| 718 | ctrl_inl(CCN_PRR)); | 390 | ctrl_inl(CCN_PRR)); |
| 719 | 391 | ||
| 720 | if (wt_enabled) | ||
| 721 | __flush_dcache_segment_fn = __flush_dcache_segment_writethrough; | ||
| 722 | else { | ||
| 723 | switch (boot_cpu_data.dcache.ways) { | ||
| 724 | case 1: | ||
| 725 | __flush_dcache_segment_fn = __flush_dcache_segment_1way; | ||
| 726 | break; | ||
| 727 | case 2: | ||
| 728 | __flush_dcache_segment_fn = __flush_dcache_segment_2way; | ||
| 729 | break; | ||
| 730 | case 4: | ||
| 731 | __flush_dcache_segment_fn = __flush_dcache_segment_4way; | ||
| 732 | break; | ||
| 733 | default: | ||
| 734 | panic("unknown number of cache ways\n"); | ||
| 735 | break; | ||
| 736 | } | ||
| 737 | } | ||
| 738 | |||
| 739 | local_flush_icache_range = sh4_flush_icache_range; | 392 | local_flush_icache_range = sh4_flush_icache_range; |
| 740 | local_flush_dcache_page = sh4_flush_dcache_page; | 393 | local_flush_dcache_page = sh4_flush_dcache_page; |
| 741 | local_flush_cache_all = sh4_flush_cache_all; | 394 | local_flush_cache_all = sh4_flush_cache_all; |
