tlb.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2005-2017 Andes Technology Corporation
  3. #include <linux/spinlock_types.h>
  4. #include <linux/mm.h>
  5. #include <linux/sched.h>
  6. #include <asm/nds32.h>
  7. #include <nds32_intrinsic.h>
  8. unsigned int cpu_last_cid = { TLB_MISC_mskCID + (2 << TLB_MISC_offCID) };
  9. DEFINE_SPINLOCK(cid_lock);
  10. void local_flush_tlb_range(struct vm_area_struct *vma,
  11. unsigned long start, unsigned long end)
  12. {
  13. unsigned long flags, ocid, ncid;
  14. if ((end - start) > 0x400000) {
  15. __nds32__tlbop_flua();
  16. __nds32__isb();
  17. return;
  18. }
  19. spin_lock_irqsave(&cid_lock, flags);
  20. ocid = __nds32__mfsr(NDS32_SR_TLB_MISC);
  21. ncid = (ocid & ~TLB_MISC_mskCID) | vma->vm_mm->context.id;
  22. __nds32__mtsr_dsb(ncid, NDS32_SR_TLB_MISC);
  23. while (start < end) {
  24. __nds32__tlbop_inv(start);
  25. __nds32__isb();
  26. start += PAGE_SIZE;
  27. }
  28. __nds32__mtsr_dsb(ocid, NDS32_SR_TLB_MISC);
  29. spin_unlock_irqrestore(&cid_lock, flags);
  30. }
  31. void local_flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
  32. {
  33. unsigned long flags, ocid, ncid;
  34. spin_lock_irqsave(&cid_lock, flags);
  35. ocid = __nds32__mfsr(NDS32_SR_TLB_MISC);
  36. ncid = (ocid & ~TLB_MISC_mskCID) | vma->vm_mm->context.id;
  37. __nds32__mtsr_dsb(ncid, NDS32_SR_TLB_MISC);
  38. __nds32__tlbop_inv(addr);
  39. __nds32__isb();
  40. __nds32__mtsr_dsb(ocid, NDS32_SR_TLB_MISC);
  41. spin_unlock_irqrestore(&cid_lock, flags);
  42. }