cacheflush.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * OpenRISC Linux
  4. *
  5. * Linux architectural port borrowing liberally from similar works of
  6. * others. All original copyrights apply as per the original source
  7. * declaration.
  8. *
  9. * OpenRISC implementation:
  10. * Copyright (C) Jan Henrik Weinstock <jan.weinstock@rwth-aachen.de>
  11. * et al.
  12. */
  13. #ifndef __ASM_CACHEFLUSH_H
  14. #define __ASM_CACHEFLUSH_H
  15. #include <linux/mm.h>
  16. /*
  17. * Helper function for flushing or invalidating entire pages from data
  18. * and instruction caches. SMP needs a little extra work, since we need
  19. * to flush the pages on all cpus.
  20. */
  21. extern void local_dcache_page_flush(struct page *page);
  22. extern void local_icache_page_inv(struct page *page);
  23. extern void local_dcache_range_flush(unsigned long start, unsigned long end);
  24. extern void local_dcache_range_inv(unsigned long start, unsigned long end);
  25. extern void local_icache_range_inv(unsigned long start, unsigned long end);
  26. /*
  27. * Data cache flushing always happen on the local cpu. Instruction cache
  28. * invalidations need to be broadcasted to all other cpu in the system in
  29. * case of SMP configurations.
  30. */
  31. #ifndef CONFIG_SMP
  32. #define dcache_page_flush(page) local_dcache_page_flush(page)
  33. #define icache_page_inv(page) local_icache_page_inv(page)
  34. #else /* CONFIG_SMP */
  35. #define dcache_page_flush(page) local_dcache_page_flush(page)
  36. #define icache_page_inv(page) smp_icache_page_inv(page)
  37. extern void smp_icache_page_inv(struct page *page);
  38. #endif /* CONFIG_SMP */
  39. /*
  40. * Even if the actual block size is larger than L1_CACHE_BYTES, paddr
  41. * can be incremented by L1_CACHE_BYTES. When paddr is written to the
  42. * invalidate register, the entire cache line encompassing this address
  43. * is invalidated. Each subsequent reference to the same cache line will
  44. * not affect the invalidation process.
  45. */
  46. #define local_dcache_block_flush(addr) \
  47. local_dcache_range_flush(addr, addr + L1_CACHE_BYTES)
  48. #define local_dcache_block_inv(addr) \
  49. local_dcache_range_inv(addr, addr + L1_CACHE_BYTES)
  50. #define local_icache_block_inv(addr) \
  51. local_icache_range_inv(addr, addr + L1_CACHE_BYTES)
  52. /*
  53. * Synchronizes caches. Whenever a cpu writes executable code to memory, this
  54. * should be called to make sure the processor sees the newly written code.
  55. */
  56. static inline void sync_icache_dcache(struct page *page)
  57. {
  58. if (!IS_ENABLED(CONFIG_DCACHE_WRITETHROUGH))
  59. dcache_page_flush(page);
  60. icache_page_inv(page);
  61. }
  62. /*
  63. * Pages with this bit set need not be flushed/invalidated, since
  64. * they have not changed since last flush. New pages start with
  65. * PG_arch_1 not set and are therefore dirty by default.
  66. */
  67. #define PG_dc_clean PG_arch_1
  68. static inline void flush_dcache_folio(struct folio *folio)
  69. {
  70. clear_bit(PG_dc_clean, &folio->flags.f);
  71. }
  72. #define flush_dcache_folio flush_dcache_folio
  73. #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
  74. static inline void flush_dcache_page(struct page *page)
  75. {
  76. flush_dcache_folio(page_folio(page));
  77. }
  78. #define flush_icache_user_page(vma, page, addr, len) \
  79. do { \
  80. if (vma->vm_flags & VM_EXEC) \
  81. sync_icache_dcache(page); \
  82. } while (0)
  83. #include <asm-generic/cacheflush.h>
  84. #endif /* __ASM_CACHEFLUSH_H */