blob: c1335432124e3b4e1002a26b0714a2312cddff11 [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 -080019 .globl kvmap_itlb
20kvmap_itlb:
21 /* g6: TAG TARGET */
22 mov TLB_TAG_ACCESS, %g4
23 ldxa [%g4] ASI_IMMU, %g4
24
25kvmap_itlb_nonlinear:
26 /* Catch kernel NULL pointer calls. */
27 sethi %hi(PAGE_SIZE), %g5
28 cmp %g4, %g5
29 bleu,pn %xcc, kvmap_dtlb_longpath
30 nop
31
32 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_itlb_load)
33
34kvmap_itlb_tsb_miss:
David S. Miller2a7e2992005-09-21 18:50:51 -070035 sethi %hi(LOW_OBP_ADDRESS), %g5
36 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -080037 blu,pn %xcc, kvmap_itlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -070038 mov 0x1, %g5
39 sllx %g5, 32, %g5
40 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -080041 blu,pn %xcc, kvmap_itlb_obp
David S. Miller2a7e2992005-09-21 18:50:51 -070042 nop
43
David S. Miller74bf4312006-01-31 18:29:18 -080044kvmap_itlb_vmalloc_addr:
45 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_itlb_longpath)
David S. Miller2a7e2992005-09-21 18:50:51 -070046
David S. Miller517af332006-02-01 15:55:21 -080047 KTSB_LOCK_TAG(%g1, %g2, %g4)
David S. Miller2a7e2992005-09-21 18:50:51 -070048
David S. Miller74bf4312006-01-31 18:29:18 -080049 /* Load and check PTE. */
50 ldxa [%g5] ASI_PHYS_USE_EC, %g5
51 brgez,a,pn %g5, kvmap_itlb_longpath
David S. Miller517af332006-02-01 15:55:21 -080052 KTSB_STORE(%g1, %g0)
David S. Miller2a7e2992005-09-21 18:50:51 -070053
David S. Miller517af332006-02-01 15:55:21 -080054 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller2a7e2992005-09-21 18:50:51 -070055
David S. Miller74bf4312006-01-31 18:29:18 -080056 /* fallthrough to TLB load */
David S. Miller2a7e2992005-09-21 18:50:51 -070057
David S. Miller74bf4312006-01-31 18:29:18 -080058kvmap_itlb_load:
59 stxa %g5, [%g0] ASI_ITLB_DATA_IN ! Reload TLB
David S. Miller2a7e2992005-09-21 18:50:51 -070060 retry
61
David S. Miller74bf4312006-01-31 18:29:18 -080062kvmap_itlb_longpath:
David S. Miller45fec052006-02-05 22:27:28 -080063
64661: rdpr %pstate, %g5
David S. Miller74bf4312006-01-31 18:29:18 -080065 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
David S. Miller45fec052006-02-05 22:27:28 -080066 .section .gl_2insn_patch, "ax"
67 .word 661b
68 nop
69 nop
70 .previous
71
David S. Miller74bf4312006-01-31 18:29:18 -080072 rdpr %tpc, %g5
73 ba,pt %xcc, sparc64_realfault_common
74 mov FAULT_CODE_ITLB, %g4
David S. Millerc9c10832005-10-12 12:22:46 -070075
David S. Miller74bf4312006-01-31 18:29:18 -080076kvmap_itlb_obp:
77 OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_itlb_longpath)
David S. Miller2a7e2992005-09-21 18:50:51 -070078
David S. Miller517af332006-02-01 15:55:21 -080079 KTSB_LOCK_TAG(%g1, %g2, %g4)
David S. Miller2a7e2992005-09-21 18:50:51 -070080
David S. Miller517af332006-02-01 15:55:21 -080081 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller2a7e2992005-09-21 18:50:51 -070082
David S. Miller74bf4312006-01-31 18:29:18 -080083 ba,pt %xcc, kvmap_itlb_load
84 nop
David S. Millerc9c10832005-10-12 12:22:46 -070085
David S. Miller74bf4312006-01-31 18:29:18 -080086kvmap_dtlb_obp:
87 OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_dtlb_longpath)
88
David S. Miller517af332006-02-01 15:55:21 -080089 KTSB_LOCK_TAG(%g1, %g2, %g4)
David S. Miller74bf4312006-01-31 18:29:18 -080090
David S. Miller517af332006-02-01 15:55:21 -080091 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller74bf4312006-01-31 18:29:18 -080092
93 ba,pt %xcc, kvmap_dtlb_load
94 nop
95
David S. Miller2a7e2992005-09-21 18:50:51 -070096 .align 32
David S. Miller74bf4312006-01-31 18:29:18 -080097 .globl kvmap_dtlb
98kvmap_dtlb:
99 /* %g6: TAG TARGET */
100 mov TLB_TAG_ACCESS, %g4
101 ldxa [%g4] ASI_DMMU, %g4
102 brgez,pn %g4, kvmap_dtlb_nonlinear
David S. Miller56425302005-09-25 16:46:57 -0700103 nop
104
David S. Miller74bf4312006-01-31 18:29:18 -0800105#define KERN_HIGHBITS ((_PAGE_VALID|_PAGE_SZ4MB)^0xfffff80000000000)
106#define KERN_LOWBITS (_PAGE_CP | _PAGE_CV | _PAGE_P | _PAGE_W)
107
108 sethi %uhi(KERN_HIGHBITS), %g2
109 or %g2, %ulo(KERN_HIGHBITS), %g2
110 sllx %g2, 32, %g2
111 or %g2, KERN_LOWBITS, %g2
112
113#undef KERN_HIGHBITS
114#undef KERN_LOWBITS
115
David S. Miller56425302005-09-25 16:46:57 -0700116 .globl kvmap_linear_patch
117kvmap_linear_patch:
David S. Miller74bf4312006-01-31 18:29:18 -0800118 ba,pt %xcc, kvmap_dtlb_load
David S. Miller2a7e2992005-09-21 18:50:51 -0700119 xor %g2, %g4, %g5
120
David S. Miller74bf4312006-01-31 18:29:18 -0800121kvmap_dtlb_vmalloc_addr:
122 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
David S. Miller56425302005-09-25 16:46:57 -0700123
David S. Miller517af332006-02-01 15:55:21 -0800124 KTSB_LOCK_TAG(%g1, %g2, %g4)
David S. Miller74bf4312006-01-31 18:29:18 -0800125
126 /* Load and check PTE. */
127 ldxa [%g5] ASI_PHYS_USE_EC, %g5
128 brgez,a,pn %g5, kvmap_dtlb_longpath
David S. Miller517af332006-02-01 15:55:21 -0800129 KTSB_STORE(%g1, %g0)
David S. Miller74bf4312006-01-31 18:29:18 -0800130
David S. Miller517af332006-02-01 15:55:21 -0800131 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller74bf4312006-01-31 18:29:18 -0800132
133 /* fallthrough to TLB load */
134
135kvmap_dtlb_load:
136 stxa %g5, [%g0] ASI_DTLB_DATA_IN ! Reload TLB
137 retry
138
139kvmap_dtlb_nonlinear:
140 /* Catch kernel NULL pointer derefs. */
141 sethi %hi(PAGE_SIZE), %g5
142 cmp %g4, %g5
143 bleu,pn %xcc, kvmap_dtlb_longpath
144 nop
145
146 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
147
148kvmap_dtlb_tsbmiss:
David S. Miller2a7e2992005-09-21 18:50:51 -0700149 sethi %hi(MODULES_VADDR), %g5
150 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800151 blu,pn %xcc, kvmap_dtlb_longpath
David S. Miller2a7e2992005-09-21 18:50:51 -0700152 mov (VMALLOC_END >> 24), %g5
153 sllx %g5, 24, %g5
154 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800155 bgeu,pn %xcc, kvmap_dtlb_longpath
David S. Miller2a7e2992005-09-21 18:50:51 -0700156 nop
157
158kvmap_check_obp:
159 sethi %hi(LOW_OBP_ADDRESS), %g5
160 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800161 blu,pn %xcc, kvmap_dtlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -0700162 mov 0x1, %g5
163 sllx %g5, 32, %g5
164 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800165 blu,pn %xcc, kvmap_dtlb_obp
166 nop
167 ba,pt %xcc, kvmap_dtlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -0700168 nop
169
David S. Miller74bf4312006-01-31 18:29:18 -0800170kvmap_dtlb_longpath:
David S. Miller45fec052006-02-05 22:27:28 -0800171
172661: rdpr %pstate, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800173 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
David S. Miller45fec052006-02-05 22:27:28 -0800174 .section .gl_2insn_patch, "ax"
175 .word 661b
176 nop
177 nop
178 .previous
179
David S. Miller74bf4312006-01-31 18:29:18 -0800180 rdpr %tl, %g4
181 cmp %g4, 1
182 mov TLB_TAG_ACCESS, %g4
183 ldxa [%g4] ASI_DMMU, %g5
184 be,pt %xcc, sparc64_realfault_common
185 mov FAULT_CODE_DTLB, %g4
186 ba,pt %xcc, winfix_trampoline
David S. Miller2a7e2992005-09-21 18:50:51 -0700187 nop