cacheflush.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 <[email protected]>
  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. /*
  24. * Data cache flushing always happen on the local cpu. Instruction cache
  25. * invalidations need to be broadcasted to all other cpu in the system in
  26. * case of SMP configurations.
  27. */
  28. #ifndef CONFIG_SMP
  29. #define dcache_page_flush(page) local_dcache_page_flush(page)
  30. #define icache_page_inv(page) local_icache_page_inv(page)
  31. #else /* CONFIG_SMP */
  32. #define dcache_page_flush(page) local_dcache_page_flush(page)
  33. #define icache_page_inv(page) smp_icache_page_inv(page)
  34. extern void smp_icache_page_inv(struct page *page);
  35. #endif /* CONFIG_SMP */
  36. /*
  37. * Synchronizes caches. Whenever a cpu writes executable code to memory, this
  38. * should be called to make sure the processor sees the newly written code.
  39. */
  40. static inline void sync_icache_dcache(struct page *page)
  41. {
  42. if (!IS_ENABLED(CONFIG_DCACHE_WRITETHROUGH))
  43. dcache_page_flush(page);
  44. icache_page_inv(page);
  45. }
  46. /*
  47. * Pages with this bit set need not be flushed/invalidated, since
  48. * they have not changed since last flush. New pages start with
  49. * PG_arch_1 not set and are therefore dirty by default.
  50. */
  51. #define PG_dc_clean PG_arch_1
  52. #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
  53. static inline void flush_dcache_page(struct page *page)
  54. {
  55. clear_bit(PG_dc_clean, &page->flags);
  56. }
  57. #define flush_icache_user_page(vma, page, addr, len) \
  58. do { \
  59. if (vma->vm_flags & VM_EXEC) \
  60. sync_icache_dcache(page); \
  61. } while (0)
  62. #include <asm-generic/cacheflush.h>
  63. #endif /* __ASM_CACHEFLUSH_H */