cacheflush.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * OpenRISC Linux
  3. *
  4. * Linux architectural port borrowing liberally from similar works of
  5. * others. All original copyrights apply as per the original source
  6. * declaration.
  7. *
  8. * OpenRISC implementation:
  9. * Copyright (C) Jan Henrik Weinstock <jan.weinstock@rwth-aachen.de>
  10. * et al.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. */
  17. #ifndef __ASM_CACHEFLUSH_H
  18. #define __ASM_CACHEFLUSH_H
  19. #include <linux/mm.h>
  20. /*
  21. * Helper function for flushing or invalidating entire pages from data
  22. * and instruction caches. SMP needs a little extra work, since we need
  23. * to flush the pages on all cpus.
  24. */
  25. extern void local_dcache_page_flush(struct page *page);
  26. extern void local_icache_page_inv(struct page *page);
  27. /*
  28. * Data cache flushing always happen on the local cpu. Instruction cache
  29. * invalidations need to be broadcasted to all other cpu in the system in
  30. * case of SMP configurations.
  31. */
  32. #ifndef CONFIG_SMP
  33. #define dcache_page_flush(page) local_dcache_page_flush(page)
  34. #define icache_page_inv(page) local_icache_page_inv(page)
  35. #else /* CONFIG_SMP */
  36. #define dcache_page_flush(page) local_dcache_page_flush(page)
  37. #define icache_page_inv(page) smp_icache_page_inv(page)
  38. extern void smp_icache_page_inv(struct page *page);
  39. #endif /* CONFIG_SMP */
  40. /*
  41. * Synchronizes caches. Whenever a cpu writes executable code to memory, this
  42. * should be called to make sure the processor sees the newly written code.
  43. */
  44. static inline void sync_icache_dcache(struct page *page)
  45. {
  46. if (!IS_ENABLED(CONFIG_DCACHE_WRITETHROUGH))
  47. dcache_page_flush(page);
  48. icache_page_inv(page);
  49. }
  50. /*
  51. * Pages with this bit set need not be flushed/invalidated, since
  52. * they have not changed since last flush. New pages start with
  53. * PG_arch_1 not set and are therefore dirty by default.
  54. */
  55. #define PG_dc_clean PG_arch_1
  56. #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
  57. static inline void flush_dcache_page(struct page *page)
  58. {
  59. clear_bit(PG_dc_clean, &page->flags);
  60. }
  61. /*
  62. * Other interfaces are not required since we do not have virtually
  63. * indexed or tagged caches. So we can use the default here.
  64. */
  65. #define flush_cache_all() do { } while (0)
  66. #define flush_cache_mm(mm) do { } while (0)
  67. #define flush_cache_dup_mm(mm) do { } while (0)
  68. #define flush_cache_range(vma, start, end) do { } while (0)
  69. #define flush_cache_page(vma, vmaddr, pfn) do { } while (0)
  70. #define flush_dcache_mmap_lock(mapping) do { } while (0)
  71. #define flush_dcache_mmap_unlock(mapping) do { } while (0)
  72. #define flush_icache_range(start, end) do { } while (0)
  73. #define flush_icache_page(vma, pg) do { } while (0)
  74. #define flush_icache_user_range(vma, pg, adr, len) 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 copy_to_user_page(vma, page, vaddr, dst, src, len) \
  78. do { \
  79. memcpy(dst, src, len); \
  80. if (vma->vm_flags & VM_EXEC) \
  81. sync_icache_dcache(page); \
  82. } while (0)
  83. #define copy_from_user_page(vma, page, vaddr, dst, src, len) \
  84. memcpy(dst, src, len)
  85. #endif /* __ASM_CACHEFLUSH_H */