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