blob: 9b415ab6db6b0e09fb85bf59a221a7f163b6f4f1 [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:
63 rdpr %pstate, %g5
64 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
65 rdpr %tpc, %g5
66 ba,pt %xcc, sparc64_realfault_common
67 mov FAULT_CODE_ITLB, %g4
David S. Millerc9c10832005-10-12 12:22:46 -070068
David S. Miller74bf4312006-01-31 18:29:18 -080069kvmap_itlb_obp:
70 OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_itlb_longpath)
David S. Miller2a7e2992005-09-21 18:50:51 -070071
David S. Miller517af332006-02-01 15:55:21 -080072 KTSB_LOCK_TAG(%g1, %g2, %g4)
David S. Miller2a7e2992005-09-21 18:50:51 -070073
David S. Miller517af332006-02-01 15:55:21 -080074 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller2a7e2992005-09-21 18:50:51 -070075
David S. Miller74bf4312006-01-31 18:29:18 -080076 ba,pt %xcc, kvmap_itlb_load
77 nop
David S. Millerc9c10832005-10-12 12:22:46 -070078
David S. Miller74bf4312006-01-31 18:29:18 -080079kvmap_dtlb_obp:
80 OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_dtlb_longpath)
81
David S. Miller517af332006-02-01 15:55:21 -080082 KTSB_LOCK_TAG(%g1, %g2, %g4)
David S. Miller74bf4312006-01-31 18:29:18 -080083
David S. Miller517af332006-02-01 15:55:21 -080084 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller74bf4312006-01-31 18:29:18 -080085
86 ba,pt %xcc, kvmap_dtlb_load
87 nop
88
David S. Miller2a7e2992005-09-21 18:50:51 -070089 .align 32
David S. Miller74bf4312006-01-31 18:29:18 -080090 .globl kvmap_dtlb
91kvmap_dtlb:
92 /* %g6: TAG TARGET */
93 mov TLB_TAG_ACCESS, %g4
94 ldxa [%g4] ASI_DMMU, %g4
95 brgez,pn %g4, kvmap_dtlb_nonlinear
David S. Miller56425302005-09-25 16:46:57 -070096 nop
97
David S. Miller74bf4312006-01-31 18:29:18 -080098#define KERN_HIGHBITS ((_PAGE_VALID|_PAGE_SZ4MB)^0xfffff80000000000)
99#define KERN_LOWBITS (_PAGE_CP | _PAGE_CV | _PAGE_P | _PAGE_W)
100
101 sethi %uhi(KERN_HIGHBITS), %g2
102 or %g2, %ulo(KERN_HIGHBITS), %g2
103 sllx %g2, 32, %g2
104 or %g2, KERN_LOWBITS, %g2
105
106#undef KERN_HIGHBITS
107#undef KERN_LOWBITS
108
David S. Miller56425302005-09-25 16:46:57 -0700109 .globl kvmap_linear_patch
110kvmap_linear_patch:
David S. Miller74bf4312006-01-31 18:29:18 -0800111 ba,pt %xcc, kvmap_dtlb_load
David S. Miller2a7e2992005-09-21 18:50:51 -0700112 xor %g2, %g4, %g5
113
David S. Miller74bf4312006-01-31 18:29:18 -0800114kvmap_dtlb_vmalloc_addr:
115 KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
David S. Miller56425302005-09-25 16:46:57 -0700116
David S. Miller517af332006-02-01 15:55:21 -0800117 KTSB_LOCK_TAG(%g1, %g2, %g4)
David S. Miller74bf4312006-01-31 18:29:18 -0800118
119 /* Load and check PTE. */
120 ldxa [%g5] ASI_PHYS_USE_EC, %g5
121 brgez,a,pn %g5, kvmap_dtlb_longpath
David S. Miller517af332006-02-01 15:55:21 -0800122 KTSB_STORE(%g1, %g0)
David S. Miller74bf4312006-01-31 18:29:18 -0800123
David S. Miller517af332006-02-01 15:55:21 -0800124 KTSB_WRITE(%g1, %g5, %g6)
David S. Miller74bf4312006-01-31 18:29:18 -0800125
126 /* fallthrough to TLB load */
127
128kvmap_dtlb_load:
129 stxa %g5, [%g0] ASI_DTLB_DATA_IN ! Reload TLB
130 retry
131
132kvmap_dtlb_nonlinear:
133 /* Catch kernel NULL pointer derefs. */
134 sethi %hi(PAGE_SIZE), %g5
135 cmp %g4, %g5
136 bleu,pn %xcc, kvmap_dtlb_longpath
137 nop
138
139 KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
140
141kvmap_dtlb_tsbmiss:
David S. Miller2a7e2992005-09-21 18:50:51 -0700142 sethi %hi(MODULES_VADDR), %g5
143 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800144 blu,pn %xcc, kvmap_dtlb_longpath
David S. Miller2a7e2992005-09-21 18:50:51 -0700145 mov (VMALLOC_END >> 24), %g5
146 sllx %g5, 24, %g5
147 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800148 bgeu,pn %xcc, kvmap_dtlb_longpath
David S. Miller2a7e2992005-09-21 18:50:51 -0700149 nop
150
151kvmap_check_obp:
152 sethi %hi(LOW_OBP_ADDRESS), %g5
153 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800154 blu,pn %xcc, kvmap_dtlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -0700155 mov 0x1, %g5
156 sllx %g5, 32, %g5
157 cmp %g4, %g5
David S. Miller74bf4312006-01-31 18:29:18 -0800158 blu,pn %xcc, kvmap_dtlb_obp
159 nop
160 ba,pt %xcc, kvmap_dtlb_vmalloc_addr
David S. Miller2a7e2992005-09-21 18:50:51 -0700161 nop
162
David S. Miller74bf4312006-01-31 18:29:18 -0800163kvmap_dtlb_longpath:
164 rdpr %pstate, %g5
165 wrpr %g5, PSTATE_AG | PSTATE_MG, %pstate
166 rdpr %tl, %g4
167 cmp %g4, 1
168 mov TLB_TAG_ACCESS, %g4
169 ldxa [%g4] ASI_DMMU, %g5
170 be,pt %xcc, sparc64_realfault_common
171 mov FAULT_CODE_DTLB, %g4
172 ba,pt %xcc, winfix_trampoline
David S. Miller2a7e2992005-09-21 18:50:51 -0700173 nop