cacheflush.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Blackfin low-level cache routines
  3. *
  4. * Copyright 2004-2009 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #ifndef _BLACKFIN_CACHEFLUSH_H
  9. #define _BLACKFIN_CACHEFLUSH_H
  10. #include <asm/blackfin.h> /* for SSYNC() */
  11. #include <asm/sections.h> /* for _ramend */
  12. #ifdef CONFIG_SMP
  13. #include <asm/smp.h>
  14. #endif
  15. extern void blackfin_icache_flush_range(unsigned long start_address, unsigned long end_address);
  16. extern void blackfin_dcache_flush_range(unsigned long start_address, unsigned long end_address);
  17. extern void blackfin_dcache_invalidate_range(unsigned long start_address, unsigned long end_address);
  18. extern void blackfin_dflush_page(void *page);
  19. extern void blackfin_invalidate_entire_dcache(void);
  20. extern void blackfin_invalidate_entire_icache(void);
  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. #ifdef CONFIG_SMP
  29. #define flush_icache_range_others(start, end) \
  30. smp_icache_flush_range_others((start), (end))
  31. #else
  32. #define flush_icache_range_others(start, end) do { } while (0)
  33. #endif
  34. static inline void flush_icache_range(unsigned start, unsigned end)
  35. {
  36. #if defined(CONFIG_BFIN_EXTMEM_WRITEBACK)
  37. if (end <= physical_mem_end)
  38. blackfin_dcache_flush_range(start, end);
  39. #endif
  40. #if defined(CONFIG_BFIN_L2_WRITEBACK)
  41. if (start >= L2_START && end <= L2_START + L2_LENGTH)
  42. blackfin_dcache_flush_range(start, end);
  43. #endif
  44. /* Make sure all write buffers in the data side of the core
  45. * are flushed before trying to invalidate the icache. This
  46. * needs to be after the data flush and before the icache
  47. * flush so that the SSYNC does the right thing in preventing
  48. * the instruction prefetcher from hitting things in cached
  49. * memory at the wrong time -- it runs much further ahead than
  50. * the pipeline.
  51. */
  52. SSYNC();
  53. #if defined(CONFIG_BFIN_EXTMEM_ICACHEABLE)
  54. if (end <= physical_mem_end) {
  55. blackfin_icache_flush_range(start, end);
  56. flush_icache_range_others(start, end);
  57. }
  58. #endif
  59. #if defined(CONFIG_BFIN_L2_ICACHEABLE)
  60. if (start >= L2_START && end <= L2_START + L2_LENGTH) {
  61. blackfin_icache_flush_range(start, end);
  62. flush_icache_range_others(start, end);
  63. }
  64. #endif
  65. }
  66. #define copy_to_user_page(vma, page, vaddr, dst, src, len) \
  67. do { memcpy(dst, src, len); \
  68. flush_icache_range((unsigned) (dst), (unsigned) (dst) + (len)); \
  69. } while (0)
  70. #define copy_from_user_page(vma, page, vaddr, dst, src, len) memcpy(dst, src, len)
  71. #if defined(CONFIG_BFIN_DCACHE)
  72. # define invalidate_dcache_range(start,end) blackfin_dcache_invalidate_range((start), (end))
  73. #else
  74. # define invalidate_dcache_range(start,end) do { } while (0)
  75. #endif
  76. #if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined(CONFIG_BFIN_L2_WRITEBACK)
  77. # define flush_dcache_range(start,end) blackfin_dcache_flush_range((start), (end))
  78. #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
  79. # define flush_dcache_page(page) blackfin_dflush_page(page_address(page))
  80. #else
  81. # define flush_dcache_range(start,end) do { } while (0)
  82. #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
  83. # define flush_dcache_page(page) do { } while (0)
  84. #endif
  85. extern unsigned long reserved_mem_dcache_on;
  86. extern unsigned long reserved_mem_icache_on;
  87. static inline int bfin_addr_dcacheable(unsigned long addr)
  88. {
  89. #ifdef CONFIG_BFIN_EXTMEM_DCACHEABLE
  90. if (addr < (_ramend - DMA_UNCACHED_REGION))
  91. return 1;
  92. #endif
  93. if (reserved_mem_dcache_on &&
  94. addr >= _ramend && addr < physical_mem_end)
  95. return 1;
  96. #ifdef CONFIG_BFIN_L2_DCACHEABLE
  97. if (addr >= L2_START && addr < L2_START + L2_LENGTH)
  98. return 1;
  99. #endif
  100. return 0;
  101. }
  102. #endif /* _BLACKFIN_ICACHEFLUSH_H */