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