David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 1 | /* arch/sparc64/kernel/ktlb.S: Kernel mapping TLB miss handling. |
| 2 | * |
David S. Miller | bf4a797 | 2008-01-10 21:10:54 -0800 | [diff] [blame] | 3 | * Copyright (C) 1995, 1997, 2005, 2008 David S. Miller <davem@davemloft.net> |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 4 | * Copyright (C) 1996 Eddie C. Dost (ecd@brainaid.de) |
| 5 | * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx) |
| 6 | * Copyright (C) 1996,98,99 Jakub Jelinek (jj@sunsite.mff.cuni.cz) |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 7 | */ |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 8 | |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 9 | #include <asm/head.h> |
| 10 | #include <asm/asi.h> |
| 11 | #include <asm/page.h> |
| 12 | #include <asm/pgtable.h> |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 13 | #include <asm/tsb.h> |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 14 | |
| 15 | .text |
| 16 | .align 32 |
| 17 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 18 | kvmap_itlb: |
| 19 | /* g6: TAG TARGET */ |
| 20 | mov TLB_TAG_ACCESS, %g4 |
| 21 | ldxa [%g4] ASI_IMMU, %g4 |
| 22 | |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame] | 23 | /* sun4v_itlb_miss branches here with the missing virtual |
| 24 | * address already loaded into %g4 |
| 25 | */ |
| 26 | kvmap_itlb_4v: |
| 27 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 28 | /* Catch kernel NULL pointer calls. */ |
| 29 | sethi %hi(PAGE_SIZE), %g5 |
| 30 | cmp %g4, %g5 |
Kirill Tkhai | 1c2696c | 2013-08-02 19:23:18 +0400 | [diff] [blame] | 31 | blu,pn %xcc, kvmap_itlb_longpath |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 32 | nop |
| 33 | |
| 34 | KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_itlb_load) |
| 35 | |
| 36 | kvmap_itlb_tsb_miss: |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 37 | sethi %hi(LOW_OBP_ADDRESS), %g5 |
| 38 | cmp %g4, %g5 |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 39 | blu,pn %xcc, kvmap_itlb_vmalloc_addr |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 40 | mov 0x1, %g5 |
| 41 | sllx %g5, 32, %g5 |
| 42 | cmp %g4, %g5 |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 43 | blu,pn %xcc, kvmap_itlb_obp |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 44 | nop |
| 45 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 46 | kvmap_itlb_vmalloc_addr: |
| 47 | KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_itlb_longpath) |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 48 | |
David S. Miller | 9076d0e | 2011-08-05 00:53:57 -0700 | [diff] [blame] | 49 | TSB_LOCK_TAG(%g1, %g2, %g7) |
David S. Miller | 9076d0e | 2011-08-05 00:53:57 -0700 | [diff] [blame] | 50 | TSB_WRITE(%g1, %g5, %g6) |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 51 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 52 | /* fallthrough to TLB load */ |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 53 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 54 | kvmap_itlb_load: |
David S. Miller | 459b6e6 | 2006-02-11 12:21:20 -0800 | [diff] [blame] | 55 | |
| 56 | 661: stxa %g5, [%g0] ASI_ITLB_DATA_IN |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 57 | retry |
David S. Miller | 459b6e6 | 2006-02-11 12:21:20 -0800 | [diff] [blame] | 58 | .section .sun4v_2insn_patch, "ax" |
| 59 | .word 661b |
| 60 | nop |
| 61 | nop |
| 62 | .previous |
| 63 | |
| 64 | /* For sun4v the ASI_ITLB_DATA_IN store and the retry |
| 65 | * instruction get nop'd out and we get here to branch |
| 66 | * to the sun4v tlb load code. The registers are setup |
| 67 | * as follows: |
| 68 | * |
| 69 | * %g4: vaddr |
| 70 | * %g5: PTE |
| 71 | * %g6: TAG |
| 72 | * |
| 73 | * The sun4v TLB load wants the PTE in %g3 so we fix that |
| 74 | * up here. |
| 75 | */ |
| 76 | ba,pt %xcc, sun4v_itlb_load |
| 77 | mov %g5, %g3 |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 78 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 79 | kvmap_itlb_longpath: |
David S. Miller | 45fec05 | 2006-02-05 22:27:28 -0800 | [diff] [blame] | 80 | |
| 81 | 661: rdpr %pstate, %g5 |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 82 | wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate |
David S. Miller | df7d6ae | 2006-02-07 00:00:16 -0800 | [diff] [blame] | 83 | .section .sun4v_2insn_patch, "ax" |
David S. Miller | 45fec05 | 2006-02-05 22:27:28 -0800 | [diff] [blame] | 84 | .word 661b |
David S. Miller | 6cc200d | 2006-02-18 16:36:39 -0800 | [diff] [blame] | 85 | SET_GL(1) |
David S. Miller | 45fec05 | 2006-02-05 22:27:28 -0800 | [diff] [blame] | 86 | nop |
| 87 | .previous |
| 88 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 89 | rdpr %tpc, %g5 |
| 90 | ba,pt %xcc, sparc64_realfault_common |
| 91 | mov FAULT_CODE_ITLB, %g4 |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 92 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 93 | kvmap_itlb_obp: |
| 94 | OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_itlb_longpath) |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 95 | |
David S. Miller | 9076d0e | 2011-08-05 00:53:57 -0700 | [diff] [blame] | 96 | TSB_LOCK_TAG(%g1, %g2, %g7) |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 97 | |
David S. Miller | 9076d0e | 2011-08-05 00:53:57 -0700 | [diff] [blame] | 98 | TSB_WRITE(%g1, %g5, %g6) |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 99 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 100 | ba,pt %xcc, kvmap_itlb_load |
| 101 | nop |
David S. Miller | c9c1083 | 2005-10-12 12:22:46 -0700 | [diff] [blame] | 102 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 103 | kvmap_dtlb_obp: |
| 104 | OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_dtlb_longpath) |
| 105 | |
David S. Miller | 9076d0e | 2011-08-05 00:53:57 -0700 | [diff] [blame] | 106 | TSB_LOCK_TAG(%g1, %g2, %g7) |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 107 | |
David S. Miller | 9076d0e | 2011-08-05 00:53:57 -0700 | [diff] [blame] | 108 | TSB_WRITE(%g1, %g5, %g6) |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 109 | |
| 110 | ba,pt %xcc, kvmap_dtlb_load |
| 111 | nop |
| 112 | |
David S. Miller | 0dd5b7b | 2014-09-24 20:56:11 -0700 | [diff] [blame] | 113 | kvmap_linear_early: |
| 114 | sethi %hi(kern_linear_pte_xor), %g7 |
| 115 | ldx [%g7 + %lo(kern_linear_pte_xor)], %g2 |
| 116 | ba,pt %xcc, kvmap_dtlb_tsb4m_load |
| 117 | xor %g2, %g4, %g5 |
| 118 | |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 119 | .align 32 |
David S. Miller | d7744a0 | 2006-02-21 22:31:11 -0800 | [diff] [blame] | 120 | kvmap_dtlb_tsb4m_load: |
David S. Miller | 9076d0e | 2011-08-05 00:53:57 -0700 | [diff] [blame] | 121 | TSB_LOCK_TAG(%g1, %g2, %g7) |
| 122 | TSB_WRITE(%g1, %g5, %g6) |
David S. Miller | d7744a0 | 2006-02-21 22:31:11 -0800 | [diff] [blame] | 123 | ba,pt %xcc, kvmap_dtlb_load |
| 124 | nop |
| 125 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 126 | kvmap_dtlb: |
| 127 | /* %g6: TAG TARGET */ |
| 128 | mov TLB_TAG_ACCESS, %g4 |
| 129 | ldxa [%g4] ASI_DMMU, %g4 |
David S. Miller | d257d5d | 2006-02-06 23:44:37 -0800 | [diff] [blame] | 130 | |
| 131 | /* sun4v_dtlb_miss branches here with the missing virtual |
| 132 | * address already loaded into %g4 |
| 133 | */ |
| 134 | kvmap_dtlb_4v: |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 135 | brgez,pn %g4, kvmap_dtlb_nonlinear |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 136 | nop |
| 137 | |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 138 | #ifdef CONFIG_DEBUG_PAGEALLOC |
| 139 | /* Index through the base page size TSB even for linear |
| 140 | * mappings when using page allocation debugging. |
| 141 | */ |
| 142 | KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load) |
| 143 | #else |
David S. Miller | d7744a0 | 2006-02-21 22:31:11 -0800 | [diff] [blame] | 144 | /* Correct TAG_TARGET is already in %g6, check 4mb TSB. */ |
| 145 | KERN_TSB4M_LOOKUP_TL1(%g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load) |
David S. Miller | d1acb42 | 2007-03-16 17:20:28 -0700 | [diff] [blame] | 146 | #endif |
David S. Miller | 0dd5b7b | 2014-09-24 20:56:11 -0700 | [diff] [blame] | 147 | /* Linear mapping TSB lookup failed. Fallthrough to kernel |
| 148 | * page table based lookup. |
David S. Miller | d7744a0 | 2006-02-21 22:31:11 -0800 | [diff] [blame] | 149 | */ |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 150 | .globl kvmap_linear_patch |
| 151 | kvmap_linear_patch: |
David S. Miller | 0dd5b7b | 2014-09-24 20:56:11 -0700 | [diff] [blame] | 152 | ba,a,pt %xcc, kvmap_linear_early |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 153 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 154 | kvmap_dtlb_vmalloc_addr: |
| 155 | KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath) |
David S. Miller | 5642530 | 2005-09-25 16:46:57 -0700 | [diff] [blame] | 156 | |
David S. Miller | 9076d0e | 2011-08-05 00:53:57 -0700 | [diff] [blame] | 157 | TSB_LOCK_TAG(%g1, %g2, %g7) |
David S. Miller | 9076d0e | 2011-08-05 00:53:57 -0700 | [diff] [blame] | 158 | TSB_WRITE(%g1, %g5, %g6) |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 159 | |
| 160 | /* fallthrough to TLB load */ |
| 161 | |
| 162 | kvmap_dtlb_load: |
David S. Miller | 459b6e6 | 2006-02-11 12:21:20 -0800 | [diff] [blame] | 163 | |
| 164 | 661: stxa %g5, [%g0] ASI_DTLB_DATA_IN ! Reload TLB |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 165 | retry |
David S. Miller | 459b6e6 | 2006-02-11 12:21:20 -0800 | [diff] [blame] | 166 | .section .sun4v_2insn_patch, "ax" |
| 167 | .word 661b |
| 168 | nop |
| 169 | nop |
| 170 | .previous |
| 171 | |
| 172 | /* For sun4v the ASI_DTLB_DATA_IN store and the retry |
| 173 | * instruction get nop'd out and we get here to branch |
| 174 | * to the sun4v tlb load code. The registers are setup |
| 175 | * as follows: |
| 176 | * |
| 177 | * %g4: vaddr |
| 178 | * %g5: PTE |
| 179 | * %g6: TAG |
| 180 | * |
| 181 | * The sun4v TLB load wants the PTE in %g3 so we fix that |
| 182 | * up here. |
| 183 | */ |
| 184 | ba,pt %xcc, sun4v_dtlb_load |
| 185 | mov %g5, %g3 |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 186 | |
David S. Miller | bf4a797 | 2008-01-10 21:10:54 -0800 | [diff] [blame] | 187 | #ifdef CONFIG_SPARSEMEM_VMEMMAP |
David Miller | 46644c2 | 2007-10-16 01:24:16 -0700 | [diff] [blame] | 188 | kvmap_vmemmap: |
David S. Miller | c06240c | 2014-09-24 21:20:14 -0700 | [diff] [blame^] | 189 | KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath) |
| 190 | ba,a,pt %xcc, kvmap_dtlb_load |
David S. Miller | bf4a797 | 2008-01-10 21:10:54 -0800 | [diff] [blame] | 191 | #endif |
David Miller | 46644c2 | 2007-10-16 01:24:16 -0700 | [diff] [blame] | 192 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 193 | kvmap_dtlb_nonlinear: |
| 194 | /* Catch kernel NULL pointer derefs. */ |
| 195 | sethi %hi(PAGE_SIZE), %g5 |
| 196 | cmp %g4, %g5 |
| 197 | bleu,pn %xcc, kvmap_dtlb_longpath |
| 198 | nop |
| 199 | |
David S. Miller | bf4a797 | 2008-01-10 21:10:54 -0800 | [diff] [blame] | 200 | #ifdef CONFIG_SPARSEMEM_VMEMMAP |
David Miller | 46644c2 | 2007-10-16 01:24:16 -0700 | [diff] [blame] | 201 | /* Do not use the TSB for vmemmap. */ |
David S. Miller | 1b6b9d6 | 2009-09-28 14:39:58 -0700 | [diff] [blame] | 202 | mov (VMEMMAP_BASE >> 40), %g5 |
| 203 | sllx %g5, 40, %g5 |
David Miller | 46644c2 | 2007-10-16 01:24:16 -0700 | [diff] [blame] | 204 | cmp %g4,%g5 |
| 205 | bgeu,pn %xcc, kvmap_vmemmap |
| 206 | nop |
David S. Miller | bf4a797 | 2008-01-10 21:10:54 -0800 | [diff] [blame] | 207 | #endif |
David Miller | 46644c2 | 2007-10-16 01:24:16 -0700 | [diff] [blame] | 208 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 209 | KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load) |
| 210 | |
| 211 | kvmap_dtlb_tsbmiss: |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 212 | sethi %hi(MODULES_VADDR), %g5 |
| 213 | cmp %g4, %g5 |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 214 | blu,pn %xcc, kvmap_dtlb_longpath |
David S. Miller | 1b6b9d6 | 2009-09-28 14:39:58 -0700 | [diff] [blame] | 215 | mov (VMALLOC_END >> 40), %g5 |
| 216 | sllx %g5, 40, %g5 |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 217 | cmp %g4, %g5 |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 218 | bgeu,pn %xcc, kvmap_dtlb_longpath |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 219 | nop |
| 220 | |
| 221 | kvmap_check_obp: |
| 222 | sethi %hi(LOW_OBP_ADDRESS), %g5 |
| 223 | cmp %g4, %g5 |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 224 | blu,pn %xcc, kvmap_dtlb_vmalloc_addr |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 225 | mov 0x1, %g5 |
| 226 | sllx %g5, 32, %g5 |
| 227 | cmp %g4, %g5 |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 228 | blu,pn %xcc, kvmap_dtlb_obp |
| 229 | nop |
| 230 | ba,pt %xcc, kvmap_dtlb_vmalloc_addr |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 231 | nop |
| 232 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 233 | kvmap_dtlb_longpath: |
David S. Miller | 45fec05 | 2006-02-05 22:27:28 -0800 | [diff] [blame] | 234 | |
| 235 | 661: rdpr %pstate, %g5 |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 236 | wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate |
David S. Miller | df7d6ae | 2006-02-07 00:00:16 -0800 | [diff] [blame] | 237 | .section .sun4v_2insn_patch, "ax" |
David S. Miller | 45fec05 | 2006-02-05 22:27:28 -0800 | [diff] [blame] | 238 | .word 661b |
David S. Miller | 8b23427 | 2006-02-17 18:01:02 -0800 | [diff] [blame] | 239 | SET_GL(1) |
| 240 | ldxa [%g0] ASI_SCRATCHPAD, %g5 |
David S. Miller | 45fec05 | 2006-02-05 22:27:28 -0800 | [diff] [blame] | 241 | .previous |
| 242 | |
David S. Miller | 459b6e6 | 2006-02-11 12:21:20 -0800 | [diff] [blame] | 243 | rdpr %tl, %g3 |
| 244 | cmp %g3, 1 |
| 245 | |
| 246 | 661: mov TLB_TAG_ACCESS, %g4 |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 247 | ldxa [%g4] ASI_DMMU, %g5 |
David S. Miller | 459b6e6 | 2006-02-11 12:21:20 -0800 | [diff] [blame] | 248 | .section .sun4v_2insn_patch, "ax" |
| 249 | .word 661b |
David S. Miller | 8b23427 | 2006-02-17 18:01:02 -0800 | [diff] [blame] | 250 | ldx [%g5 + HV_FAULT_D_ADDR_OFFSET], %g5 |
David S. Miller | 459b6e6 | 2006-02-11 12:21:20 -0800 | [diff] [blame] | 251 | nop |
| 252 | .previous |
| 253 | |
David S. Miller | 74bf431 | 2006-01-31 18:29:18 -0800 | [diff] [blame] | 254 | be,pt %xcc, sparc64_realfault_common |
| 255 | mov FAULT_CODE_DTLB, %g4 |
| 256 | ba,pt %xcc, winfix_trampoline |
David S. Miller | 2a7e299 | 2005-09-21 18:50:51 -0700 | [diff] [blame] | 257 | nop |