cacheflush.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
  3. * Copyright (C) 2007-2009 PetaLogix
  4. * Copyright (C) 2007 John Williams <john.williams@petalogix.com>
  5. * based on v850 version which was
  6. * Copyright (C) 2001,02,03 NEC Electronics Corporation
  7. * Copyright (C) 2001,02,03 Miles Bader <miles@gnu.org>
  8. *
  9. * This file is subject to the terms and conditions of the GNU General
  10. * Public License. See the file COPYING in the main directory of this
  11. * archive for more details.
  12. *
  13. */
  14. #ifndef _ASM_MICROBLAZE_CACHEFLUSH_H
  15. #define _ASM_MICROBLAZE_CACHEFLUSH_H
  16. /* Somebody depends on this; sigh... */
  17. #include <linux/mm.h>
  18. #include <linux/io.h>
  19. /* Look at Documentation/cachetlb.txt */
  20. /*
  21. * Cache handling functions.
  22. * Microblaze has a write-through data cache, meaning that the data cache
  23. * never needs to be flushed. The only flushing operations that are
  24. * implemented are to invalidate the instruction cache. These are called
  25. * after loading a user application into memory, we must invalidate the
  26. * instruction cache to make sure we don't fetch old, bad code.
  27. */
  28. /* struct cache, d=dcache, i=icache, fl = flush, iv = invalidate,
  29. * suffix r = range */
  30. struct scache {
  31. /* icache */
  32. void (*ie)(void); /* enable */
  33. void (*id)(void); /* disable */
  34. void (*ifl)(void); /* flush */
  35. void (*iflr)(unsigned long a, unsigned long b);
  36. void (*iin)(void); /* invalidate */
  37. void (*iinr)(unsigned long a, unsigned long b);
  38. /* dcache */
  39. void (*de)(void); /* enable */
  40. void (*dd)(void); /* disable */
  41. void (*dfl)(void); /* flush */
  42. void (*dflr)(unsigned long a, unsigned long b);
  43. void (*din)(void); /* invalidate */
  44. void (*dinr)(unsigned long a, unsigned long b);
  45. };
  46. /* microblaze cache */
  47. extern struct scache *mbc;
  48. void microblaze_cache_init(void);
  49. #define enable_icache() mbc->ie();
  50. #define disable_icache() mbc->id();
  51. #define flush_icache() mbc->ifl();
  52. #define flush_icache_range(start, end) mbc->iflr(start, end);
  53. #define invalidate_icache() mbc->iin();
  54. #define invalidate_icache_range(start, end) mbc->iinr(start, end);
  55. #define flush_icache_user_range(vma, pg, adr, len) flush_icache();
  56. #define flush_icache_page(vma, pg) do { } while (0)
  57. #define enable_dcache() mbc->de();
  58. #define disable_dcache() mbc->dd();
  59. /* FIXME for LL-temac driver */
  60. #define invalidate_dcache() mbc->din();
  61. #define invalidate_dcache_range(start, end) mbc->dinr(start, end);
  62. #define flush_dcache() mbc->dfl();
  63. #define flush_dcache_range(start, end) mbc->dflr(start, end);
  64. #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
  65. /* MS: We have to implement it because of rootfs-jffs2 issue on WB */
  66. #define flush_dcache_page(page) \
  67. do { \
  68. unsigned long addr = (unsigned long) page_address(page); /* virtual */ \
  69. addr = (u32)virt_to_phys((void *)addr); \
  70. flush_dcache_range((unsigned) (addr), (unsigned) (addr) + PAGE_SIZE); \
  71. } while (0);
  72. #define flush_dcache_mmap_lock(mapping) do { } while (0)
  73. #define flush_dcache_mmap_unlock(mapping) do { } while (0)
  74. #define flush_cache_dup_mm(mm) do { } while (0)
  75. #define flush_cache_vmap(start, end) do { } while (0)
  76. #define flush_cache_vunmap(start, end) do { } while (0)
  77. #define flush_cache_mm(mm) do { } while (0)
  78. #define flush_cache_page(vma, vmaddr, pfn) \
  79. flush_dcache_range(pfn << PAGE_SHIFT, (pfn << PAGE_SHIFT) + PAGE_SIZE);
  80. /* MS: kgdb code use this macro, wrong len with FLASH */
  81. #if 0
  82. #define flush_cache_range(vma, start, len) { \
  83. flush_icache_range((unsigned) (start), (unsigned) (start) + (len)); \
  84. flush_dcache_range((unsigned) (start), (unsigned) (start) + (len)); \
  85. }
  86. #endif
  87. #define flush_cache_range(vma, start, len) do { } while (0)
  88. static inline void copy_to_user_page(struct vm_area_struct *vma,
  89. struct page *page, unsigned long vaddr,
  90. void *dst, void *src, int len)
  91. {
  92. u32 addr = virt_to_phys(dst);
  93. memcpy(dst, src, len);
  94. if (vma->vm_flags & VM_EXEC) {
  95. invalidate_icache_range(addr, addr + PAGE_SIZE);
  96. flush_dcache_range(addr, addr + PAGE_SIZE);
  97. }
  98. }
  99. static inline void copy_from_user_page(struct vm_area_struct *vma,
  100. struct page *page, unsigned long vaddr,
  101. void *dst, void *src, int len)
  102. {
  103. memcpy(dst, src, len);
  104. }
  105. #endif /* _ASM_MICROBLAZE_CACHEFLUSH_H */