Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1 | /* |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 2 | * Blackfin low-level cache routines |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 3 | * |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 4 | * Copyright 2004-2009 Analog Devices Inc. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 5 | * |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [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 | #ifndef _BLACKFIN_CACHEFLUSH_H |
| 10 | #define _BLACKFIN_CACHEFLUSH_H |
| 11 | |
Mike Frysinger | 5d89137 | 2009-04-10 20:52:08 +0000 | [diff] [blame] | 12 | #include <asm/blackfin.h> /* for SSYNC() */ |
| 13 | |
Mike Frysinger | 8fb4f8f | 2008-10-16 23:39:12 +0800 | [diff] [blame] | 14 | extern void blackfin_icache_flush_range(unsigned long start_address, unsigned long end_address); |
| 15 | extern void blackfin_dcache_flush_range(unsigned long start_address, unsigned long end_address); |
| 16 | extern void blackfin_dcache_invalidate_range(unsigned long start_address, unsigned long end_address); |
| 17 | extern void blackfin_dflush_page(void *page); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 18 | extern void blackfin_invalidate_entire_dcache(void); |
Sonic Zhang | 47e9ded | 2009-06-10 08:57:08 +0000 | [diff] [blame] | 19 | extern void blackfin_invalidate_entire_icache(void); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 20 | |
| 21 | #define flush_dcache_mmap_lock(mapping) do { } while (0) |
| 22 | #define flush_dcache_mmap_unlock(mapping) do { } while (0) |
| 23 | #define flush_cache_mm(mm) do { } while (0) |
| 24 | #define flush_cache_range(vma, start, end) do { } while (0) |
| 25 | #define flush_cache_page(vma, vmaddr) do { } while (0) |
| 26 | #define flush_cache_vmap(start, end) do { } while (0) |
| 27 | #define flush_cache_vunmap(start, end) do { } while (0) |
| 28 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 29 | #ifdef CONFIG_SMP |
| 30 | #define flush_icache_range_others(start, end) \ |
| 31 | smp_icache_flush_range_others((start), (end)) |
| 32 | #else |
| 33 | #define flush_icache_range_others(start, end) do { } while (0) |
| 34 | #endif |
| 35 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 36 | static inline void flush_icache_range(unsigned start, unsigned end) |
| 37 | { |
Jie Zhang | 41ba653 | 2009-06-16 09:48:33 +0000 | [diff] [blame] | 38 | #if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined(CONFIG_BFIN_L2_WRITEBACK) |
Mike Frysinger | 5d89137 | 2009-04-10 20:52:08 +0000 | [diff] [blame] | 39 | blackfin_dcache_flush_range(start, end); |
| 40 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 41 | |
Mike Frysinger | 5d89137 | 2009-04-10 20:52:08 +0000 | [diff] [blame] | 42 | /* Make sure all write buffers in the data side of the core |
| 43 | * are flushed before trying to invalidate the icache. This |
| 44 | * needs to be after the data flush and before the icache |
| 45 | * flush so that the SSYNC does the right thing in preventing |
| 46 | * the instruction prefetcher from hitting things in cached |
| 47 | * memory at the wrong time -- it runs much further ahead than |
| 48 | * the pipeline. |
| 49 | */ |
| 50 | SSYNC(); |
| 51 | #if defined(CONFIG_BFIN_ICACHE) |
| 52 | blackfin_icache_flush_range(start, end); |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 53 | flush_icache_range_others(start, end); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 54 | #endif |
| 55 | } |
| 56 | |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 57 | #define copy_to_user_page(vma, page, vaddr, dst, src, len) \ |
| 58 | do { memcpy(dst, src, len); \ |
| 59 | flush_icache_range((unsigned) (dst), (unsigned) (dst) + (len)); \ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 60 | } while (0) |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 61 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 62 | #define copy_from_user_page(vma, page, vaddr, dst, src, len) memcpy(dst, src, len) |
| 63 | |
Robin Getz | 3bebca2 | 2007-10-10 23:55:26 +0800 | [diff] [blame] | 64 | #if defined(CONFIG_BFIN_DCACHE) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 65 | # define invalidate_dcache_range(start,end) blackfin_dcache_invalidate_range((start), (end)) |
| 66 | #else |
| 67 | # define invalidate_dcache_range(start,end) do { } while (0) |
| 68 | #endif |
Jie Zhang | 41ba653 | 2009-06-16 09:48:33 +0000 | [diff] [blame] | 69 | #if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined(CONFIG_BFIN_L2_WRITEBACK) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 70 | # define flush_dcache_range(start,end) blackfin_dcache_flush_range((start), (end)) |
Ilya Loginov | 2d4dc89 | 2009-11-26 09:16:19 +0100 | [diff] [blame] | 71 | #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 |
Jie Zhang | 41ba653 | 2009-06-16 09:48:33 +0000 | [diff] [blame] | 72 | # define flush_dcache_page(page) blackfin_dflush_page(page_address(page)) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 73 | #else |
| 74 | # define flush_dcache_range(start,end) do { } while (0) |
Ilya Loginov | 2d4dc89 | 2009-11-26 09:16:19 +0100 | [diff] [blame] | 75 | #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0 |
Graf Yang | 6b3087c | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 76 | # define flush_dcache_page(page) do { } while (0) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 77 | #endif |
| 78 | |
Mike Frysinger | 04be80e | 2008-10-16 23:33:53 +0800 | [diff] [blame] | 79 | extern unsigned long reserved_mem_dcache_on; |
| 80 | extern unsigned long reserved_mem_icache_on; |
| 81 | |
Jie Zhang | 67834fa | 2009-06-10 06:26:26 +0000 | [diff] [blame] | 82 | static inline int bfin_addr_dcacheable(unsigned long addr) |
Mike Frysinger | 04be80e | 2008-10-16 23:33:53 +0800 | [diff] [blame] | 83 | { |
Jie Zhang | 41ba653 | 2009-06-16 09:48:33 +0000 | [diff] [blame] | 84 | #ifdef CONFIG_BFIN_EXTMEM_DCACHEABLE |
Mike Frysinger | 04be80e | 2008-10-16 23:33:53 +0800 | [diff] [blame] | 85 | if (addr < (_ramend - DMA_UNCACHED_REGION)) |
| 86 | return 1; |
| 87 | #endif |
| 88 | |
| 89 | if (reserved_mem_dcache_on && |
| 90 | addr >= _ramend && addr < physical_mem_end) |
| 91 | return 1; |
| 92 | |
Jie Zhang | 41ba653 | 2009-06-16 09:48:33 +0000 | [diff] [blame] | 93 | #ifdef CONFIG_BFIN_L2_DCACHEABLE |
Mike Frysinger | f339f46 | 2009-05-19 12:58:13 +0000 | [diff] [blame] | 94 | if (addr >= L2_START && addr < L2_START + L2_LENGTH) |
| 95 | return 1; |
| 96 | #endif |
| 97 | |
Mike Frysinger | 04be80e | 2008-10-16 23:33:53 +0800 | [diff] [blame] | 98 | return 0; |
| 99 | } |
| 100 | |
Robin Getz | 3bebca2 | 2007-10-10 23:55:26 +0800 | [diff] [blame] | 101 | #endif /* _BLACKFIN_ICACHEFLUSH_H */ |