]> err.no Git - linux-2.6/blob - arch/sparc64/kernel/ktlb.S
[SPARC64]: Make use of Niagara 256MB PTEs for kernel mappings.
[linux-2.6] / arch / sparc64 / kernel / ktlb.S
1 /* 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)
7  */
8
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>
14 #include <asm/tsb.h>
15
16         .text
17         .align          32
18
19 kvmap_itlb:
20         /* g6: TAG TARGET */
21         mov             TLB_TAG_ACCESS, %g4
22         ldxa            [%g4] ASI_IMMU, %g4
23
24         /* sun4v_itlb_miss branches here with the missing virtual
25          * address already loaded into %g4
26          */
27 kvmap_itlb_4v:
28
29 kvmap_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
38 kvmap_itlb_tsb_miss:
39         sethi           %hi(LOW_OBP_ADDRESS), %g5
40         cmp             %g4, %g5
41         blu,pn          %xcc, kvmap_itlb_vmalloc_addr
42          mov            0x1, %g5
43         sllx            %g5, 32, %g5
44         cmp             %g4, %g5
45         blu,pn          %xcc, kvmap_itlb_obp
46          nop
47
48 kvmap_itlb_vmalloc_addr:
49         KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_itlb_longpath)
50
51         KTSB_LOCK_TAG(%g1, %g2, %g7)
52
53         /* Load and check PTE.  */
54         ldxa            [%g5] ASI_PHYS_USE_EC, %g5
55         mov             1, %g7
56         sllx            %g7, TSB_TAG_INVALID_BIT, %g7
57         brgez,a,pn      %g5, kvmap_itlb_longpath
58          KTSB_STORE(%g1, %g7)
59
60         KTSB_WRITE(%g1, %g5, %g6)
61
62         /* fallthrough to TLB load */
63
64 kvmap_itlb_load:
65
66 661:    stxa            %g5, [%g0] ASI_ITLB_DATA_IN
67         retry
68         .section        .sun4v_2insn_patch, "ax"
69         .word           661b
70         nop
71         nop
72         .previous
73
74         /* For sun4v the ASI_ITLB_DATA_IN store and the retry
75          * instruction get nop'd out and we get here to branch
76          * to the sun4v tlb load code.  The registers are setup
77          * as follows:
78          *
79          * %g4: vaddr
80          * %g5: PTE
81          * %g6: TAG
82          *
83          * The sun4v TLB load wants the PTE in %g3 so we fix that
84          * up here.
85          */
86         ba,pt           %xcc, sun4v_itlb_load
87          mov            %g5, %g3
88
89 kvmap_itlb_longpath:
90
91 661:    rdpr    %pstate, %g5
92         wrpr    %g5, PSTATE_AG | PSTATE_MG, %pstate
93         .section .sun4v_2insn_patch, "ax"
94         .word   661b
95         SET_GL(1)
96         nop
97         .previous
98
99         rdpr    %tpc, %g5
100         ba,pt   %xcc, sparc64_realfault_common
101          mov    FAULT_CODE_ITLB, %g4
102
103 kvmap_itlb_obp:
104         OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_itlb_longpath)
105
106         KTSB_LOCK_TAG(%g1, %g2, %g7)
107
108         KTSB_WRITE(%g1, %g5, %g6)
109
110         ba,pt           %xcc, kvmap_itlb_load
111          nop
112
113 kvmap_dtlb_obp:
114         OBP_TRANS_LOOKUP(%g4, %g5, %g2, %g3, kvmap_dtlb_longpath)
115
116         KTSB_LOCK_TAG(%g1, %g2, %g7)
117
118         KTSB_WRITE(%g1, %g5, %g6)
119
120         ba,pt           %xcc, kvmap_dtlb_load
121          nop
122
123         .align          32
124 kvmap_dtlb:
125         /* %g6: TAG TARGET */
126         mov             TLB_TAG_ACCESS, %g4
127         ldxa            [%g4] ASI_DMMU, %g4
128
129         /* sun4v_dtlb_miss branches here with the missing virtual
130          * address already loaded into %g4
131          */
132 kvmap_dtlb_4v:
133         brgez,pn        %g4, kvmap_dtlb_nonlinear
134          nop
135
136         sethi           %hi(kpte_linear_bitmap), %g2
137         or              %g2, %lo(kpte_linear_bitmap), %g2
138
139         /* Clear the PAGE_OFFSET top virtual bits, then shift
140          * down to get a 256MB physical address index.
141          */
142         sllx            %g4, 21, %g5
143         mov             1, %g7
144         srlx            %g5, 21 + 28, %g5
145
146         /* Don't try this at home kids... this depends upon srlx
147          * only taking the low 6 bits of the shift count in %g5.
148          */
149         sllx            %g7, %g5, %g7
150
151         /* Divide by 64 to get the offset into the bitmask.  */
152         srlx            %g5, 6, %g5
153
154         /* kern_linear_pte_xor[((mask & bit) ? 1 : 0)] */
155         ldx             [%g2 + %g5], %g2
156         andcc           %g2, %g7, %g0
157         sethi           %hi(kern_linear_pte_xor), %g5
158         or              %g5, %lo(kern_linear_pte_xor), %g5
159         bne,a,pt        %xcc, 1f
160          add            %g5, 8, %g5
161
162 1:      ldx             [%g5], %g2
163
164         .globl          kvmap_linear_patch
165 kvmap_linear_patch:
166         ba,pt           %xcc, kvmap_dtlb_load
167          xor            %g2, %g4, %g5
168
169 kvmap_dtlb_vmalloc_addr:
170         KERN_PGTABLE_WALK(%g4, %g5, %g2, kvmap_dtlb_longpath)
171
172         KTSB_LOCK_TAG(%g1, %g2, %g7)
173
174         /* Load and check PTE.  */
175         ldxa            [%g5] ASI_PHYS_USE_EC, %g5
176         mov             1, %g7
177         sllx            %g7, TSB_TAG_INVALID_BIT, %g7
178         brgez,a,pn      %g5, kvmap_dtlb_longpath
179          KTSB_STORE(%g1, %g7)
180
181         KTSB_WRITE(%g1, %g5, %g6)
182
183         /* fallthrough to TLB load */
184
185 kvmap_dtlb_load:
186
187 661:    stxa            %g5, [%g0] ASI_DTLB_DATA_IN     ! Reload TLB
188         retry
189         .section        .sun4v_2insn_patch, "ax"
190         .word           661b
191         nop
192         nop
193         .previous
194
195         /* For sun4v the ASI_DTLB_DATA_IN store and the retry
196          * instruction get nop'd out and we get here to branch
197          * to the sun4v tlb load code.  The registers are setup
198          * as follows:
199          *
200          * %g4: vaddr
201          * %g5: PTE
202          * %g6: TAG
203          *
204          * The sun4v TLB load wants the PTE in %g3 so we fix that
205          * up here.
206          */
207         ba,pt           %xcc, sun4v_dtlb_load
208          mov            %g5, %g3
209
210 kvmap_dtlb_nonlinear:
211         /* Catch kernel NULL pointer derefs.  */
212         sethi           %hi(PAGE_SIZE), %g5
213         cmp             %g4, %g5
214         bleu,pn         %xcc, kvmap_dtlb_longpath
215          nop
216
217         KERN_TSB_LOOKUP_TL1(%g4, %g6, %g5, %g1, %g2, %g3, kvmap_dtlb_load)
218
219 kvmap_dtlb_tsbmiss:
220         sethi           %hi(MODULES_VADDR), %g5
221         cmp             %g4, %g5
222         blu,pn          %xcc, kvmap_dtlb_longpath
223          mov            (VMALLOC_END >> 24), %g5
224         sllx            %g5, 24, %g5
225         cmp             %g4, %g5
226         bgeu,pn         %xcc, kvmap_dtlb_longpath
227          nop
228
229 kvmap_check_obp:
230         sethi           %hi(LOW_OBP_ADDRESS), %g5
231         cmp             %g4, %g5
232         blu,pn          %xcc, kvmap_dtlb_vmalloc_addr
233          mov            0x1, %g5
234         sllx            %g5, 32, %g5
235         cmp             %g4, %g5
236         blu,pn          %xcc, kvmap_dtlb_obp
237          nop
238         ba,pt           %xcc, kvmap_dtlb_vmalloc_addr
239          nop
240
241 kvmap_dtlb_longpath:
242
243 661:    rdpr    %pstate, %g5
244         wrpr    %g5, PSTATE_AG | PSTATE_MG, %pstate
245         .section .sun4v_2insn_patch, "ax"
246         .word   661b
247         SET_GL(1)
248         ldxa            [%g0] ASI_SCRATCHPAD, %g5
249         .previous
250
251         rdpr    %tl, %g3
252         cmp     %g3, 1
253
254 661:    mov     TLB_TAG_ACCESS, %g4
255         ldxa    [%g4] ASI_DMMU, %g5
256         .section .sun4v_2insn_patch, "ax"
257         .word   661b
258         ldx     [%g5 + HV_FAULT_D_ADDR_OFFSET], %g5
259         nop
260         .previous
261
262         be,pt   %xcc, sparc64_realfault_common
263          mov    FAULT_CODE_DTLB, %g4
264         ba,pt   %xcc, winfix_trampoline
265          nop