1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* sun4v_ivec.S: Sun4v interrupt vector handling.
4 * Copyright (C) 2006 <davem@davemloft.net>
7 #include <asm/cpudata.h>
8 #include <asm/intr_queue.h>
15 /* Head offset in %g2, tail offset in %g4.
16 * If they are the same, no work.
18 mov INTRQ_CPU_MONDO_HEAD, %g2
19 ldxa [%g2] ASI_QUEUE, %g2
20 mov INTRQ_CPU_MONDO_TAIL, %g4
21 ldxa [%g4] ASI_QUEUE, %g4
23 be,pn %xcc, sun4v_cpu_mondo_queue_empty
26 /* Get &trap_block[smp_processor_id()] into %g4. */
27 ldxa [%g0] ASI_SCRATCHPAD, %g4
28 sub %g4, TRAP_PER_CPU_FAULT_INFO, %g4
30 /* Get smp_processor_id() into %g3 */
31 sethi %hi(trap_block), %g5
32 or %g5, %lo(trap_block), %g5
34 srlx %g3, TRAP_BLOCK_SZ_SHIFT, %g3
36 /* Increment cpu_mondo_counter[smp_processor_id()] */
37 sethi %hi(cpu_mondo_counter), %g5
38 or %g5, %lo(cpu_mondo_counter), %g5
45 /* Get CPU mondo queue base phys address into %g7. */
46 ldx [%g4 + TRAP_PER_CPU_CPU_MONDO_PA], %g7
48 /* Now get the cross-call arguments and handler PC, same
51 * 1st 64-bit word: low half is 32-bit PC, put into %g3 and jmpl to it
52 * high half is context arg to MMU flushes, into %g5
53 * 2nd 64-bit word: 64-bit arg, load into %g1
54 * 3rd 64-bit word: 64-bit arg, load into %g7
56 ldxa [%g7 + %g2] ASI_PHYS_USE_EC, %g3
59 ldxa [%g7 + %g2] ASI_PHYS_USE_EC, %g1
62 ldxa [%g7 + %g2] ASI_PHYS_USE_EC, %g7
63 add %g2, 0x40 - 0x8 - 0x8, %g2
65 /* Update queue head pointer. */
66 lduw [%g4 + TRAP_PER_CPU_CPU_MONDO_QMASK], %g4
69 mov INTRQ_CPU_MONDO_HEAD, %g4
70 stxa %g2, [%g4] ASI_QUEUE
76 sun4v_cpu_mondo_queue_empty:
80 /* Head offset in %g2, tail offset in %g4. */
81 mov INTRQ_DEVICE_MONDO_HEAD, %g2
82 ldxa [%g2] ASI_QUEUE, %g2
83 mov INTRQ_DEVICE_MONDO_TAIL, %g4
84 ldxa [%g4] ASI_QUEUE, %g4
86 be,pn %xcc, sun4v_dev_mondo_queue_empty
89 /* Get &trap_block[smp_processor_id()] into %g4. */
90 ldxa [%g0] ASI_SCRATCHPAD, %g4
91 sub %g4, TRAP_PER_CPU_FAULT_INFO, %g4
93 /* Get DEV mondo queue base phys address into %g5. */
94 ldx [%g4 + TRAP_PER_CPU_DEV_MONDO_PA], %g5
96 /* Load IVEC into %g3. */
97 ldxa [%g5 + %g2] ASI_PHYS_USE_EC, %g3
100 /* XXX There can be a full 64-byte block of data here.
101 * XXX This is how we can get at MSI vector data.
102 * XXX Current we do not capture this, but when we do we'll
103 * XXX need to add a 64-byte storage area in the struct ino_bucket
104 * XXX or the struct irq_desc.
107 /* Update queue head pointer, this frees up some registers. */
108 lduw [%g4 + TRAP_PER_CPU_DEV_MONDO_QMASK], %g4
111 mov INTRQ_DEVICE_MONDO_HEAD, %g4
112 stxa %g2, [%g4] ASI_QUEUE
115 TRAP_LOAD_IRQ_WORK_PA(%g1, %g4)
117 /* For VIRQs, cookie is encoded as ~bucket_phys_addr */
121 /* Get __pa(&ivector_table[IVEC]) into %g4. */
122 sethi %hi(ivector_table_pa), %g4
123 ldx [%g4 + %lo(ivector_table_pa)], %g4
128 stxa %g2, [%g4] ASI_PHYS_USE_EC
131 /* Signal the interrupt by setting (1 << pil) in %softint. */
132 wr %g0, 1 << PIL_DEVICE_IRQ, %set_softint
134 sun4v_dev_mondo_queue_empty:
138 /* Head offset in %g2, tail offset in %g4. */
139 mov INTRQ_RESUM_MONDO_HEAD, %g2
140 ldxa [%g2] ASI_QUEUE, %g2
141 mov INTRQ_RESUM_MONDO_TAIL, %g4
142 ldxa [%g4] ASI_QUEUE, %g4
144 be,pn %xcc, sun4v_res_mondo_queue_empty
147 /* Get &trap_block[smp_processor_id()] into %g3. */
148 ldxa [%g0] ASI_SCRATCHPAD, %g3
149 sub %g3, TRAP_PER_CPU_FAULT_INFO, %g3
151 /* Get RES mondo queue base phys address into %g5. */
152 ldx [%g3 + TRAP_PER_CPU_RESUM_MONDO_PA], %g5
154 /* Get RES kernel buffer base phys address into %g7. */
155 ldx [%g3 + TRAP_PER_CPU_RESUM_KBUF_PA], %g7
157 /* If the first word is non-zero, queue is full. */
158 ldxa [%g7 + %g2] ASI_PHYS_USE_EC, %g1
159 brnz,pn %g1, sun4v_res_mondo_queue_full
162 lduw [%g3 + TRAP_PER_CPU_RESUM_QMASK], %g4
164 /* Remember this entry's offset in %g1. */
167 /* Copy 64-byte queue entry into kernel buffer. */
168 ldxa [%g5 + %g2] ASI_PHYS_USE_EC, %g3
169 stxa %g3, [%g7 + %g2] ASI_PHYS_USE_EC
171 ldxa [%g5 + %g2] ASI_PHYS_USE_EC, %g3
172 stxa %g3, [%g7 + %g2] ASI_PHYS_USE_EC
174 ldxa [%g5 + %g2] ASI_PHYS_USE_EC, %g3
175 stxa %g3, [%g7 + %g2] ASI_PHYS_USE_EC
177 ldxa [%g5 + %g2] ASI_PHYS_USE_EC, %g3
178 stxa %g3, [%g7 + %g2] ASI_PHYS_USE_EC
180 ldxa [%g5 + %g2] ASI_PHYS_USE_EC, %g3
181 stxa %g3, [%g7 + %g2] ASI_PHYS_USE_EC
183 ldxa [%g5 + %g2] ASI_PHYS_USE_EC, %g3
184 stxa %g3, [%g7 + %g2] ASI_PHYS_USE_EC
186 ldxa [%g5 + %g2] ASI_PHYS_USE_EC, %g3
187 stxa %g3, [%g7 + %g2] ASI_PHYS_USE_EC
189 ldxa [%g5 + %g2] ASI_PHYS_USE_EC, %g3
190 stxa %g3, [%g7 + %g2] ASI_PHYS_USE_EC
193 /* Update queue head pointer. */
196 mov INTRQ_RESUM_MONDO_HEAD, %g4
197 stxa %g2, [%g4] ASI_QUEUE
200 /* Disable interrupts and save register state so we can call
201 * C code. The etrap handling will leave %g4 in %l4 for us
205 wrpr %g0, PIL_NORMAL_MAX, %pil
207 ba,pt %xcc, etrap_irq
209 #ifdef CONFIG_TRACE_IRQFLAGS
210 call trace_hardirqs_off
214 add %sp, PTREGS_OFF, %o0
215 call sun4v_resum_error
218 /* Return from trap. */
219 ba,pt %xcc, rtrap_irq
222 sun4v_res_mondo_queue_empty:
225 sun4v_res_mondo_queue_full:
226 /* The queue is full, consolidate our damage by setting
227 * the head equal to the tail. We'll just trap again otherwise.
228 * Call C code to log the event.
230 mov INTRQ_RESUM_MONDO_HEAD, %g2
231 stxa %g4, [%g2] ASI_QUEUE
235 wrpr %g0, PIL_NORMAL_MAX, %pil
236 ba,pt %xcc, etrap_irq
238 #ifdef CONFIG_TRACE_IRQFLAGS
239 call trace_hardirqs_off
242 call sun4v_resum_overflow
243 add %sp, PTREGS_OFF, %o0
245 ba,pt %xcc, rtrap_irq
249 /* Head offset in %g2, tail offset in %g4. */
250 mov INTRQ_NONRESUM_MONDO_HEAD, %g2
251 ldxa [%g2] ASI_QUEUE, %g2
252 mov INTRQ_NONRESUM_MONDO_TAIL, %g4
253 ldxa [%g4] ASI_QUEUE, %g4
255 be,pn %xcc, sun4v_nonres_mondo_queue_empty
258 /* Get &trap_block[smp_processor_id()] into %g3. */
259 ldxa [%g0] ASI_SCRATCHPAD, %g3
260 sub %g3, TRAP_PER_CPU_FAULT_INFO, %g3
262 /* Get RES mondo queue base phys address into %g5. */
263 ldx [%g3 + TRAP_PER_CPU_NONRESUM_MONDO_PA], %g5
265 /* Get RES kernel buffer base phys address into %g7. */
266 ldx [%g3 + TRAP_PER_CPU_NONRESUM_KBUF_PA], %g7
268 /* If the first word is non-zero, queue is full. */
269 ldxa [%g7 + %g2] ASI_PHYS_USE_EC, %g1
270 brnz,pn %g1, sun4v_nonres_mondo_queue_full
273 lduw [%g3 + TRAP_PER_CPU_NONRESUM_QMASK], %g4
275 /* Remember this entry's offset in %g1. */
278 /* Copy 64-byte queue entry into kernel buffer. */
279 ldxa [%g5 + %g2] ASI_PHYS_USE_EC, %g3
280 stxa %g3, [%g7 + %g2] ASI_PHYS_USE_EC
282 ldxa [%g5 + %g2] ASI_PHYS_USE_EC, %g3
283 stxa %g3, [%g7 + %g2] ASI_PHYS_USE_EC
285 ldxa [%g5 + %g2] ASI_PHYS_USE_EC, %g3
286 stxa %g3, [%g7 + %g2] ASI_PHYS_USE_EC
288 ldxa [%g5 + %g2] ASI_PHYS_USE_EC, %g3
289 stxa %g3, [%g7 + %g2] ASI_PHYS_USE_EC
291 ldxa [%g5 + %g2] ASI_PHYS_USE_EC, %g3
292 stxa %g3, [%g7 + %g2] ASI_PHYS_USE_EC
294 ldxa [%g5 + %g2] ASI_PHYS_USE_EC, %g3
295 stxa %g3, [%g7 + %g2] ASI_PHYS_USE_EC
297 ldxa [%g5 + %g2] ASI_PHYS_USE_EC, %g3
298 stxa %g3, [%g7 + %g2] ASI_PHYS_USE_EC
300 ldxa [%g5 + %g2] ASI_PHYS_USE_EC, %g3
301 stxa %g3, [%g7 + %g2] ASI_PHYS_USE_EC
304 /* Update queue head pointer. */
307 mov INTRQ_NONRESUM_MONDO_HEAD, %g4
308 stxa %g2, [%g4] ASI_QUEUE
311 /* Disable interrupts and save register state so we can call
312 * C code. The etrap handling will leave %g4 in %l4 for us
316 wrpr %g0, PIL_NORMAL_MAX, %pil
318 ba,pt %xcc, etrap_irq
320 #ifdef CONFIG_TRACE_IRQFLAGS
321 call trace_hardirqs_off
325 add %sp, PTREGS_OFF, %o0
326 call sun4v_nonresum_error
329 /* Return from trap. */
330 ba,pt %xcc, rtrap_irq
333 sun4v_nonres_mondo_queue_empty:
336 sun4v_nonres_mondo_queue_full:
337 /* The queue is full, consolidate our damage by setting
338 * the head equal to the tail. We'll just trap again otherwise.
339 * Call C code to log the event.
341 mov INTRQ_NONRESUM_MONDO_HEAD, %g2
342 stxa %g4, [%g2] ASI_QUEUE
346 wrpr %g0, PIL_NORMAL_MAX, %pil
347 ba,pt %xcc, etrap_irq
349 #ifdef CONFIG_TRACE_IRQFLAGS
350 call trace_hardirqs_off
353 call sun4v_nonresum_overflow
354 add %sp, PTREGS_OFF, %o0
356 ba,pt %xcc, rtrap_irq