cacheflush.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
  3. #include <linux/cache.h>
  4. #include <linux/highmem.h>
  5. #include <linux/mm.h>
  6. #include <asm/cache.h>
  7. void update_mmu_cache(struct vm_area_struct *vma, unsigned long address,
  8. pte_t *pte)
  9. {
  10. unsigned long addr;
  11. struct page *page;
  12. if (!pfn_valid(pte_pfn(*pte)))
  13. return;
  14. page = pfn_to_page(pte_pfn(*pte));
  15. if (page == ZERO_PAGE(0))
  16. return;
  17. if (test_and_set_bit(PG_dcache_clean, &page->flags))
  18. return;
  19. addr = (unsigned long) kmap_atomic(page);
  20. dcache_wb_range(addr, addr + PAGE_SIZE);
  21. if (vma->vm_flags & VM_EXEC)
  22. icache_inv_range(addr, addr + PAGE_SIZE);
  23. kunmap_atomic((void *) addr);
  24. }
  25. void flush_icache_deferred(struct mm_struct *mm)
  26. {
  27. unsigned int cpu = smp_processor_id();
  28. cpumask_t *mask = &mm->context.icache_stale_mask;
  29. if (cpumask_test_cpu(cpu, mask)) {
  30. cpumask_clear_cpu(cpu, mask);
  31. /*
  32. * Ensure the remote hart's writes are visible to this hart.
  33. * This pairs with a barrier in flush_icache_mm.
  34. */
  35. smp_mb();
  36. local_icache_inv_all(NULL);
  37. }
  38. }
  39. void flush_icache_mm_range(struct mm_struct *mm,
  40. unsigned long start, unsigned long end)
  41. {
  42. unsigned int cpu;
  43. cpumask_t others, *mask;
  44. preempt_disable();
  45. #ifdef CONFIG_CPU_HAS_ICACHE_INS
  46. if (mm == current->mm) {
  47. icache_inv_range(start, end);
  48. preempt_enable();
  49. return;
  50. }
  51. #endif
  52. /* Mark every hart's icache as needing a flush for this MM. */
  53. mask = &mm->context.icache_stale_mask;
  54. cpumask_setall(mask);
  55. /* Flush this hart's I$ now, and mark it as flushed. */
  56. cpu = smp_processor_id();
  57. cpumask_clear_cpu(cpu, mask);
  58. local_icache_inv_all(NULL);
  59. /*
  60. * Flush the I$ of other harts concurrently executing, and mark them as
  61. * flushed.
  62. */
  63. cpumask_andnot(&others, mm_cpumask(mm), cpumask_of(cpu));
  64. if (mm != current->active_mm || !cpumask_empty(&others)) {
  65. on_each_cpu_mask(&others, local_icache_inv_all, NULL, 1);
  66. cpumask_clear(mask);
  67. }
  68. preempt_enable();
  69. }