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