cacheflush.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2007-2009 Michal Simek <[email protected]>
  4. * Copyright (C) 2007-2009 PetaLogix
  5. * Copyright (C) 2007 John Williams <[email protected]>
  6. * based on v850 version which was
  7. * Copyright (C) 2001,02,03 NEC Electronics Corporation
  8. * Copyright (C) 2001,02,03 Miles Bader <[email protected]>
  9. */
  10. #ifndef _ASM_MICROBLAZE_CACHEFLUSH_H
  11. #define _ASM_MICROBLAZE_CACHEFLUSH_H
  12. /* Somebody depends on this; sigh... */
  13. #include <linux/mm.h>
  14. #include <linux/io.h>
  15. /* Look at Documentation/core-api/cachetlb.rst */
  16. /*
  17. * Cache handling functions.
  18. * Microblaze has a write-through data cache, meaning that the data cache
  19. * never needs to be flushed. The only flushing operations that are
  20. * implemented are to invalidate the instruction cache. These are called
  21. * after loading a user application into memory, we must invalidate the
  22. * instruction cache to make sure we don't fetch old, bad code.
  23. */
  24. /* struct cache, d=dcache, i=icache, fl = flush, iv = invalidate,
  25. * suffix r = range */
  26. struct scache {
  27. /* icache */
  28. void (*ie)(void); /* enable */
  29. void (*id)(void); /* disable */
  30. void (*ifl)(void); /* flush */
  31. void (*iflr)(unsigned long a, unsigned long b);
  32. void (*iin)(void); /* invalidate */
  33. void (*iinr)(unsigned long a, unsigned long b);
  34. /* dcache */
  35. void (*de)(void); /* enable */
  36. void (*dd)(void); /* disable */
  37. void (*dfl)(void); /* flush */
  38. void (*dflr)(unsigned long a, unsigned long b);
  39. void (*din)(void); /* invalidate */
  40. void (*dinr)(unsigned long a, unsigned long b);
  41. };
  42. /* microblaze cache */
  43. extern struct scache *mbc;
  44. void microblaze_cache_init(void);
  45. #define enable_icache() mbc->ie();
  46. #define disable_icache() mbc->id();
  47. #define flush_icache() mbc->ifl();
  48. #define flush_icache_range(start, end) mbc->iflr(start, end);
  49. #define invalidate_icache() mbc->iin();
  50. #define invalidate_icache_range(start, end) mbc->iinr(start, end);
  51. #define enable_dcache() mbc->de();
  52. #define disable_dcache() mbc->dd();
  53. /* FIXME for LL-temac driver */
  54. #define invalidate_dcache() mbc->din();
  55. #define invalidate_dcache_range(start, end) mbc->dinr(start, end);
  56. #define flush_dcache() mbc->dfl();
  57. #define flush_dcache_range(start, end) mbc->dflr(start, end);
  58. #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
  59. /* MS: We have to implement it because of rootfs-jffs2 issue on WB */
  60. #define flush_dcache_page(page) \
  61. do { \
  62. unsigned long addr = (unsigned long) page_address(page); /* virtual */ \
  63. addr = (u32)virt_to_phys((void *)addr); \
  64. flush_dcache_range((unsigned) (addr), (unsigned) (addr) + PAGE_SIZE); \
  65. } while (0);
  66. #define flush_cache_page(vma, vmaddr, pfn) \
  67. flush_dcache_range(pfn << PAGE_SHIFT, (pfn << PAGE_SHIFT) + PAGE_SIZE);
  68. static inline void copy_to_user_page(struct vm_area_struct *vma,
  69. struct page *page, unsigned long vaddr,
  70. void *dst, void *src, int len)
  71. {
  72. u32 addr = virt_to_phys(dst);
  73. memcpy(dst, src, len);
  74. if (vma->vm_flags & VM_EXEC) {
  75. invalidate_icache_range(addr, addr + PAGE_SIZE);
  76. flush_dcache_range(addr, addr + PAGE_SIZE);
  77. }
  78. }
  79. #define copy_to_user_page copy_to_user_page
  80. #include <asm-generic/cacheflush.h>
  81. #endif /* _ASM_MICROBLAZE_CACHEFLUSH_H */