tsb.h 5.6 KB

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