tlb.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * arch/sh64/mm/tlb.c
  3. *
  4. * Copyright (C) 2003 Paul Mundt <lethal@linux-sh.org>
  5. * Copyright (C) 2003 Richard Curnow <richard.curnow@superh.com>
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. *
  11. */
  12. #include <linux/mm.h>
  13. #include <linux/init.h>
  14. #include <asm/page.h>
  15. #include <asm/tlb.h>
  16. #include <asm/mmu_context.h>
  17. /**
  18. * sh64_tlb_init
  19. *
  20. * Perform initial setup for the DTLB and ITLB.
  21. */
  22. int __init sh64_tlb_init(void)
  23. {
  24. /* Assign some sane DTLB defaults */
  25. cpu_data->dtlb.entries = 64;
  26. cpu_data->dtlb.step = 0x10;
  27. cpu_data->dtlb.first = DTLB_FIXED | cpu_data->dtlb.step;
  28. cpu_data->dtlb.next = cpu_data->dtlb.first;
  29. cpu_data->dtlb.last = DTLB_FIXED |
  30. ((cpu_data->dtlb.entries - 1) *
  31. cpu_data->dtlb.step);
  32. /* And again for the ITLB */
  33. cpu_data->itlb.entries = 64;
  34. cpu_data->itlb.step = 0x10;
  35. cpu_data->itlb.first = ITLB_FIXED | cpu_data->itlb.step;
  36. cpu_data->itlb.next = cpu_data->itlb.first;
  37. cpu_data->itlb.last = ITLB_FIXED |
  38. ((cpu_data->itlb.entries - 1) *
  39. cpu_data->itlb.step);
  40. return 0;
  41. }
  42. /**
  43. * sh64_next_free_dtlb_entry
  44. *
  45. * Find the next available DTLB entry
  46. */
  47. unsigned long long sh64_next_free_dtlb_entry(void)
  48. {
  49. return cpu_data->dtlb.next;
  50. }
  51. /**
  52. * sh64_get_wired_dtlb_entry
  53. *
  54. * Allocate a wired (locked-in) entry in the DTLB
  55. */
  56. unsigned long long sh64_get_wired_dtlb_entry(void)
  57. {
  58. unsigned long long entry = sh64_next_free_dtlb_entry();
  59. cpu_data->dtlb.first += cpu_data->dtlb.step;
  60. cpu_data->dtlb.next += cpu_data->dtlb.step;
  61. return entry;
  62. }
  63. /**
  64. * sh64_put_wired_dtlb_entry
  65. *
  66. * @entry: Address of TLB slot.
  67. *
  68. * Free a wired (locked-in) entry in the DTLB.
  69. *
  70. * Works like a stack, last one to allocate must be first one to free.
  71. */
  72. int sh64_put_wired_dtlb_entry(unsigned long long entry)
  73. {
  74. __flush_tlb_slot(entry);
  75. /*
  76. * We don't do any particularly useful tracking of wired entries,
  77. * so this approach works like a stack .. last one to be allocated
  78. * has to be the first one to be freed.
  79. *
  80. * We could potentially load wired entries into a list and work on
  81. * rebalancing the list periodically (which also entails moving the
  82. * contents of a TLB entry) .. though I have a feeling that this is
  83. * more trouble than it's worth.
  84. */
  85. /*
  86. * Entry must be valid .. we don't want any ITLB addresses!
  87. */
  88. if (entry <= DTLB_FIXED)
  89. return -EINVAL;
  90. /*
  91. * Next, check if we're within range to be freed. (ie, must be the
  92. * entry beneath the first 'free' entry!
  93. */
  94. if (entry < (cpu_data->dtlb.first - cpu_data->dtlb.step))
  95. return -EINVAL;
  96. /* If we are, then bring this entry back into the list */
  97. cpu_data->dtlb.first -= cpu_data->dtlb.step;
  98. cpu_data->dtlb.next = entry;
  99. return 0;
  100. }
  101. /**
  102. * sh64_setup_tlb_slot
  103. *
  104. * @config_addr: Address of TLB slot.
  105. * @eaddr: Virtual address.
  106. * @asid: Address Space Identifier.
  107. * @paddr: Physical address.
  108. *
  109. * Load up a virtual<->physical translation for @eaddr<->@paddr in the
  110. * pre-allocated TLB slot @config_addr (see sh64_get_wired_dtlb_entry).
  111. */
  112. inline void sh64_setup_tlb_slot(unsigned long long config_addr,
  113. unsigned long eaddr,
  114. unsigned long asid,
  115. unsigned long paddr)
  116. {
  117. unsigned long long pteh, ptel;
  118. /* Sign extension */
  119. #if (NEFF == 32)
  120. pteh = (unsigned long long)(signed long long)(signed long) eaddr;
  121. #else
  122. #error "Can't sign extend more than 32 bits yet"
  123. #endif
  124. pteh &= PAGE_MASK;
  125. pteh |= (asid << PTEH_ASID_SHIFT) | PTEH_VALID;
  126. #if (NEFF == 32)
  127. ptel = (unsigned long long)(signed long long)(signed long) paddr;
  128. #else
  129. #error "Can't sign extend more than 32 bits yet"
  130. #endif
  131. ptel &= PAGE_MASK;
  132. ptel |= (_PAGE_CACHABLE | _PAGE_READ | _PAGE_WRITE);
  133. asm volatile("putcfg %0, 1, %1\n\t"
  134. "putcfg %0, 0, %2\n"
  135. : : "r" (config_addr), "r" (ptel), "r" (pteh));
  136. }
  137. /**
  138. * sh64_teardown_tlb_slot
  139. *
  140. * @config_addr: Address of TLB slot.
  141. *
  142. * Teardown any existing mapping in the TLB slot @config_addr.
  143. */
  144. inline void sh64_teardown_tlb_slot(unsigned long long config_addr)
  145. __attribute__ ((alias("__flush_tlb_slot")));