tsb.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #ifndef _SPARC64_TSB_H
  2. #define _SPARC64_TSB_H
  3. /* The sparc64 TSB is similar to the powerpc hashtables. It's a
  4. * power-of-2 sized table of TAG/PTE pairs. The cpu precomputes
  5. * pointers into this table for 8K and 64K page sizes, and also a
  6. * comparison TAG based upon the virtual address and context which
  7. * faults.
  8. *
  9. * TLB miss trap handler software does the actual lookup via something
  10. * of the form:
  11. *
  12. * ldxa [%g0] ASI_{D,I}MMU_TSB_8KB_PTR, %g1
  13. * ldxa [%g0] ASI_{D,I}MMU, %g6
  14. * ldda [%g1] ASI_NUCLEUS_QUAD_LDD, %g4
  15. * cmp %g4, %g6
  16. * bne,pn %xcc, tsb_miss_{d,i}tlb
  17. * mov FAULT_CODE_{D,I}TLB, %g3
  18. * stxa %g5, [%g0] ASI_{D,I}TLB_DATA_IN
  19. * retry
  20. *
  21. *
  22. * Each 16-byte slot of the TSB is the 8-byte tag and then the 8-byte
  23. * PTE. The TAG is of the same layout as the TLB TAG TARGET mmu
  24. * register which is:
  25. *
  26. * -------------------------------------------------
  27. * | - | CONTEXT | - | VADDR bits 63:22 |
  28. * -------------------------------------------------
  29. * 63 61 60 48 47 42 41 0
  30. *
  31. * Like the powerpc hashtables we need to use locking in order to
  32. * synchronize while we update the entries. PTE updates need locking
  33. * as well.
  34. *
  35. * We need to carefully choose a lock bits for the TSB entry. We
  36. * choose to use bit 47 in the tag. Also, since we never map anything
  37. * at page zero in context zero, we use zero as an invalid tag entry.
  38. * When the lock bit is set, this forces a tag comparison failure.
  39. *
  40. * Currently, we allocate an 8K TSB per-process and we use it for both
  41. * I-TLB and D-TLB misses. Perhaps at some point we'll add code that
  42. * monitors the number of active pages in the process as we get
  43. * major/minor faults, and grow the TSB in response. The only trick
  44. * in implementing that is synchronizing the freeing of the old TSB
  45. * wrt. parallel TSB updates occuring on other processors. On
  46. * possible solution is to use RCU for the freeing of the TSB.
  47. */
  48. #define TSB_TAG_LOCK_BIT 47
  49. #define TSB_TAG_LOCK_HIGH (1 << (TSB_TAG_LOCK_BIT - 32))
  50. #define TSB_MEMBAR membar #StoreStore
  51. #define TSB_LOCK_TAG(TSB, REG1, REG2) \
  52. 99: lduwa [TSB] ASI_N, REG1; \
  53. sethi %hi(TSB_TAG_LOCK_HIGH), REG2;\
  54. andcc REG1, REG2, %g0; \
  55. bne,pn %icc, 99b; \
  56. nop; \
  57. casa [TSB] ASI_N, REG1, REG2;\
  58. cmp REG1, REG2; \
  59. bne,pn %icc, 99b; \
  60. nop; \
  61. TSB_MEMBAR
  62. #define TSB_WRITE(TSB, TTE, TAG) \
  63. stx TTE, [TSB + 0x08]; \
  64. TSB_MEMBAR; \
  65. stx TAG, [TSB + 0x00];
  66. /* Do a kernel page table walk. Leaves physical PTE pointer in
  67. * REG1. Jumps to FAIL_LABEL on early page table walk termination.
  68. * VADDR will not be clobbered, but REG2 will.
  69. */
  70. #define KERN_PGTABLE_WALK(VADDR, REG1, REG2, FAIL_LABEL) \
  71. sethi %hi(swapper_pg_dir), REG1; \
  72. or REG1, %lo(swapper_pg_dir), REG1; \
  73. sllx VADDR, 64 - (PGDIR_SHIFT + PGDIR_BITS), REG2; \
  74. srlx REG2, 64 - PAGE_SHIFT, REG2; \
  75. andn REG2, 0x3, REG2; \
  76. lduw [REG1 + REG2], REG1; \
  77. brz,pn REG1, FAIL_LABEL; \
  78. sllx VADDR, 64 - (PMD_SHIFT + PMD_BITS), REG2; \
  79. srlx REG2, 64 - PAGE_SHIFT, REG2; \
  80. sllx REG1, 11, REG1; \
  81. andn REG2, 0x3, REG2; \
  82. lduwa [REG1 + REG2] ASI_PHYS_USE_EC, REG1; \
  83. brz,pn REG1, FAIL_LABEL; \
  84. sllx VADDR, 64 - PMD_SHIFT, REG2; \
  85. srlx REG2, 64 - PAGE_SHIFT, REG2; \
  86. sllx REG1, 11, REG1; \
  87. andn REG2, 0x7, REG2; \
  88. add REG1, REG2, REG1;
  89. /* Do a user page table walk in MMU globals. Leaves physical PTE
  90. * pointer in REG1. Jumps to FAIL_LABEL on early page table walk
  91. * termination. Physical base of page tables is in PHYS_PGD which
  92. * will not be modified.
  93. *
  94. * VADDR will not be clobbered, but REG1 and REG2 will.
  95. */
  96. #define USER_PGTABLE_WALK_TL1(VADDR, PHYS_PGD, REG1, REG2, FAIL_LABEL) \
  97. sllx VADDR, 64 - (PGDIR_SHIFT + PGDIR_BITS), REG2; \
  98. srlx REG2, 64 - PAGE_SHIFT, REG2; \
  99. andn REG2, 0x3, REG2; \
  100. lduwa [PHYS_PGD + REG2] ASI_PHYS_USE_EC, REG1; \
  101. brz,pn REG1, FAIL_LABEL; \
  102. sllx VADDR, 64 - (PMD_SHIFT + PMD_BITS), REG2; \
  103. srlx REG2, 64 - PAGE_SHIFT, REG2; \
  104. sllx REG1, 11, REG1; \
  105. andn REG2, 0x3, REG2; \
  106. lduwa [REG1 + REG2] ASI_PHYS_USE_EC, REG1; \
  107. brz,pn REG1, FAIL_LABEL; \
  108. sllx VADDR, 64 - PMD_SHIFT, REG2; \
  109. srlx REG2, 64 - PAGE_SHIFT, REG2; \
  110. sllx REG1, 11, REG1; \
  111. andn REG2, 0x7, REG2; \
  112. add REG1, REG2, REG1;
  113. /* Lookup a OBP mapping on VADDR in the prom_trans[] table at TL>0.
  114. * If no entry is found, FAIL_LABEL will be branched to. On success
  115. * the resulting PTE value will be left in REG1. VADDR is preserved
  116. * by this routine.
  117. */
  118. #define OBP_TRANS_LOOKUP(VADDR, REG1, REG2, REG3, FAIL_LABEL) \
  119. sethi %hi(prom_trans), REG1; \
  120. or REG1, %lo(prom_trans), REG1; \
  121. 97: ldx [REG1 + 0x00], REG2; \
  122. brz,pn REG2, FAIL_LABEL; \
  123. nop; \
  124. ldx [REG1 + 0x08], REG3; \
  125. add REG2, REG3, REG3; \
  126. cmp REG2, VADDR; \
  127. bgu,pt %xcc, 98f; \
  128. cmp VADDR, REG3; \
  129. bgeu,pt %xcc, 98f; \
  130. ldx [REG1 + 0x10], REG3; \
  131. sub VADDR, REG2, REG2; \
  132. ba,pt %xcc, 99f; \
  133. add REG3, REG2, REG1; \
  134. 98: ba,pt %xcc, 97b; \
  135. add REG1, (3 * 8), REG1; \
  136. 99:
  137. /* Do a kernel TSB lookup at tl>0 on VADDR+TAG, branch to OK_LABEL
  138. * on TSB hit. REG1, REG2, REG3, and REG4 are used as temporaries
  139. * and the found TTE will be left in REG1. REG3 and REG4 must
  140. * be an even/odd pair of registers.
  141. *
  142. * VADDR and TAG will be preserved and not clobbered by this macro.
  143. */
  144. /* XXX non-8K base page size support... */
  145. #define KERN_TSB_LOOKUP_TL1(VADDR, TAG, REG1, REG2, REG3, REG4, OK_LABEL) \
  146. sethi %hi(swapper_tsb), REG1; \
  147. or REG1, %lo(swapper_tsb), REG1; \
  148. srlx VADDR, 13, REG2; \
  149. and REG2, (512 - 1), REG2; \
  150. sllx REG2, 4, REG2; \
  151. add REG1, REG2, REG2; \
  152. ldda [REG2] ASI_NUCLEUS_QUAD_LDD, REG3; \
  153. cmp REG3, TAG; \
  154. be,a,pt %xcc, OK_LABEL; \
  155. mov REG4, REG1;
  156. #endif /* !(_SPARC64_TSB_H) */