blob: f6bb2e08964a2f8e1a9b22050ec4e370707281ed [file] [log] [blame]
David S. Miller2a7e2992005-09-21 18:50:51 -07001/* arch/sparc64/kernel/ktlb.S: Kernel mapping TLB miss handling.
2 *
3 * Copyright (C) 1995, 1997, 2005 David S. Miller <davem@davemloft.net>
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. Miller74bf4312006-01-31 18:29:18 -08007 */
David S. Miller2a7e2992005-09-21 18:50:51 -07008
9#include <linux/config.h>
10#include <asm/head.h>
11#include <asm/asi.h>
12#include <asm/page.h>
13#include <asm/pgtable.h>
David S. Miller74bf4312006-01-31 18:29:18 -080014#include <asm/tsb.h>
David S. Miller2a7e2992005-09-21 18:50:51 -070015
16 .text
17 .align 32
18
David S. Miller74bf4312006-01-31 18:29:18 -080019kvmap_itlb:
20 /* g6: TAG TARGET */
21 mov TLB_TAG_ACCESS, %g4
22 ldxa [%g4] ASI_IMMU, %g4
23
David S. Millerd257d5d2006-02-06 23:44:37 -080024 /* sun4v_itlb_miss branches here with the missing virtual
25 * address already loaded into %g4
26 */
27kvmap_itlb_4v:
28
David S. Miller74bf4312006-01-31 18:29:18 -080029kvmap_itlb_nonlinear:
30 /* Catch kernel NULL pointer calls. */
31 sethi %hi(PAGE_SIZE), %g5
32 cmp %g4, %g5
33 bleu,pn %xcc, kvmap_dtlb_longpath
34 nop
35
36 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_itlb_load)
37
38kvmap_itlb_tsb_miss:
David S. Miller2a7e2992005-09-21 18:50:51 -070039 sethi %hi(LOW_OBP_ADDRESS), %g5
40 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -080041 blu,pn %xcc, kvmap_itlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -070042 mov 0x1, %g5
43 sllx %g5, 32, %g5
44 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -080045 blu,pn %xcc, kvmap_itlb_obp
David S. Miller2a7e2992005-09-21 18:50:51 -070046 nop
47
David S. Miller74bf4312006-01-31 18:29:18 -080048kvmap_itlb_vmalloc_addr:
49 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_itlb_longpath)
David S. Miller2a7e2992005-09-21 18:50:51 -070050
David S. Miller517af332006-02-01 15:55:21 -080051 KTSB_LOCK_TAG(%g1, %g2, %g4)
David S. Miller2a7e2992005-09-21 18:50:51 -070052
David S. Miller74bf4312006-01-31 18:29:18 -080053 /* Load and check PTE. */
54 ldxa [%g5] ASI_PHYS_USE_EC, %g5
55 brgez,a,pn %g5, kvmap_itlb_longpath
David S. Miller517af332006-02-01 15:55:21 -080056 KTSB_STORE(%g1, %g0)
David S. Miller2a7e2992005-09-21 18:50:51 -070057
David S. Miller517af332006-02-01 15:55:21 -080058 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller2a7e2992005-09-21 18:50:51 -070059
David S. Miller74bf4312006-01-31 18:29:18 -080060 /* fallthrough to TLB load */
David S. Miller2a7e2992005-09-21 18:50:51 -070061
David S. Miller74bf4312006-01-31 18:29:18 -080062kvmap_itlb_load:
63 stxa %g5, [%g0] ASI_ITLB_DATA_IN ! Reload TLB
David S. Miller2a7e2992005-09-21 18:50:51 -070064 retry
65
David S. Miller74bf4312006-01-31 18:29:18 -080066kvmap_itlb_longpath:
David S. Miller45fec052006-02-05 22:27:28 -080067
68661: rdpr %pstate, %g5
David S. Miller74bf4312006-01-31 18:29:18 -080069 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
David S. Millerdf7d6ae2006-02-07 00:00:16 -080070 .section .sun4v_2insn_patch, "ax"
David S. Miller45fec052006-02-05 22:27:28 -080071 .word 661b
72 nop
73 nop
74 .previous
75
David S. Miller74bf4312006-01-31 18:29:18 -080076 rdpr %tpc, %g5
77 ba,pt %xcc, sparc64_realfault_common
78 mov FAULT_CODE_ITLB, %g4
David S. Millerc9c10832005-10-12 12:22:46 -070079
David S. Miller74bf4312006-01-31 18:29:18 -080080kvmap_itlb_obp:
81 OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_itlb_longpath)
David S. Miller2a7e2992005-09-21 18:50:51 -070082
David S. Miller517af332006-02-01 15:55:21 -080083 KTSB_LOCK_TAG(%g1, %g2, %g4)
David S. Miller2a7e2992005-09-21 18:50:51 -070084
David S. Miller517af332006-02-01 15:55:21 -080085 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller2a7e2992005-09-21 18:50:51 -070086
David S. Miller74bf4312006-01-31 18:29:18 -080087 ba,pt %xcc, kvmap_itlb_load
88 nop
David S. Millerc9c10832005-10-12 12:22:46 -070089
David S. Miller74bf4312006-01-31 18:29:18 -080090kvmap_dtlb_obp:
91 OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_dtlb_longpath)
92
David S. Miller517af332006-02-01 15:55:21 -080093 KTSB_LOCK_TAG(%g1, %g2, %g4)
David S. Miller74bf4312006-01-31 18:29:18 -080094
David S. Miller517af332006-02-01 15:55:21 -080095 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller74bf4312006-01-31 18:29:18 -080096
97 ba,pt %xcc, kvmap_dtlb_load
98 nop
99
David S. Miller2a7e2992005-09-21 18:50:51 -0700100 .align 32
David S. Miller74bf4312006-01-31 18:29:18 -0800101kvmap_dtlb:
102 /* %g6: TAG TARGET */
103 mov TLB_TAG_ACCESS, %g4
104 ldxa [%g4] ASI_DMMU, %g4
David S. Millerd257d5d2006-02-06 23:44:37 -0800105
106 /* sun4v_dtlb_miss branches here with the missing virtual
107 * address already loaded into %g4
108 */
109kvmap_dtlb_4v:
David S. Miller74bf4312006-01-31 18:29:18 -0800110 brgez,pn %g4, kvmap_dtlb_nonlinear
David S. Miller56425302005-09-25 16:46:57 -0700111 nop
112
David S. Miller74bf4312006-01-31 18:29:18 -0800113#define KERN_HIGHBITS ((_PAGE_VALID|_PAGE_SZ4MB)^0xfffff80000000000)
114#define KERN_LOWBITS (_PAGE_CP | _PAGE_CV | _PAGE_P | _PAGE_W)
115
116 sethi %uhi(KERN_HIGHBITS), %g2
117 or %g2, %ulo(KERN_HIGHBITS), %g2
118 sllx %g2, 32, %g2
119 or %g2, KERN_LOWBITS, %g2
120
121#undef KERN_HIGHBITS
122#undef KERN_LOWBITS
123
David S. Miller56425302005-09-25 16:46:57 -0700124 .globl kvmap_linear_patch
125kvmap_linear_patch:
David S. Miller74bf4312006-01-31 18:29:18 -0800126 ba,pt %xcc, kvmap_dtlb_load
David S. Miller2a7e2992005-09-21 18:50:51 -0700127 xor %g2, %g4, %g5
128
David S. Miller74bf4312006-01-31 18:29:18 -0800129kvmap_dtlb_vmalloc_addr:
130 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
David S. Miller56425302005-09-25 16:46:57 -0700131
David S. Miller517af332006-02-01 15:55:21 -0800132 KTSB_LOCK_TAG(%g1, %g2, %g4)
David S. Miller74bf4312006-01-31 18:29:18 -0800133
134 /* Load and check PTE. */
135 ldxa [%g5] ASI_PHYS_USE_EC, %g5
136 brgez,a,pn %g5, kvmap_dtlb_longpath
David S. Miller517af332006-02-01 15:55:21 -0800137 KTSB_STORE(%g1, %g0)
David S. Miller74bf4312006-01-31 18:29:18 -0800138
David S. Miller517af332006-02-01 15:55:21 -0800139 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller74bf4312006-01-31 18:29:18 -0800140
141 /* fallthrough to TLB load */
142
143kvmap_dtlb_load:
144 stxa %g5, [%g0] ASI_DTLB_DATA_IN ! Reload TLB
145 retry
146
147kvmap_dtlb_nonlinear:
148 /* Catch kernel NULL pointer derefs. */
149 sethi %hi(PAGE_SIZE), %g5
150 cmp %g4, %g5
151 bleu,pn %xcc, kvmap_dtlb_longpath
152 nop
153
154 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
155
156kvmap_dtlb_tsbmiss:
David S. Miller2a7e2992005-09-21 18:50:51 -0700157 sethi %hi(MODULES_VADDR), %g5
158 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800159 blu,pn %xcc, kvmap_dtlb_longpath
David S. Miller2a7e2992005-09-21 18:50:51 -0700160 mov (VMALLOC_END >> 24), %g5
161 sllx %g5, 24, %g5
162 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800163 bgeu,pn %xcc, kvmap_dtlb_longpath
David S. Miller2a7e2992005-09-21 18:50:51 -0700164 nop
165
166kvmap_check_obp:
167 sethi %hi(LOW_OBP_ADDRESS), %g5
168 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800169 blu,pn %xcc, kvmap_dtlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -0700170 mov 0x1, %g5
171 sllx %g5, 32, %g5
172 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800173 blu,pn %xcc, kvmap_dtlb_obp
174 nop
175 ba,pt %xcc, kvmap_dtlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -0700176 nop
177
David S. Miller74bf4312006-01-31 18:29:18 -0800178kvmap_dtlb_longpath:
David S. Miller45fec052006-02-05 22:27:28 -0800179
180661: rdpr %pstate, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800181 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800182 .section .sun4v_2insn_patch, "ax"
David S. Miller45fec052006-02-05 22:27:28 -0800183 .word 661b
184 nop
185 nop
186 .previous
187
David S. Miller74bf4312006-01-31 18:29:18 -0800188 rdpr %tl, %g4
189 cmp %g4, 1
190 mov TLB_TAG_ACCESS, %g4
191 ldxa [%g4] ASI_DMMU, %g5
192 be,pt %xcc, sparc64_realfault_common
193 mov FAULT_CODE_DTLB, %g4
194 ba,pt %xcc, winfix_trampoline
David S. Miller2a7e2992005-09-21 18:50:51 -0700195 nop