tlbflush.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (C) 2009 Chen Liqin <liqin.chen@sunplusct.com>
  3. * Copyright (C) 2012 Regents of the University of California
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation, version 2.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #ifndef _ASM_RISCV_TLBFLUSH_H
  15. #define _ASM_RISCV_TLBFLUSH_H
  16. #include <linux/mm_types.h>
  17. /*
  18. * Flush entire local TLB. 'sfence.vma' implicitly fences with the instruction
  19. * cache as well, so a 'fence.i' is not necessary.
  20. */
  21. static inline void local_flush_tlb_all(void)
  22. {
  23. __asm__ __volatile__ ("sfence.vma" : : : "memory");
  24. }
  25. /* Flush one page from local TLB */
  26. static inline void local_flush_tlb_page(unsigned long addr)
  27. {
  28. __asm__ __volatile__ ("sfence.vma %0" : : "r" (addr) : "memory");
  29. }
  30. #ifndef CONFIG_SMP
  31. #define flush_tlb_all() local_flush_tlb_all()
  32. #define flush_tlb_page(vma, addr) local_flush_tlb_page(addr)
  33. static inline void flush_tlb_range(struct vm_area_struct *vma,
  34. unsigned long start, unsigned long end)
  35. {
  36. local_flush_tlb_all();
  37. }
  38. #define flush_tlb_mm(mm) flush_tlb_all()
  39. #else /* CONFIG_SMP */
  40. #include <asm/sbi.h>
  41. #define flush_tlb_all() sbi_remote_sfence_vma(NULL, 0, -1)
  42. #define flush_tlb_page(vma, addr) flush_tlb_range(vma, addr, 0)
  43. #define flush_tlb_range(vma, start, end) \
  44. sbi_remote_sfence_vma(mm_cpumask((vma)->vm_mm)->bits, \
  45. start, (end) - (start))
  46. #define flush_tlb_mm(mm) \
  47. sbi_remote_sfence_vma(mm_cpumask(mm)->bits, 0, -1)
  48. #endif /* CONFIG_SMP */
  49. /* Flush a range of kernel pages */
  50. static inline void flush_tlb_kernel_range(unsigned long start,
  51. unsigned long end)
  52. {
  53. flush_tlb_all();
  54. }
  55. #endif /* _ASM_RISCV_TLBFLUSH_H */