cacheflush.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2015 Regents of the University of California
  4. */
  5. #ifndef _ASM_RISCV_CACHEFLUSH_H
  6. #define _ASM_RISCV_CACHEFLUSH_H
  7. #include <linux/mm.h>
  8. static inline void local_flush_icache_all(void)
  9. {
  10. asm volatile ("fence.i" ::: "memory");
  11. }
  12. static inline void local_flush_icache_range(unsigned long start,
  13. unsigned long end)
  14. {
  15. local_flush_icache_all();
  16. }
  17. #define PG_dcache_clean PG_arch_1
  18. static inline void flush_dcache_folio(struct folio *folio)
  19. {
  20. if (test_bit(PG_dcache_clean, &folio->flags))
  21. clear_bit(PG_dcache_clean, &folio->flags);
  22. }
  23. #define flush_dcache_folio flush_dcache_folio
  24. #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
  25. static inline void flush_dcache_page(struct page *page)
  26. {
  27. flush_dcache_folio(page_folio(page));
  28. }
  29. #define flush_icache_user_page(vma, pg, addr, len) \
  30. do { \
  31. if (vma->vm_flags & VM_EXEC) \
  32. flush_icache_mm(vma->vm_mm, 0); \
  33. } while (0)
  34. #ifdef CONFIG_64BIT
  35. extern u64 new_vmalloc[NR_CPUS / sizeof(u64) + 1];
  36. extern char _end[];
  37. #define flush_cache_vmap flush_cache_vmap
  38. static inline void flush_cache_vmap(unsigned long start, unsigned long end)
  39. {
  40. if (is_vmalloc_or_module_addr((void *)start)) {
  41. int i;
  42. /*
  43. * We don't care if concurrently a cpu resets this value since
  44. * the only place this can happen is in handle_exception() where
  45. * an sfence.vma is emitted.
  46. */
  47. for (i = 0; i < ARRAY_SIZE(new_vmalloc); ++i)
  48. new_vmalloc[i] = -1ULL;
  49. }
  50. }
  51. #define flush_cache_vmap_early(start, end) local_flush_tlb_kernel_range(start, end)
  52. #endif
  53. #ifndef CONFIG_SMP
  54. #define flush_icache_all() local_flush_icache_all()
  55. #define flush_icache_mm(mm, local) flush_icache_all()
  56. #else /* CONFIG_SMP */
  57. void flush_icache_all(void);
  58. void flush_icache_mm(struct mm_struct *mm, bool local);
  59. #endif /* CONFIG_SMP */
  60. /*
  61. * RISC-V doesn't have an instruction to flush parts of the instruction cache,
  62. * so instead we just flush the whole thing.
  63. */
  64. #define flush_icache_range flush_icache_range
  65. static inline void flush_icache_range(unsigned long start, unsigned long end)
  66. {
  67. flush_icache_all();
  68. }
  69. extern unsigned int riscv_cbom_block_size;
  70. extern unsigned int riscv_cboz_block_size;
  71. void riscv_init_cbo_blocksizes(void);
  72. #ifdef CONFIG_RISCV_DMA_NONCOHERENT
  73. void riscv_noncoherent_supported(void);
  74. void __init riscv_set_dma_cache_alignment(void);
  75. #else
  76. static inline void riscv_noncoherent_supported(void) {}
  77. static inline void riscv_set_dma_cache_alignment(void) {}
  78. #endif
  79. /*
  80. * Bits in sys_riscv_flush_icache()'s flags argument.
  81. */
  82. #define SYS_RISCV_FLUSH_ICACHE_LOCAL 1UL
  83. #define SYS_RISCV_FLUSH_ICACHE_ALL (SYS_RISCV_FLUSH_ICACHE_LOCAL)
  84. #include <asm-generic/cacheflush.h>
  85. #endif /* _ASM_RISCV_CACHEFLUSH_H */