tlb-pteaex.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * arch/sh/mm/tlb-pteaex.c
  3. *
  4. * TLB operations for SH-X3 CPUs featuring PTE ASID Extensions.
  5. *
  6. * Copyright (C) 2009 Paul Mundt
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/mm.h>
  14. #include <linux/io.h>
  15. #include <asm/system.h>
  16. #include <asm/mmu_context.h>
  17. #include <asm/cacheflush.h>
  18. void __update_tlb(struct vm_area_struct *vma, unsigned long address, pte_t pte)
  19. {
  20. unsigned long flags, pteval, vpn;
  21. /*
  22. * Handle debugger faulting in for debugee.
  23. */
  24. if (vma && current->active_mm != vma->vm_mm)
  25. return;
  26. local_irq_save(flags);
  27. /* Set PTEH register */
  28. vpn = address & MMU_VPN_MASK;
  29. __raw_writel(vpn, MMU_PTEH);
  30. /* Set PTEAEX */
  31. __raw_writel(get_asid(), MMU_PTEAEX);
  32. pteval = pte.pte_low;
  33. /* Set PTEA register */
  34. #ifdef CONFIG_X2TLB
  35. /*
  36. * For the extended mode TLB this is trivial, only the ESZ and
  37. * EPR bits need to be written out to PTEA, with the remainder of
  38. * the protection bits (with the exception of the compat-mode SZ
  39. * and PR bits, which are cleared) being written out in PTEL.
  40. */
  41. __raw_writel(pte.pte_high, MMU_PTEA);
  42. #endif
  43. /* Set PTEL register */
  44. pteval &= _PAGE_FLAGS_HARDWARE_MASK; /* drop software flags */
  45. #ifdef CONFIG_CACHE_WRITETHROUGH
  46. pteval |= _PAGE_WT;
  47. #endif
  48. /* conveniently, we want all the software flags to be 0 anyway */
  49. __raw_writel(pteval, MMU_PTEL);
  50. /* Load the TLB */
  51. asm volatile("ldtlb": /* no output */ : /* no input */ : "memory");
  52. local_irq_restore(flags);
  53. }
  54. /*
  55. * While SH-X2 extended TLB mode splits out the memory-mapped I/UTLB
  56. * data arrays, SH-X3 cores with PTEAEX split out the memory-mapped
  57. * address arrays. In compat mode the second array is inaccessible, while
  58. * in extended mode, the legacy 8-bit ASID field in address array 1 has
  59. * undefined behaviour.
  60. */
  61. void __uses_jump_to_uncached local_flush_tlb_one(unsigned long asid,
  62. unsigned long page)
  63. {
  64. jump_to_uncached();
  65. __raw_writel(page, MMU_UTLB_ADDRESS_ARRAY | MMU_PAGE_ASSOC_BIT);
  66. __raw_writel(asid, MMU_UTLB_ADDRESS_ARRAY2 | MMU_PAGE_ASSOC_BIT);
  67. back_to_cached();
  68. }
  69. /*
  70. * Load the entry for 'addr' into the TLB and wire the entry.
  71. */
  72. void tlb_wire_entry(struct vm_area_struct *vma, unsigned long addr, pte_t pte)
  73. {
  74. unsigned long status, flags;
  75. int urb;
  76. local_irq_save(flags);
  77. /* Load the entry into the TLB */
  78. __update_tlb(vma, addr, pte);
  79. /* ... and wire it up. */
  80. status = ctrl_inl(MMUCR);
  81. urb = (status & MMUCR_URB) >> MMUCR_URB_SHIFT;
  82. status &= ~MMUCR_URB;
  83. /*
  84. * Make sure we're not trying to wire the last TLB entry slot.
  85. */
  86. BUG_ON(!--urb);
  87. urb = urb % MMUCR_URB_NENTRIES;
  88. status |= (urb << MMUCR_URB_SHIFT);
  89. ctrl_outl(status, MMUCR);
  90. ctrl_barrier();
  91. local_irq_restore(flags);
  92. }
  93. /*
  94. * Unwire the last wired TLB entry.
  95. *
  96. * It should also be noted that it is not possible to wire and unwire
  97. * TLB entries in an arbitrary order. If you wire TLB entry N, followed
  98. * by entry N+1, you must unwire entry N+1 first, then entry N. In this
  99. * respect, it works like a stack or LIFO queue.
  100. */
  101. void tlb_unwire_entry(void)
  102. {
  103. unsigned long status, flags;
  104. int urb;
  105. local_irq_save(flags);
  106. status = ctrl_inl(MMUCR);
  107. urb = (status & MMUCR_URB) >> MMUCR_URB_SHIFT;
  108. status &= ~MMUCR_URB;
  109. /*
  110. * Make sure we're not trying to unwire a TLB entry when none
  111. * have been wired.
  112. */
  113. BUG_ON(urb++ == MMUCR_URB_NENTRIES);
  114. urb = urb % MMUCR_URB_NENTRIES;
  115. status |= (urb << MMUCR_URB_SHIFT);
  116. ctrl_outl(status, MMUCR);
  117. ctrl_barrier();
  118. local_irq_restore(flags);
  119. }