tlb-sh4.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * arch/sh/mm/tlb-sh4.c
  4. *
  5. * SH-4 specific TLB operations
  6. *
  7. * Copyright (C) 1999 Niibe Yutaka
  8. * Copyright (C) 2002 - 2007 Paul Mundt
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/mm.h>
  12. #include <linux/io.h>
  13. #include <asm/mmu_context.h>
  14. #include <asm/cacheflush.h>
  15. void __update_tlb(struct vm_area_struct *vma, unsigned long address, pte_t pte)
  16. {
  17. unsigned long flags, pteval, vpn;
  18. /*
  19. * Handle debugger faulting in for debugee.
  20. */
  21. if (vma && current->active_mm != vma->vm_mm)
  22. return;
  23. local_irq_save(flags);
  24. /* Set PTEH register */
  25. vpn = (address & MMU_VPN_MASK) | get_asid();
  26. __raw_writel(vpn, MMU_PTEH);
  27. pteval = pte.pte_low;
  28. /* Set PTEA register */
  29. #ifdef CONFIG_X2TLB
  30. /*
  31. * For the extended mode TLB this is trivial, only the ESZ and
  32. * EPR bits need to be written out to PTEA, with the remainder of
  33. * the protection bits (with the exception of the compat-mode SZ
  34. * and PR bits, which are cleared) being written out in PTEL.
  35. */
  36. __raw_writel(pte.pte_high, MMU_PTEA);
  37. #else
  38. if (cpu_data->flags & CPU_HAS_PTEA) {
  39. /* The last 3 bits and the first one of pteval contains
  40. * the PTEA timing control and space attribute bits
  41. */
  42. __raw_writel(copy_ptea_attributes(pteval), MMU_PTEA);
  43. }
  44. #endif
  45. /* Set PTEL register */
  46. pteval &= _PAGE_FLAGS_HARDWARE_MASK; /* drop software flags */
  47. #ifdef CONFIG_CACHE_WRITETHROUGH
  48. pteval |= _PAGE_WT;
  49. #endif
  50. /* conveniently, we want all the software flags to be 0 anyway */
  51. __raw_writel(pteval, MMU_PTEL);
  52. /* Load the TLB */
  53. asm volatile("ldtlb": /* no output */ : /* no input */ : "memory");
  54. local_irq_restore(flags);
  55. }
  56. void local_flush_tlb_one(unsigned long asid, unsigned long page)
  57. {
  58. unsigned long addr, data;
  59. /*
  60. * NOTE: PTEH.ASID should be set to this MM
  61. * _AND_ we need to write ASID to the array.
  62. *
  63. * It would be simple if we didn't need to set PTEH.ASID...
  64. */
  65. addr = MMU_UTLB_ADDRESS_ARRAY | MMU_PAGE_ASSOC_BIT;
  66. data = page | asid; /* VALID bit is off */
  67. jump_to_uncached();
  68. __raw_writel(data, addr);
  69. back_to_cached();
  70. }
  71. void local_flush_tlb_all(void)
  72. {
  73. unsigned long flags, status;
  74. int i;
  75. /*
  76. * Flush all the TLB.
  77. */
  78. local_irq_save(flags);
  79. jump_to_uncached();
  80. status = __raw_readl(MMUCR);
  81. status = ((status & MMUCR_URB) >> MMUCR_URB_SHIFT);
  82. if (status == 0)
  83. status = MMUCR_URB_NENTRIES;
  84. for (i = 0; i < status; i++)
  85. __raw_writel(0x0, MMU_UTLB_ADDRESS_ARRAY | (i << 8));
  86. for (i = 0; i < 4; i++)
  87. __raw_writel(0x0, MMU_ITLB_ADDRESS_ARRAY | (i << 8));
  88. back_to_cached();
  89. ctrl_barrier();
  90. local_irq_restore(flags);
  91. }