dtlb_backend.S 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* $Id: dtlb_backend.S,v 1.16 2001/10/09 04:02:11 davem Exp $
  2. * dtlb_backend.S: Back end to DTLB miss replacement strategy.
  3. * This is included directly into the trap table.
  4. *
  5. * Copyright (C) 1996,1998 David S. Miller (davem@redhat.com)
  6. * Copyright (C) 1997,1998 Jakub Jelinek (jj@ultra.linux.cz)
  7. */
  8. #include <asm/pgtable.h>
  9. #include <asm/mmu.h>
  10. #define VALID_SZ_BITS (_PAGE_VALID | _PAGE_SZBITS)
  11. #define VPTE_BITS (_PAGE_CP | _PAGE_CV | _PAGE_P )
  12. #define VPTE_SHIFT (PAGE_SHIFT - 3)
  13. /* Ways we can get here:
  14. *
  15. * 1) Nucleus loads and stores to/from PA-->VA direct mappings at tl>1.
  16. * 2) Nucleus loads and stores to/from user/kernel window save areas.
  17. * 3) VPTE misses from dtlb_base and itlb_base.
  18. *
  19. * We need to extract out the PMD and PGDIR indexes from the
  20. * linear virtual page table access address. The PTE index
  21. * is at the bottom, but we are not concerned with it. Bits
  22. * 0 to 2 are clear since each PTE is 8 bytes in size. Each
  23. * PMD and PGDIR entry are 4 bytes in size. Thus, this
  24. * address looks something like:
  25. *
  26. * |---------------------------------------------------------------|
  27. * | ... | PGDIR index | PMD index | PTE index | |
  28. * |---------------------------------------------------------------|
  29. * 63 F E D C B A 3 2 0 <- bit nr
  30. *
  31. * The variable bits above are defined as:
  32. * A --> 3 + (PAGE_SHIFT - log2(8))
  33. * --> 3 + (PAGE_SHIFT - 3) - 1
  34. * (ie. this is "bit 3" + PAGE_SIZE - size of PTE entry in bits - 1)
  35. * B --> A + 1
  36. * C --> B + (PAGE_SHIFT - log2(4))
  37. * --> B + (PAGE_SHIFT - 2) - 1
  38. * (ie. this is "bit B" + PAGE_SIZE - size of PMD entry in bits - 1)
  39. * D --> C + 1
  40. * E --> D + (PAGE_SHIFT - log2(4))
  41. * --> D + (PAGE_SHIFT - 2) - 1
  42. * (ie. this is "bit D" + PAGE_SIZE - size of PGDIR entry in bits - 1)
  43. * F --> E + 1
  44. *
  45. * (Note how "B" always evalutes to PAGE_SHIFT, all the other constants
  46. * cancel out.)
  47. *
  48. * For 8K PAGE_SIZE (thus, PAGE_SHIFT of 13) the bit numbers are:
  49. * A --> 12
  50. * B --> 13
  51. * C --> 23
  52. * D --> 24
  53. * E --> 34
  54. * F --> 35
  55. *
  56. * For 64K PAGE_SIZE (thus, PAGE_SHIFT of 16) the bit numbers are:
  57. * A --> 15
  58. * B --> 16
  59. * C --> 29
  60. * D --> 30
  61. * E --> 43
  62. * F --> 44
  63. *
  64. * Because bits both above and below each PGDIR and PMD index need to
  65. * be masked out, and the index can be as long as 14 bits (when using a
  66. * 64K PAGE_SIZE, and thus a PAGE_SHIFT of 16), we need 3 instructions
  67. * to extract each index out.
  68. *
  69. * Shifts do not pair very well on UltraSPARC-I, II, IIi, and IIe, so
  70. * we try to avoid using them for the entire operation. We could setup
  71. * a mask anywhere from bit 31 down to bit 10 using the sethi instruction.
  72. *
  73. * We need a mask covering bits B --> C and one covering D --> E.
  74. * For 8K PAGE_SIZE these masks are 0x00ffe000 and 0x7ff000000.
  75. * For 64K PAGE_SIZE these masks are 0x3fff0000 and 0xfffc0000000.
  76. * The second in each set cannot be loaded with a single sethi
  77. * instruction, because the upper bits are past bit 32. We would
  78. * need to use a sethi + a shift.
  79. *
  80. * For the time being, we use 2 shifts and a simple "and" mask.
  81. * We shift left to clear the bits above the index, we shift down
  82. * to clear the bits below the index (sans the log2(4 or 8) bits)
  83. * and a mask to clear the log2(4 or 8) bits. We need therefore
  84. * define 4 shift counts, all of which are relative to PAGE_SHIFT.
  85. *
  86. * Although unsupportable for other reasons, this does mean that
  87. * 512K and 4MB page sizes would be generaally supported by the
  88. * kernel. (ELF binaries would break with > 64K PAGE_SIZE since
  89. * the sections are only aligned that strongly).
  90. *
  91. * The operations performed for extraction are thus:
  92. *
  93. * ((X << FOO_SHIFT_LEFT) >> FOO_SHIFT_RIGHT) & ~0x3
  94. *
  95. */
  96. #define A (3 + (PAGE_SHIFT - 3) - 1)
  97. #define B (A + 1)
  98. #define C (B + (PAGE_SHIFT - 2) - 1)
  99. #define D (C + 1)
  100. #define E (D + (PAGE_SHIFT - 2) - 1)
  101. #define F (E + 1)
  102. #define PMD_SHIFT_LEFT (64 - D)
  103. #define PMD_SHIFT_RIGHT (64 - (D - B) - 2)
  104. #define PGDIR_SHIFT_LEFT (64 - F)
  105. #define PGDIR_SHIFT_RIGHT (64 - (F - D) - 2)
  106. #define LOW_MASK_BITS 0x3
  107. /* TLB1 ** ICACHE line 1: tl1 DTLB and quick VPTE miss */
  108. ldxa [%g1 + %g1] ASI_DMMU, %g4 ! Get TAG_ACCESS
  109. add %g3, %g3, %g5 ! Compute VPTE base
  110. cmp %g4, %g5 ! VPTE miss?
  111. bgeu,pt %xcc, 1f ! Continue here
  112. andcc %g4, TAG_CONTEXT_BITS, %g5 ! tl0 miss Nucleus test
  113. ba,a,pt %xcc, from_tl1_trap ! Fall to tl0 miss
  114. 1: sllx %g6, VPTE_SHIFT, %g4 ! Position TAG_ACCESS
  115. or %g4, %g5, %g4 ! Prepare TAG_ACCESS
  116. /* TLB1 ** ICACHE line 2: Quick VPTE miss */
  117. mov TSB_REG, %g1 ! Grab TSB reg
  118. ldxa [%g1] ASI_DMMU, %g5 ! Doing PGD caching?
  119. sllx %g6, PMD_SHIFT_LEFT, %g1 ! Position PMD offset
  120. be,pn %xcc, sparc64_vpte_nucleus ! Is it from Nucleus?
  121. srlx %g1, PMD_SHIFT_RIGHT, %g1 ! Mask PMD offset bits
  122. brnz,pt %g5, sparc64_vpte_continue ! Yep, go like smoke
  123. andn %g1, LOW_MASK_BITS, %g1 ! Final PMD mask
  124. sllx %g6, PGDIR_SHIFT_LEFT, %g5 ! Position PGD offset
  125. /* TLB1 ** ICACHE line 3: Quick VPTE miss */
  126. srlx %g5, PGDIR_SHIFT_RIGHT, %g5 ! Mask PGD offset bits
  127. andn %g5, LOW_MASK_BITS, %g5 ! Final PGD mask
  128. lduwa [%g7 + %g5] ASI_PHYS_USE_EC, %g5! Load PGD
  129. brz,pn %g5, vpte_noent ! Valid?
  130. sparc64_kpte_continue:
  131. sllx %g5, 11, %g5 ! Shift into place
  132. sparc64_vpte_continue:
  133. lduwa [%g5 + %g1] ASI_PHYS_USE_EC, %g5! Load PMD
  134. sllx %g5, 11, %g5 ! Shift into place
  135. brz,pn %g5, vpte_noent ! Valid?
  136. /* TLB1 ** ICACHE line 4: Quick VPTE miss */
  137. mov (VALID_SZ_BITS >> 61), %g1 ! upper vpte into %g1
  138. sllx %g1, 61, %g1 ! finish calc
  139. or %g5, VPTE_BITS, %g5 ! Prepare VPTE data
  140. or %g5, %g1, %g5 ! ...
  141. mov TLB_SFSR, %g1 ! Restore %g1 value
  142. stxa %g5, [%g0] ASI_DTLB_DATA_IN ! Load VPTE into TLB
  143. stxa %g4, [%g1 + %g1] ASI_DMMU ! Restore previous TAG_ACCESS
  144. retry ! Load PTE once again
  145. #undef VALID_SZ_BITS
  146. #undef VPTE_SHIFT
  147. #undef VPTE_BITS
  148. #undef A
  149. #undef B
  150. #undef C
  151. #undef D
  152. #undef E
  153. #undef F
  154. #undef PMD_SHIFT_LEFT
  155. #undef PMD_SHIFT_RIGHT
  156. #undef PGDIR_SHIFT_LEFT
  157. #undef PGDIR_SHIFT_RIGHT
  158. #undef LOW_MASK_BITS