David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 1 | /* tsb.S: Sparc64 TSB table handling. |
| 2 | * |
| 3 | * Copyright (C) 2006 David S. Miller <davem@davemloft.net> |
| 4 | */ |
| 5 | |
| 6 | #include <asm/tsb.h> |
| 7 | |
| 8 | .text |
| 9 | .align 32 |
| 10 | |
| 11 | /* Invoked from TLB miss handler, we are in the |
| 12 | * MMU global registers and they are setup like |
| 13 | * this: |
| 14 | * |
| 15 | * %g1: TSB entry pointer |
| 16 | * %g2: available temporary |
| 17 | * %g3: FAULT_CODE_{D,I}TLB |
| 18 | * %g4: available temporary |
| 19 | * %g5: available temporary |
| 20 | * %g6: TAG TARGET |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame^] | 21 | * %g7: available temporary, will be loaded by us with |
| 22 | * the physical address base of the linux page |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 23 | * tables for the current address space |
| 24 | */ |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 25 | tsb_miss_dtlb: |
| 26 | mov TLB_TAG_ACCESS, %g4 |
| 27 | ldxa [%g4] ASI_DMMU, %g4 |
| 28 | ba,pt %xcc, tsb_miss_page_table_walk |
| 29 | nop |
| 30 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 31 | tsb_miss_itlb: |
| 32 | mov TLB_TAG_ACCESS, %g4 |
| 33 | ldxa [%g4] ASI_IMMU, %g4 |
| 34 | ba,pt %xcc, tsb_miss_page_table_walk |
| 35 | nop |
| 36 | |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame^] | 37 | /* The sun4v TLB miss handlers jump directly here instead |
| 38 | * of tsb_miss_{d,i}tlb with the missing virtual address |
| 39 | * already loaded into %g4. |
| 40 | */ |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 41 | tsb_miss_page_table_walk: |
David S. Miller | ffe483d | 2006-02-02 21:55:10 -0800 | [diff] [blame] | 42 | TRAP_LOAD_PGD_PHYS(%g7, %g5) |
David S. Miller | 56fb4df | 2006-02-26 23:24:22 -0800 | [diff] [blame] | 43 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 44 | USER_PGTABLE_WALK_TL1(%g4, %g7, %g5, %g2, tsb_do_fault) |
| 45 | |
| 46 | tsb_reload: |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame^] | 47 | TSB_LOCK_TAG(%g1, %g2, %g7) |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 48 | |
| 49 | /* Load and check PTE. */ |
| 50 | ldxa [%g5] ASI_PHYS_USE_EC, %g5 |
| 51 | brgez,a,pn %g5, tsb_do_fault |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 52 | TSB_STORE(%g1, %g0) |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 53 | |
David S. Miller | 09f9428 | 2006-01-31 18:31:06 -0800 | [diff] [blame] | 54 | /* If it is larger than the base page size, don't |
| 55 | * bother putting it into the TSB. |
| 56 | */ |
| 57 | srlx %g5, 32, %g2 |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame^] | 58 | sethi %hi(_PAGE_ALL_SZ_BITS >> 32), %g7 |
| 59 | and %g2, %g7, %g2 |
David S. Miller | 09f9428 | 2006-01-31 18:31:06 -0800 | [diff] [blame] | 60 | sethi %hi(_PAGE_SZBITS >> 32), %g7 |
David S. Miller | 09f9428 | 2006-01-31 18:31:06 -0800 | [diff] [blame] | 61 | cmp %g2, %g7 |
| 62 | bne,a,pn %xcc, tsb_tlb_reload |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 63 | TSB_STORE(%g1, %g0) |
David S. Miller | 09f9428 | 2006-01-31 18:31:06 -0800 | [diff] [blame] | 64 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 65 | TSB_WRITE(%g1, %g5, %g6) |
| 66 | |
| 67 | /* Finally, load TLB and return from trap. */ |
| 68 | tsb_tlb_reload: |
| 69 | cmp %g3, FAULT_CODE_DTLB |
| 70 | bne,pn %xcc, tsb_itlb_load |
| 71 | nop |
| 72 | |
| 73 | tsb_dtlb_load: |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame^] | 74 | |
| 75 | 661: stxa %g5, [%g0] ASI_DTLB_DATA_IN |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 76 | retry |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame^] | 77 | .section .gl_2insn_patch, "ax" |
| 78 | .word 661b |
| 79 | nop |
| 80 | nop |
| 81 | .previous |
| 82 | |
| 83 | /* For sun4v the ASI_DTLB_DATA_IN store and the retry |
| 84 | * instruction get nop'd out and we get here to branch |
| 85 | * to the sun4v tlb load code. The registers are setup |
| 86 | * as follows: |
| 87 | * |
| 88 | * %g4: vaddr |
| 89 | * %g5: PTE |
| 90 | * %g6: TAG |
| 91 | * |
| 92 | * The sun4v TLB load wants the PTE in %g3 so we fix that |
| 93 | * up here. |
| 94 | */ |
| 95 | ba,pt %xcc, sun4v_dtlb_load |
| 96 | mov %g5, %g3 |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 97 | |
| 98 | tsb_itlb_load: |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame^] | 99 | |
| 100 | 661: stxa %g5, [%g0] ASI_ITLB_DATA_IN |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 101 | retry |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame^] | 102 | .section .gl_2insn_patch, "ax" |
| 103 | .word 661b |
| 104 | nop |
| 105 | nop |
| 106 | .previous |
| 107 | |
| 108 | /* For sun4v the ASI_ITLB_DATA_IN store and the retry |
| 109 | * instruction get nop'd out and we get here to branch |
| 110 | * to the sun4v tlb load code. The registers are setup |
| 111 | * as follows: |
| 112 | * |
| 113 | * %g4: vaddr |
| 114 | * %g5: PTE |
| 115 | * %g6: TAG |
| 116 | * |
| 117 | * The sun4v TLB load wants the PTE in %g3 so we fix that |
| 118 | * up here. |
| 119 | */ |
| 120 | ba,pt %xcc, sun4v_itlb_load |
| 121 | mov %g5, %g3 |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 122 | |
| 123 | /* No valid entry in the page tables, do full fault |
| 124 | * processing. |
| 125 | */ |
| 126 | |
| 127 | .globl tsb_do_fault |
| 128 | tsb_do_fault: |
| 129 | cmp %g3, FAULT_CODE_DTLB |
David S. Miller | 45fec05 | 2006-02-05 22:27:28 -0800 | [diff] [blame] | 130 | |
| 131 | 661: rdpr %pstate, %g5 |
| 132 | wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate |
| 133 | .section .gl_2insn_patch, "ax" |
| 134 | .word 661b |
| 135 | nop |
| 136 | nop |
| 137 | .previous |
| 138 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 139 | bne,pn %xcc, tsb_do_itlb_fault |
David S. Miller | 45fec05 | 2006-02-05 22:27:28 -0800 | [diff] [blame] | 140 | nop |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 141 | |
| 142 | tsb_do_dtlb_fault: |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame^] | 143 | rdpr %tl, %g3 |
| 144 | cmp %g3, 1 |
| 145 | |
| 146 | 661: mov TLB_TAG_ACCESS, %g4 |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 147 | ldxa [%g4] ASI_DMMU, %g5 |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame^] | 148 | .section .gl_2insn_patch, "ax" |
| 149 | .word 661b |
| 150 | mov %g4, %g5 |
| 151 | nop |
| 152 | .previous |
| 153 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 154 | be,pt %xcc, sparc64_realfault_common |
| 155 | mov FAULT_CODE_DTLB, %g4 |
| 156 | ba,pt %xcc, winfix_trampoline |
| 157 | nop |
| 158 | |
| 159 | tsb_do_itlb_fault: |
| 160 | rdpr %tpc, %g5 |
| 161 | ba,pt %xcc, sparc64_realfault_common |
| 162 | mov FAULT_CODE_ITLB, %g4 |
| 163 | |
| 164 | .globl sparc64_realfault_common |
| 165 | sparc64_realfault_common: |
David S. Miller | 9bc657b | 2006-01-31 18:34:21 -0800 | [diff] [blame] | 166 | /* fault code in %g4, fault address in %g5, etrap will |
| 167 | * preserve these two values in %l4 and %l5 respectively |
| 168 | */ |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 169 | ba,pt %xcc, etrap ! Save trap state |
| 170 | 1: rd %pc, %g7 ! ... |
David S. Miller | 9bc657b | 2006-01-31 18:34:21 -0800 | [diff] [blame] | 171 | stb %l4, [%g6 + TI_FAULT_CODE] ! Save fault code |
| 172 | stx %l5, [%g6 + TI_FAULT_ADDR] ! Save fault address |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 173 | call do_sparc64_fault ! Call fault handler |
| 174 | add %sp, PTREGS_OFF, %o0 ! Compute pt_regs arg |
| 175 | ba,pt %xcc, rtrap_clr_l6 ! Restore cpu state |
| 176 | nop ! Delay slot (fill me) |
| 177 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 178 | winfix_trampoline: |
| 179 | rdpr %tpc, %g3 ! Prepare winfixup TNPC |
| 180 | or %g3, 0x7c, %g3 ! Compute branch offset |
| 181 | wrpr %g3, %tnpc ! Write it into TNPC |
| 182 | done ! Trap return |
| 183 | |
David S. Miller | b70c0fa | 2006-01-31 18:32:04 -0800 | [diff] [blame] | 184 | /* Insert an entry into the TSB. |
| 185 | * |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 186 | * %o0: TSB entry pointer (virt or phys address) |
David S. Miller | b70c0fa | 2006-01-31 18:32:04 -0800 | [diff] [blame] | 187 | * %o1: tag |
| 188 | * %o2: pte |
| 189 | */ |
| 190 | .align 32 |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 191 | .globl __tsb_insert |
| 192 | __tsb_insert: |
David S. Miller | b70c0fa | 2006-01-31 18:32:04 -0800 | [diff] [blame] | 193 | rdpr %pstate, %o5 |
| 194 | wrpr %o5, PSTATE_IE, %pstate |
| 195 | TSB_LOCK_TAG(%o0, %g2, %g3) |
| 196 | TSB_WRITE(%o0, %o2, %o1) |
| 197 | wrpr %o5, %pstate |
| 198 | retl |
| 199 | nop |
| 200 | |
David S. Miller | 517af33 | 2006-02-01 15:55:21 -0800 | [diff] [blame] | 201 | /* Flush the given TSB entry if it has the matching |
| 202 | * tag. |
| 203 | * |
| 204 | * %o0: TSB entry pointer (virt or phys address) |
| 205 | * %o1: tag |
| 206 | */ |
| 207 | .align 32 |
| 208 | .globl tsb_flush |
| 209 | tsb_flush: |
| 210 | sethi %hi(TSB_TAG_LOCK_HIGH), %g2 |
| 211 | 1: TSB_LOAD_TAG(%o0, %g1) |
| 212 | srlx %g1, 32, %o3 |
| 213 | andcc %o3, %g2, %g0 |
| 214 | bne,pn %icc, 1b |
| 215 | membar #LoadLoad |
| 216 | cmp %g1, %o1 |
| 217 | bne,pt %xcc, 2f |
| 218 | clr %o3 |
| 219 | TSB_CAS_TAG(%o0, %g1, %o3) |
| 220 | cmp %g1, %o3 |
| 221 | bne,pn %xcc, 1b |
| 222 | nop |
| 223 | 2: retl |
| 224 | TSB_MEMBAR |
| 225 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 226 | /* Reload MMU related context switch state at |
| 227 | * schedule() time. |
| 228 | * |
| 229 | * %o0: page table physical address |
David S. Miller | 98c5584 | 2006-01-31 18:31:20 -0800 | [diff] [blame] | 230 | * %o1: TSB register value |
| 231 | * %o2: TSB virtual address |
| 232 | * %o3: TSB mapping locked PTE |
| 233 | * |
| 234 | * We have to run this whole thing with interrupts |
| 235 | * disabled so that the current cpu doesn't change |
| 236 | * due to preemption. |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 237 | */ |
David S. Miller | 56fb4df | 2006-02-26 23:24:22 -0800 | [diff] [blame] | 238 | .align 32 |
David S. Miller | 98c5584 | 2006-01-31 18:31:20 -0800 | [diff] [blame] | 239 | .globl __tsb_context_switch |
| 240 | __tsb_context_switch: |
David S. Miller | 56fb4df | 2006-02-26 23:24:22 -0800 | [diff] [blame] | 241 | rdpr %pstate, %o5 |
| 242 | wrpr %o5, PSTATE_IE, %pstate |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 243 | |
David S. Miller | 98c5584 | 2006-01-31 18:31:20 -0800 | [diff] [blame] | 244 | ldub [%g6 + TI_CPU], %g1 |
| 245 | sethi %hi(trap_block), %g2 |
| 246 | sllx %g1, TRAP_BLOCK_SZ_SHIFT, %g1 |
| 247 | or %g2, %lo(trap_block), %g2 |
| 248 | add %g2, %g1, %g2 |
| 249 | stx %o0, [%g2 + TRAP_PER_CPU_PGD_PADDR] |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 250 | |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame^] | 251 | 661: mov TSB_REG, %g1 |
David S. Miller | 98c5584 | 2006-01-31 18:31:20 -0800 | [diff] [blame] | 252 | stxa %o1, [%g1] ASI_DMMU |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame^] | 253 | .section .gl_2insn_patch, "ax" |
| 254 | .word 661b |
| 255 | mov SCRATCHPAD_UTSBREG1, %g1 |
| 256 | stxa %o1, [%g1] ASI_SCRATCHPAD |
| 257 | .previous |
| 258 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 259 | membar #Sync |
| 260 | |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame^] | 261 | 661: stxa %o1, [%g1] ASI_IMMU |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 262 | membar #Sync |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame^] | 263 | .section .gl_2insn_patch, "ax" |
| 264 | .word 661b |
| 265 | nop |
| 266 | nop |
| 267 | .previous |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 268 | |
David S. Miller | 98c5584 | 2006-01-31 18:31:20 -0800 | [diff] [blame] | 269 | brz %o2, 9f |
| 270 | nop |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 271 | |
David S. Miller | 6b6d017 | 2006-01-31 18:33:12 -0800 | [diff] [blame] | 272 | sethi %hi(sparc64_highest_unlocked_tlb_ent), %o4 |
| 273 | mov TLB_TAG_ACCESS, %g1 |
| 274 | lduw [%o4 + %lo(sparc64_highest_unlocked_tlb_ent)], %g2 |
| 275 | stxa %o2, [%g1] ASI_DMMU |
| 276 | membar #Sync |
| 277 | sllx %g2, 3, %g2 |
| 278 | stxa %o3, [%g2] ASI_DTLB_DATA_ACCESS |
| 279 | membar #Sync |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 280 | 9: |
David S. Miller | 56fb4df | 2006-02-26 23:24:22 -0800 | [diff] [blame] | 281 | wrpr %o5, %pstate |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 282 | |
| 283 | retl |
David S. Miller | 98c5584 | 2006-01-31 18:31:20 -0800 | [diff] [blame] | 284 | nop |