Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1 | /* |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 2 | * Blackfin cache control code |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 3 | * |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 4 | * Copyright 2004-2008 Analog Devices Inc. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 5 | * |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 6 | * Enter bugs at http://blackfin.uclinux.org/ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 7 | * |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 8 | * Licensed under the GPL-2 or later. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/linkage.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 12 | #include <asm/blackfin.h> |
| 13 | #include <asm/cache.h> |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 14 | #include <asm/page.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 15 | |
| 16 | .text |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 17 | |
Mike Frysinger | 78f28a0 | 2009-04-10 21:20:19 +0000 | [diff] [blame] | 18 | /* 05000443 - IFLUSH cannot be last instruction in hardware loop */ |
| 19 | #if ANOMALY_05000443 |
| 20 | # define BROK_FLUSH_INST "IFLUSH" |
| 21 | #else |
| 22 | # define BROK_FLUSH_INST "no anomaly! yeah!" |
| 23 | #endif |
| 24 | |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 25 | /* Since all L1 caches work the same way, we use the same method for flushing |
| 26 | * them. Only the actual flush instruction differs. We write this in asm as |
| 27 | * GCC can be hard to coax into writing nice hardware loops. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 28 | * |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 29 | * Also, we assume the following register setup: |
| 30 | * R0 = start address |
| 31 | * R1 = end address |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 32 | */ |
Mike Frysinger | 78f28a0 | 2009-04-10 21:20:19 +0000 | [diff] [blame] | 33 | .macro do_flush flushins:req label |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 34 | |
Mike Frysinger | 39e96c8 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 35 | R2 = -L1_CACHE_BYTES; |
| 36 | |
| 37 | /* start = (start & -L1_CACHE_BYTES) */ |
| 38 | R0 = R0 & R2; |
| 39 | |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 40 | /* end = ((end - 1) & -L1_CACHE_BYTES) + L1_CACHE_BYTES; */ |
| 41 | R1 += -1; |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 42 | R1 = R1 & R2; |
| 43 | R1 += L1_CACHE_BYTES; |
| 44 | |
| 45 | /* count = (end - start) >> L1_CACHE_SHIFT */ |
| 46 | R2 = R1 - R0; |
| 47 | R2 >>= L1_CACHE_SHIFT; |
| 48 | P1 = R2; |
| 49 | |
| 50 | .ifnb \label |
| 51 | \label : |
| 52 | .endif |
| 53 | P0 = R0; |
Mike Frysinger | 78f28a0 | 2009-04-10 21:20:19 +0000 | [diff] [blame] | 54 | |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 55 | LSETUP (1f, 2f) LC1 = P1; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 56 | 1: |
Mike Frysinger | 78f28a0 | 2009-04-10 21:20:19 +0000 | [diff] [blame] | 57 | .ifeqs "\flushins", BROK_FLUSH_INST |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 58 | \flushins [P0++]; |
Mike Frysinger | 78f28a0 | 2009-04-10 21:20:19 +0000 | [diff] [blame] | 59 | 2: nop; |
| 60 | .else |
Mike Frysinger | 2cf8511 | 2008-10-28 16:34:42 +0800 | [diff] [blame] | 61 | 2: \flushins [P0++]; |
Mike Frysinger | 78f28a0 | 2009-04-10 21:20:19 +0000 | [diff] [blame] | 62 | .endif |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 63 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 64 | RTS; |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 65 | .endm |
| 66 | |
| 67 | /* Invalidate all instruction cache lines assocoiated with this memory area */ |
| 68 | ENTRY(_blackfin_icache_flush_range) |
Sonic Zhang | d7ff1a9 | 2009-03-05 18:26:59 +0800 | [diff] [blame] | 69 | /* |
| 70 | * Walkaround to avoid loading wrong instruction after invalidating icache |
| 71 | * and following sequence is met. |
| 72 | * |
| 73 | * 1) One instruction address is cached in the instruction cache. |
| 74 | * 2) This instruction in SDRAM is changed. |
| 75 | * 3) IFLASH[P0] is executed only once in blackfin_icache_flush_range(). |
| 76 | * 4) This instruction is executed again, but the old one is loaded. |
| 77 | */ |
| 78 | P0 = R0; |
| 79 | IFLUSH[P0]; |
Mike Frysinger | 78f28a0 | 2009-04-10 21:20:19 +0000 | [diff] [blame] | 80 | do_flush IFLUSH |
Mike Frysinger | 51be24c | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 81 | ENDPROC(_blackfin_icache_flush_range) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 82 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 83 | /* Throw away all D-cached data in specified region without any obligation to |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 84 | * write them back. Since the Blackfin ISA does not have an "invalidate" |
| 85 | * instruction, we use flush/invalidate. Perhaps as a speed optimization we |
| 86 | * could bang on the DTEST MMRs ... |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 87 | */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 88 | ENTRY(_blackfin_dcache_invalidate_range) |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 89 | do_flush FLUSHINV |
Mike Frysinger | 51be24c | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 90 | ENDPROC(_blackfin_dcache_invalidate_range) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 91 | |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 92 | /* Flush all data cache lines assocoiated with this memory area */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 93 | ENTRY(_blackfin_dcache_flush_range) |
Mike Frysinger | 78f28a0 | 2009-04-10 21:20:19 +0000 | [diff] [blame] | 94 | do_flush FLUSH, .Ldfr |
Mike Frysinger | 51be24c | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 95 | ENDPROC(_blackfin_dcache_flush_range) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 96 | |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 97 | /* Our headers convert the page structure to an address, so just need to flush |
| 98 | * its contents like normal. We know the start address is page aligned (which |
| 99 | * greater than our cache alignment), as is the end address. So just jump into |
| 100 | * the middle of the dcache flush function. |
| 101 | */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 102 | ENTRY(_blackfin_dflush_page) |
| 103 | P1 = 1 << (PAGE_SHIFT - L1_CACHE_SHIFT); |
Mike Frysinger | ded963a | 2008-10-16 23:01:24 +0800 | [diff] [blame] | 104 | jump .Ldfr; |
Mike Frysinger | 51be24c | 2007-06-11 15:31:30 +0800 | [diff] [blame] | 105 | ENDPROC(_blackfin_dflush_page) |