2 * Copyright (C) 2007 Ben Skeggs.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 #include "nouveau_drv.h"
30 #include "nouveau_ramht.h"
31 #include "nouveau_grctx.h"
32 #include "nouveau_dma.h"
33 #include "nouveau_vm.h"
34 #include "nouveau_ramht.h"
37 static int nv50_graph_register(struct drm_device
*);
38 static void nv50_graph_isr(struct drm_device
*);
41 nv50_graph_init_reset(struct drm_device
*dev
)
43 uint32_t pmc_e
= NV_PMC_ENABLE_PGRAPH
| (1 << 21);
47 nv_wr32(dev
, NV03_PMC_ENABLE
, nv_rd32(dev
, NV03_PMC_ENABLE
) & ~pmc_e
);
48 nv_wr32(dev
, NV03_PMC_ENABLE
, nv_rd32(dev
, NV03_PMC_ENABLE
) | pmc_e
);
52 nv50_graph_init_intr(struct drm_device
*dev
)
56 nouveau_irq_register(dev
, 12, nv50_graph_isr
);
57 nv_wr32(dev
, NV03_PGRAPH_INTR
, 0xffffffff);
58 nv_wr32(dev
, 0x400138, 0xffffffff);
59 nv_wr32(dev
, NV40_PGRAPH_INTR_EN
, 0xffffffff);
63 nv50_graph_init_regs__nv(struct drm_device
*dev
)
65 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
66 uint32_t units
= nv_rd32(dev
, 0x1540);
71 nv_wr32(dev
, 0x400804, 0xc0000000);
72 nv_wr32(dev
, 0x406800, 0xc0000000);
73 nv_wr32(dev
, 0x400c04, 0xc0000000);
74 nv_wr32(dev
, 0x401800, 0xc0000000);
75 nv_wr32(dev
, 0x405018, 0xc0000000);
76 nv_wr32(dev
, 0x402000, 0xc0000000);
78 for (i
= 0; i
< 16; i
++) {
80 if (dev_priv
->chipset
< 0xa0) {
81 nv_wr32(dev
, 0x408900 + (i
<< 12), 0xc0000000);
82 nv_wr32(dev
, 0x408e08 + (i
<< 12), 0xc0000000);
83 nv_wr32(dev
, 0x408314 + (i
<< 12), 0xc0000000);
85 nv_wr32(dev
, 0x408600 + (i
<< 11), 0xc0000000);
86 nv_wr32(dev
, 0x408708 + (i
<< 11), 0xc0000000);
87 nv_wr32(dev
, 0x40831c + (i
<< 11), 0xc0000000);
92 nv_wr32(dev
, 0x400108, 0xffffffff);
94 nv_wr32(dev
, 0x400824, 0x00004000);
95 nv_wr32(dev
, 0x400500, 0x00010001);
99 nv50_graph_init_zcull(struct drm_device
*dev
)
101 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
106 switch (dev_priv
->chipset
& 0xf0) {
110 nv_wr32(dev
, 0x402ca8, 0x00000800);
114 nv_wr32(dev
, 0x402cc0, 0x00000000);
115 if (dev_priv
->chipset
== 0xa0 ||
116 dev_priv
->chipset
== 0xaa ||
117 dev_priv
->chipset
== 0xac) {
118 nv_wr32(dev
, 0x402ca8, 0x00000802);
120 nv_wr32(dev
, 0x402cc0, 0x00000000);
121 nv_wr32(dev
, 0x402ca8, 0x00000002);
127 /* zero out zcull regions */
128 for (i
= 0; i
< 8; i
++) {
129 nv_wr32(dev
, 0x402c20 + (i
* 8), 0x00000000);
130 nv_wr32(dev
, 0x402c24 + (i
* 8), 0x00000000);
131 nv_wr32(dev
, 0x402c28 + (i
* 8), 0x00000000);
132 nv_wr32(dev
, 0x402c2c + (i
* 8), 0x00000000);
137 nv50_graph_init_ctxctl(struct drm_device
*dev
)
139 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
140 struct nouveau_grctx ctx
= {};
146 cp
= kmalloc(512 * 4, GFP_KERNEL
);
148 NV_ERROR(dev
, "failed to allocate ctxprog\n");
149 dev_priv
->engine
.graph
.accel_blocked
= true;
154 ctx
.mode
= NOUVEAU_GRCTX_PROG
;
156 ctx
.ctxprog_max
= 512;
157 if (!nv50_grctx_init(&ctx
)) {
158 dev_priv
->engine
.graph
.grctx_size
= ctx
.ctxvals_pos
* 4;
160 nv_wr32(dev
, NV40_PGRAPH_CTXCTL_UCODE_INDEX
, 0);
161 for (i
= 0; i
< ctx
.ctxprog_len
; i
++)
162 nv_wr32(dev
, NV40_PGRAPH_CTXCTL_UCODE_DATA
, cp
[i
]);
164 dev_priv
->engine
.graph
.accel_blocked
= true;
168 nv_wr32(dev
, 0x40008c, 0x00000004); /* HW_CTX_SWITCH_ENABLED */
169 nv_wr32(dev
, 0x400320, 4);
170 nv_wr32(dev
, NV40_PGRAPH_CTXCTL_CUR
, 0);
171 nv_wr32(dev
, NV20_PGRAPH_CHANNEL_CTX_POINTER
, 0);
176 nv50_graph_init(struct drm_device
*dev
)
182 nv50_graph_init_reset(dev
);
183 nv50_graph_init_regs__nv(dev
);
184 nv50_graph_init_zcull(dev
);
186 ret
= nv50_graph_init_ctxctl(dev
);
190 ret
= nv50_graph_register(dev
);
193 nv50_graph_init_intr(dev
);
198 nv50_graph_takedown(struct drm_device
*dev
)
201 nv_wr32(dev
, 0x40013c, 0x00000000);
202 nouveau_irq_unregister(dev
, 12);
206 nv50_graph_fifo_access(struct drm_device
*dev
, bool enabled
)
208 const uint32_t mask
= 0x00010001;
211 nv_wr32(dev
, 0x400500, nv_rd32(dev
, 0x400500) | mask
);
213 nv_wr32(dev
, 0x400500, nv_rd32(dev
, 0x400500) & ~mask
);
216 struct nouveau_channel
*
217 nv50_graph_channel(struct drm_device
*dev
)
219 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
223 /* Be sure we're not in the middle of a context switch or bad things
224 * will happen, such as unloading the wrong pgraph context.
226 if (!nv_wait(dev
, 0x400300, 0x00000001, 0x00000000))
227 NV_ERROR(dev
, "Ctxprog is still running\n");
229 inst
= nv_rd32(dev
, NV50_PGRAPH_CTXCTL_CUR
);
230 if (!(inst
& NV50_PGRAPH_CTXCTL_CUR_LOADED
))
232 inst
= (inst
& NV50_PGRAPH_CTXCTL_CUR_INSTANCE
) << 12;
234 for (i
= 0; i
< dev_priv
->engine
.fifo
.channels
; i
++) {
235 struct nouveau_channel
*chan
= dev_priv
->channels
.ptr
[i
];
237 if (chan
&& chan
->ramin
&& chan
->ramin
->vinst
== inst
)
245 nv50_graph_create_context(struct nouveau_channel
*chan
)
247 struct drm_device
*dev
= chan
->dev
;
248 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
249 struct nouveau_gpuobj
*ramin
= chan
->ramin
;
250 struct nouveau_pgraph_engine
*pgraph
= &dev_priv
->engine
.graph
;
251 struct nouveau_grctx ctx
= {};
254 NV_DEBUG(dev
, "ch%d\n", chan
->id
);
256 ret
= nouveau_gpuobj_new(dev
, chan
, pgraph
->grctx_size
, 0,
257 NVOBJ_FLAG_ZERO_ALLOC
|
258 NVOBJ_FLAG_ZERO_FREE
, &chan
->ramin_grctx
);
262 hdr
= (dev_priv
->chipset
== 0x50) ? 0x200 : 0x20;
263 nv_wo32(ramin
, hdr
+ 0x00, 0x00190002);
264 nv_wo32(ramin
, hdr
+ 0x04, chan
->ramin_grctx
->vinst
+
265 pgraph
->grctx_size
- 1);
266 nv_wo32(ramin
, hdr
+ 0x08, chan
->ramin_grctx
->vinst
);
267 nv_wo32(ramin
, hdr
+ 0x0c, 0);
268 nv_wo32(ramin
, hdr
+ 0x10, 0);
269 nv_wo32(ramin
, hdr
+ 0x14, 0x00010000);
272 ctx
.mode
= NOUVEAU_GRCTX_VALS
;
273 ctx
.data
= chan
->ramin_grctx
;
274 nv50_grctx_init(&ctx
);
276 nv_wo32(chan
->ramin_grctx
, 0x00000, chan
->ramin
->vinst
>> 12);
278 dev_priv
->engine
.instmem
.flush(dev
);
279 atomic_inc(&chan
->vm
->pgraph_refs
);
284 nv50_graph_destroy_context(struct nouveau_channel
*chan
)
286 struct drm_device
*dev
= chan
->dev
;
287 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
288 struct nouveau_pgraph_engine
*pgraph
= &dev_priv
->engine
.graph
;
289 struct nouveau_fifo_engine
*pfifo
= &dev_priv
->engine
.fifo
;
290 int i
, hdr
= (dev_priv
->chipset
== 0x50) ? 0x200 : 0x20;
293 NV_DEBUG(dev
, "ch%d\n", chan
->id
);
298 spin_lock_irqsave(&dev_priv
->context_switch_lock
, flags
);
299 pfifo
->reassign(dev
, false);
300 pgraph
->fifo_access(dev
, false);
302 if (pgraph
->channel(dev
) == chan
)
303 pgraph
->unload_context(dev
);
305 for (i
= hdr
; i
< hdr
+ 24; i
+= 4)
306 nv_wo32(chan
->ramin
, i
, 0);
307 dev_priv
->engine
.instmem
.flush(dev
);
309 pgraph
->fifo_access(dev
, true);
310 pfifo
->reassign(dev
, true);
311 spin_unlock_irqrestore(&dev_priv
->context_switch_lock
, flags
);
313 nouveau_gpuobj_ref(NULL
, &chan
->ramin_grctx
);
315 atomic_dec(&chan
->vm
->pgraph_refs
);
319 nv50_graph_do_load_context(struct drm_device
*dev
, uint32_t inst
)
321 uint32_t fifo
= nv_rd32(dev
, 0x400500);
323 nv_wr32(dev
, 0x400500, fifo
& ~1);
324 nv_wr32(dev
, 0x400784, inst
);
325 nv_wr32(dev
, 0x400824, nv_rd32(dev
, 0x400824) | 0x40);
326 nv_wr32(dev
, 0x400320, nv_rd32(dev
, 0x400320) | 0x11);
327 nv_wr32(dev
, 0x400040, 0xffffffff);
328 (void)nv_rd32(dev
, 0x400040);
329 nv_wr32(dev
, 0x400040, 0x00000000);
330 nv_wr32(dev
, 0x400304, nv_rd32(dev
, 0x400304) | 1);
332 if (nouveau_wait_for_idle(dev
))
333 nv_wr32(dev
, 0x40032c, inst
| (1<<31));
334 nv_wr32(dev
, 0x400500, fifo
);
340 nv50_graph_load_context(struct nouveau_channel
*chan
)
342 uint32_t inst
= chan
->ramin
->vinst
>> 12;
344 NV_DEBUG(chan
->dev
, "ch%d\n", chan
->id
);
345 return nv50_graph_do_load_context(chan
->dev
, inst
);
349 nv50_graph_unload_context(struct drm_device
*dev
)
353 inst
= nv_rd32(dev
, NV50_PGRAPH_CTXCTL_CUR
);
354 if (!(inst
& NV50_PGRAPH_CTXCTL_CUR_LOADED
))
356 inst
&= NV50_PGRAPH_CTXCTL_CUR_INSTANCE
;
358 nouveau_wait_for_idle(dev
);
359 nv_wr32(dev
, 0x400784, inst
);
360 nv_wr32(dev
, 0x400824, nv_rd32(dev
, 0x400824) | 0x20);
361 nv_wr32(dev
, 0x400304, nv_rd32(dev
, 0x400304) | 0x01);
362 nouveau_wait_for_idle(dev
);
364 nv_wr32(dev
, NV50_PGRAPH_CTXCTL_CUR
, inst
);
369 nv50_graph_object_new(struct nouveau_channel
*chan
, u32 handle
, u16
class)
371 struct drm_device
*dev
= chan
->dev
;
372 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
373 struct nouveau_gpuobj
*obj
= NULL
;
376 ret
= nouveau_gpuobj_new(dev
, chan
, 16, 16, NVOBJ_FLAG_ZERO_FREE
, &obj
);
382 nv_wo32(obj
, 0x00, class);
383 nv_wo32(obj
, 0x04, 0x00000000);
384 nv_wo32(obj
, 0x08, 0x00000000);
385 nv_wo32(obj
, 0x0c, 0x00000000);
386 dev_priv
->engine
.instmem
.flush(dev
);
388 ret
= nouveau_ramht_insert(chan
, handle
, obj
);
389 nouveau_gpuobj_ref(NULL
, &obj
);
394 nv50_graph_context_switch(struct drm_device
*dev
)
398 nv50_graph_unload_context(dev
);
400 inst
= nv_rd32(dev
, NV50_PGRAPH_CTXCTL_NEXT
);
401 inst
&= NV50_PGRAPH_CTXCTL_NEXT_INSTANCE
;
402 nv50_graph_do_load_context(dev
, inst
);
404 nv_wr32(dev
, NV40_PGRAPH_INTR_EN
, nv_rd32(dev
,
405 NV40_PGRAPH_INTR_EN
) | NV_PGRAPH_INTR_CONTEXT_SWITCH
);
409 nv50_graph_nvsw_dma_vblsem(struct nouveau_channel
*chan
,
410 u32
class, u32 mthd
, u32 data
)
412 struct nouveau_gpuobj
*gpuobj
;
414 gpuobj
= nouveau_ramht_find(chan
, data
);
418 if (nouveau_notifier_offset(gpuobj
, NULL
))
421 chan
->nvsw
.vblsem
= gpuobj
;
422 chan
->nvsw
.vblsem_offset
= ~0;
427 nv50_graph_nvsw_vblsem_offset(struct nouveau_channel
*chan
,
428 u32
class, u32 mthd
, u32 data
)
430 if (nouveau_notifier_offset(chan
->nvsw
.vblsem
, &data
))
433 chan
->nvsw
.vblsem_offset
= data
>> 2;
438 nv50_graph_nvsw_vblsem_release_val(struct nouveau_channel
*chan
,
439 u32
class, u32 mthd
, u32 data
)
441 chan
->nvsw
.vblsem_rval
= data
;
446 nv50_graph_nvsw_vblsem_release(struct nouveau_channel
*chan
,
447 u32
class, u32 mthd
, u32 data
)
449 struct drm_device
*dev
= chan
->dev
;
450 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
452 if (!chan
->nvsw
.vblsem
|| chan
->nvsw
.vblsem_offset
== ~0 || data
> 1)
455 drm_vblank_get(dev
, data
);
457 chan
->nvsw
.vblsem_head
= data
;
458 list_add(&chan
->nvsw
.vbl_wait
, &dev_priv
->vbl_waiting
);
464 nv50_graph_nvsw_mthd_page_flip(struct nouveau_channel
*chan
,
465 u32
class, u32 mthd
, u32 data
)
467 nouveau_finish_page_flip(chan
, NULL
);
472 nv50_graph_register(struct drm_device
*dev
)
474 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
476 if (dev_priv
->engine
.graph
.registered
)
479 NVOBJ_CLASS(dev
, 0x506e, SW
); /* nvsw */
480 NVOBJ_MTHD (dev
, 0x506e, 0x018c, nv50_graph_nvsw_dma_vblsem
);
481 NVOBJ_MTHD (dev
, 0x506e, 0x0400, nv50_graph_nvsw_vblsem_offset
);
482 NVOBJ_MTHD (dev
, 0x506e, 0x0404, nv50_graph_nvsw_vblsem_release_val
);
483 NVOBJ_MTHD (dev
, 0x506e, 0x0408, nv50_graph_nvsw_vblsem_release
);
484 NVOBJ_MTHD (dev
, 0x506e, 0x0500, nv50_graph_nvsw_mthd_page_flip
);
486 NVOBJ_CLASS(dev
, 0x0030, GR
); /* null */
487 NVOBJ_CLASS(dev
, 0x5039, GR
); /* m2mf */
488 NVOBJ_CLASS(dev
, 0x502d, GR
); /* 2d */
491 if (dev_priv
->chipset
== 0x50)
492 NVOBJ_CLASS(dev
, 0x5097, GR
); /* tesla (nv50) */
494 if (dev_priv
->chipset
< 0xa0)
495 NVOBJ_CLASS(dev
, 0x8297, GR
); /* tesla (nv8x/nv9x) */
497 switch (dev_priv
->chipset
) {
501 NVOBJ_CLASS(dev
, 0x8397, GR
);
506 NVOBJ_CLASS(dev
, 0x8597, GR
);
509 NVOBJ_CLASS(dev
, 0x8697, GR
);
515 NVOBJ_CLASS(dev
, 0x50c0, GR
);
516 if (dev_priv
->chipset
> 0xa0 &&
517 dev_priv
->chipset
!= 0xaa &&
518 dev_priv
->chipset
!= 0xac)
519 NVOBJ_CLASS(dev
, 0x85c0, GR
);
521 dev_priv
->engine
.graph
.registered
= true;
526 nv50_graph_tlb_flush(struct drm_device
*dev
)
528 nv50_vm_flush_engine(dev
, 0);
532 nv84_graph_tlb_flush(struct drm_device
*dev
)
534 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
535 struct nouveau_timer_engine
*ptimer
= &dev_priv
->engine
.timer
;
536 bool idle
, timeout
= false;
541 spin_lock_irqsave(&dev_priv
->context_switch_lock
, flags
);
542 nv_mask(dev
, 0x400500, 0x00000001, 0x00000000);
544 start
= ptimer
->read(dev
);
548 for (tmp
= nv_rd32(dev
, 0x400380); tmp
&& idle
; tmp
>>= 3) {
553 for (tmp
= nv_rd32(dev
, 0x400384); tmp
&& idle
; tmp
>>= 3) {
558 for (tmp
= nv_rd32(dev
, 0x400388); tmp
&& idle
; tmp
>>= 3) {
562 } while (!idle
&& !(timeout
= ptimer
->read(dev
) - start
> 2000000000));
565 NV_ERROR(dev
, "PGRAPH TLB flush idle timeout fail: "
566 "0x%08x 0x%08x 0x%08x 0x%08x\n",
567 nv_rd32(dev
, 0x400700), nv_rd32(dev
, 0x400380),
568 nv_rd32(dev
, 0x400384), nv_rd32(dev
, 0x400388));
571 nv50_vm_flush_engine(dev
, 0);
573 nv_mask(dev
, 0x400500, 0x00000001, 0x00000001);
574 spin_unlock_irqrestore(&dev_priv
->context_switch_lock
, flags
);
577 static struct nouveau_enum nv50_mp_exec_error_names
[] = {
578 { 3, "STACK_UNDERFLOW", NULL
},
579 { 4, "QUADON_ACTIVE", NULL
},
580 { 8, "TIMEOUT", NULL
},
581 { 0x10, "INVALID_OPCODE", NULL
},
582 { 0x40, "BREAKPOINT", NULL
},
586 static struct nouveau_bitfield nv50_graph_trap_m2mf
[] = {
587 { 0x00000001, "NOTIFY" },
588 { 0x00000002, "IN" },
589 { 0x00000004, "OUT" },
593 static struct nouveau_bitfield nv50_graph_trap_vfetch
[] = {
594 { 0x00000001, "FAULT" },
598 static struct nouveau_bitfield nv50_graph_trap_strmout
[] = {
599 { 0x00000001, "FAULT" },
603 static struct nouveau_bitfield nv50_graph_trap_ccache
[] = {
604 { 0x00000001, "FAULT" },
608 /* There must be a *lot* of these. Will take some time to gather them up. */
609 struct nouveau_enum nv50_data_error_names
[] = {
610 { 0x00000003, "INVALID_QUERY_OR_TEXTURE", NULL
},
611 { 0x00000004, "INVALID_VALUE", NULL
},
612 { 0x00000005, "INVALID_ENUM", NULL
},
613 { 0x00000008, "INVALID_OBJECT", NULL
},
614 { 0x00000009, "READ_ONLY_OBJECT", NULL
},
615 { 0x0000000a, "SUPERVISOR_OBJECT", NULL
},
616 { 0x0000000b, "INVALID_ADDRESS_ALIGNMENT", NULL
},
617 { 0x0000000c, "INVALID_BITFIELD", NULL
},
618 { 0x0000000d, "BEGIN_END_ACTIVE", NULL
},
619 { 0x0000000e, "SEMANTIC_COLOR_BACK_OVER_LIMIT", NULL
},
620 { 0x0000000f, "VIEWPORT_ID_NEEDS_GP", NULL
},
621 { 0x00000010, "RT_DOUBLE_BIND", NULL
},
622 { 0x00000011, "RT_TYPES_MISMATCH", NULL
},
623 { 0x00000012, "RT_LINEAR_WITH_ZETA", NULL
},
624 { 0x00000015, "FP_TOO_FEW_REGS", NULL
},
625 { 0x00000016, "ZETA_FORMAT_CSAA_MISMATCH", NULL
},
626 { 0x00000017, "RT_LINEAR_WITH_MSAA", NULL
},
627 { 0x00000018, "FP_INTERPOLANT_START_OVER_LIMIT", NULL
},
628 { 0x00000019, "SEMANTIC_LAYER_OVER_LIMIT", NULL
},
629 { 0x0000001a, "RT_INVALID_ALIGNMENT", NULL
},
630 { 0x0000001b, "SAMPLER_OVER_LIMIT", NULL
},
631 { 0x0000001c, "TEXTURE_OVER_LIMIT", NULL
},
632 { 0x0000001e, "GP_TOO_MANY_OUTPUTS", NULL
},
633 { 0x0000001f, "RT_BPP128_WITH_MS8", NULL
},
634 { 0x00000021, "Z_OUT_OF_BOUNDS", NULL
},
635 { 0x00000023, "XY_OUT_OF_BOUNDS", NULL
},
636 { 0x00000027, "CP_MORE_PARAMS_THAN_SHARED", NULL
},
637 { 0x00000028, "CP_NO_REG_SPACE_STRIPED", NULL
},
638 { 0x00000029, "CP_NO_REG_SPACE_PACKED", NULL
},
639 { 0x0000002a, "CP_NOT_ENOUGH_WARPS", NULL
},
640 { 0x0000002b, "CP_BLOCK_SIZE_MISMATCH", NULL
},
641 { 0x0000002c, "CP_NOT_ENOUGH_LOCAL_WARPS", NULL
},
642 { 0x0000002d, "CP_NOT_ENOUGH_STACK_WARPS", NULL
},
643 { 0x0000002e, "CP_NO_BLOCKDIM_LATCH", NULL
},
644 { 0x00000031, "ENG2D_FORMAT_MISMATCH", NULL
},
645 { 0x0000003f, "PRIMITIVE_ID_NEEDS_GP", NULL
},
646 { 0x00000044, "SEMANTIC_VIEWPORT_OVER_LIMIT", NULL
},
647 { 0x00000045, "SEMANTIC_COLOR_FRONT_OVER_LIMIT", NULL
},
648 { 0x00000046, "LAYER_ID_NEEDS_GP", NULL
},
649 { 0x00000047, "SEMANTIC_CLIP_OVER_LIMIT", NULL
},
650 { 0x00000048, "SEMANTIC_PTSZ_OVER_LIMIT", NULL
},
654 static struct nouveau_bitfield nv50_graph_intr
[] = {
655 { 0x00000001, "NOTIFY" },
656 { 0x00000002, "COMPUTE_QUERY" },
657 { 0x00000010, "ILLEGAL_MTHD" },
658 { 0x00000020, "ILLEGAL_CLASS" },
659 { 0x00000040, "DOUBLE_NOTIFY" },
660 { 0x00001000, "CONTEXT_SWITCH" },
661 { 0x00010000, "BUFFER_NOTIFY" },
662 { 0x00100000, "DATA_ERROR" },
663 { 0x00200000, "TRAP" },
664 { 0x01000000, "SINGLE_STEP" },
669 nv50_pgraph_mp_trap(struct drm_device
*dev
, int tpid
, int display
)
671 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
672 uint32_t units
= nv_rd32(dev
, 0x1540);
673 uint32_t addr
, mp10
, status
, pc
, oplow
, ophigh
;
676 for (i
= 0; i
< 4; i
++) {
677 if (!(units
& 1 << (i
+24)))
679 if (dev_priv
->chipset
< 0xa0)
680 addr
= 0x408200 + (tpid
<< 12) + (i
<< 7);
682 addr
= 0x408100 + (tpid
<< 11) + (i
<< 7);
683 mp10
= nv_rd32(dev
, addr
+ 0x10);
684 status
= nv_rd32(dev
, addr
+ 0x14);
688 nv_rd32(dev
, addr
+ 0x20);
689 pc
= nv_rd32(dev
, addr
+ 0x24);
690 oplow
= nv_rd32(dev
, addr
+ 0x70);
691 ophigh
= nv_rd32(dev
, addr
+ 0x74);
692 NV_INFO(dev
, "PGRAPH_TRAP_MP_EXEC - "
693 "TP %d MP %d: ", tpid
, i
);
694 nouveau_enum_print(nv50_mp_exec_error_names
, status
);
695 printk(" at %06x warp %d, opcode %08x %08x\n",
696 pc
&0xffffff, pc
>> 24,
699 nv_wr32(dev
, addr
+ 0x10, mp10
);
700 nv_wr32(dev
, addr
+ 0x14, 0);
704 NV_INFO(dev
, "PGRAPH_TRAP_MP_EXEC - TP %d: "
705 "No MPs claiming errors?\n", tpid
);
709 nv50_pgraph_tp_trap(struct drm_device
*dev
, int type
, uint32_t ustatus_old
,
710 uint32_t ustatus_new
, int display
, const char *name
)
712 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
714 uint32_t units
= nv_rd32(dev
, 0x1540);
716 uint32_t ustatus_addr
, ustatus
;
717 for (i
= 0; i
< 16; i
++) {
718 if (!(units
& (1 << i
)))
720 if (dev_priv
->chipset
< 0xa0)
721 ustatus_addr
= ustatus_old
+ (i
<< 12);
723 ustatus_addr
= ustatus_new
+ (i
<< 11);
724 ustatus
= nv_rd32(dev
, ustatus_addr
) & 0x7fffffff;
729 case 6: /* texture error... unknown for now */
731 NV_ERROR(dev
, "magic set %d:\n", i
);
732 for (r
= ustatus_addr
+ 4; r
<= ustatus_addr
+ 0x10; r
+= 4)
733 NV_ERROR(dev
, "\t0x%08x: 0x%08x\n", r
,
737 case 7: /* MP error */
738 if (ustatus
& 0x00010000) {
739 nv50_pgraph_mp_trap(dev
, i
, display
);
740 ustatus
&= ~0x00010000;
743 case 8: /* TPDMA error */
745 uint32_t e0c
= nv_rd32(dev
, ustatus_addr
+ 4);
746 uint32_t e10
= nv_rd32(dev
, ustatus_addr
+ 8);
747 uint32_t e14
= nv_rd32(dev
, ustatus_addr
+ 0xc);
748 uint32_t e18
= nv_rd32(dev
, ustatus_addr
+ 0x10);
749 uint32_t e1c
= nv_rd32(dev
, ustatus_addr
+ 0x14);
750 uint32_t e20
= nv_rd32(dev
, ustatus_addr
+ 0x18);
751 uint32_t e24
= nv_rd32(dev
, ustatus_addr
+ 0x1c);
752 /* 2d engine destination */
753 if (ustatus
& 0x00000010) {
755 NV_INFO(dev
, "PGRAPH_TRAP_TPDMA_2D - TP %d - Unknown fault at address %02x%08x\n",
757 NV_INFO(dev
, "PGRAPH_TRAP_TPDMA_2D - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
758 i
, e0c
, e18
, e1c
, e20
, e24
);
760 ustatus
&= ~0x00000010;
763 if (ustatus
& 0x00000040) {
765 NV_INFO(dev
, "PGRAPH_TRAP_TPDMA_RT - TP %d - Unknown fault at address %02x%08x\n",
767 NV_INFO(dev
, "PGRAPH_TRAP_TPDMA_RT - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
768 i
, e0c
, e18
, e1c
, e20
, e24
);
770 ustatus
&= ~0x00000040;
772 /* CUDA memory: l[], g[] or stack. */
773 if (ustatus
& 0x00000080) {
775 if (e18
& 0x80000000) {
776 /* g[] read fault? */
777 NV_INFO(dev
, "PGRAPH_TRAP_TPDMA - TP %d - Global read fault at address %02x%08x\n",
778 i
, e14
, e10
| ((e18
>> 24) & 0x1f));
780 } else if (e18
& 0xc) {
781 /* g[] write fault? */
782 NV_INFO(dev
, "PGRAPH_TRAP_TPDMA - TP %d - Global write fault at address %02x%08x\n",
783 i
, e14
, e10
| ((e18
>> 7) & 0x1f));
786 NV_INFO(dev
, "PGRAPH_TRAP_TPDMA - TP %d - Unknown CUDA fault at address %02x%08x\n",
789 NV_INFO(dev
, "PGRAPH_TRAP_TPDMA - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
790 i
, e0c
, e18
, e1c
, e20
, e24
);
792 ustatus
&= ~0x00000080;
799 NV_INFO(dev
, "%s - TP%d: Unhandled ustatus 0x%08x\n", name
, i
, ustatus
);
801 nv_wr32(dev
, ustatus_addr
, 0xc0000000);
805 NV_INFO(dev
, "%s - No TPs claiming errors?\n", name
);
809 nv50_pgraph_trap_handler(struct drm_device
*dev
, u32 display
, u64 inst
, u32 chid
)
811 u32 status
= nv_rd32(dev
, 0x400108);
814 if (!status
&& display
) {
815 NV_INFO(dev
, "PGRAPH - TRAP: no units reporting traps?\n");
819 /* DISPATCH: Relays commands to other units and handles NOTIFY,
820 * COND, QUERY. If you get a trap from it, the command is still stuck
821 * in DISPATCH and you need to do something about it. */
822 if (status
& 0x001) {
823 ustatus
= nv_rd32(dev
, 0x400804) & 0x7fffffff;
824 if (!ustatus
&& display
) {
825 NV_INFO(dev
, "PGRAPH_TRAP_DISPATCH - no ustatus?\n");
828 nv_wr32(dev
, 0x400500, 0x00000000);
830 /* Known to be triggered by screwed up NOTIFY and COND... */
831 if (ustatus
& 0x00000001) {
832 u32 addr
= nv_rd32(dev
, 0x400808);
833 u32 subc
= (addr
& 0x00070000) >> 16;
834 u32 mthd
= (addr
& 0x00001ffc);
835 u32 datal
= nv_rd32(dev
, 0x40080c);
836 u32 datah
= nv_rd32(dev
, 0x400810);
837 u32
class = nv_rd32(dev
, 0x400814);
838 u32 r848
= nv_rd32(dev
, 0x400848);
840 NV_INFO(dev
, "PGRAPH - TRAP DISPATCH_FAULT\n");
841 if (display
&& (addr
& 0x80000000)) {
842 NV_INFO(dev
, "PGRAPH - ch %d (0x%010llx) "
843 "subc %d class 0x%04x mthd 0x%04x "
845 "400808 0x%08x 400848 0x%08x\n",
846 chid
, inst
, subc
, class, mthd
, datah
,
850 NV_INFO(dev
, "PGRAPH - no stuck command?\n");
853 nv_wr32(dev
, 0x400808, 0);
854 nv_wr32(dev
, 0x4008e8, nv_rd32(dev
, 0x4008e8) & 3);
855 nv_wr32(dev
, 0x400848, 0);
856 ustatus
&= ~0x00000001;
859 if (ustatus
& 0x00000002) {
860 u32 addr
= nv_rd32(dev
, 0x40084c);
861 u32 subc
= (addr
& 0x00070000) >> 16;
862 u32 mthd
= (addr
& 0x00001ffc);
863 u32 data
= nv_rd32(dev
, 0x40085c);
864 u32
class = nv_rd32(dev
, 0x400814);
866 NV_INFO(dev
, "PGRAPH - TRAP DISPATCH_QUERY\n");
867 if (display
&& (addr
& 0x80000000)) {
868 NV_INFO(dev
, "PGRAPH - ch %d (0x%010llx) "
869 "subc %d class 0x%04x mthd 0x%04x "
870 "data 0x%08x 40084c 0x%08x\n",
871 chid
, inst
, subc
, class, mthd
,
875 NV_INFO(dev
, "PGRAPH - no stuck command?\n");
878 nv_wr32(dev
, 0x40084c, 0);
879 ustatus
&= ~0x00000002;
882 if (ustatus
&& display
) {
883 NV_INFO(dev
, "PGRAPH - TRAP_DISPATCH (unknown "
884 "0x%08x)\n", ustatus
);
887 nv_wr32(dev
, 0x400804, 0xc0000000);
888 nv_wr32(dev
, 0x400108, 0x001);
894 /* M2MF: Memory to memory copy engine. */
895 if (status
& 0x002) {
896 u32 ustatus
= nv_rd32(dev
, 0x406800) & 0x7fffffff;
898 NV_INFO(dev
, "PGRAPH - TRAP_M2MF");
899 nouveau_bitfield_print(nv50_graph_trap_m2mf
, ustatus
);
901 NV_INFO(dev
, "PGRAPH - TRAP_M2MF %08x %08x %08x %08x\n",
902 nv_rd32(dev
, 0x406804), nv_rd32(dev
, 0x406808),
903 nv_rd32(dev
, 0x40680c), nv_rd32(dev
, 0x406810));
907 /* No sane way found yet -- just reset the bugger. */
908 nv_wr32(dev
, 0x400040, 2);
909 nv_wr32(dev
, 0x400040, 0);
910 nv_wr32(dev
, 0x406800, 0xc0000000);
911 nv_wr32(dev
, 0x400108, 0x002);
915 /* VFETCH: Fetches data from vertex buffers. */
916 if (status
& 0x004) {
917 u32 ustatus
= nv_rd32(dev
, 0x400c04) & 0x7fffffff;
919 NV_INFO(dev
, "PGRAPH - TRAP_VFETCH");
920 nouveau_bitfield_print(nv50_graph_trap_vfetch
, ustatus
);
922 NV_INFO(dev
, "PGRAPH - TRAP_VFETCH %08x %08x %08x %08x\n",
923 nv_rd32(dev
, 0x400c00), nv_rd32(dev
, 0x400c08),
924 nv_rd32(dev
, 0x400c0c), nv_rd32(dev
, 0x400c10));
927 nv_wr32(dev
, 0x400c04, 0xc0000000);
928 nv_wr32(dev
, 0x400108, 0x004);
932 /* STRMOUT: DirectX streamout / OpenGL transform feedback. */
933 if (status
& 0x008) {
934 ustatus
= nv_rd32(dev
, 0x401800) & 0x7fffffff;
936 NV_INFO(dev
, "PGRAPH - TRAP_STRMOUT");
937 nouveau_bitfield_print(nv50_graph_trap_strmout
, ustatus
);
939 NV_INFO(dev
, "PGRAPH - TRAP_STRMOUT %08x %08x %08x %08x\n",
940 nv_rd32(dev
, 0x401804), nv_rd32(dev
, 0x401808),
941 nv_rd32(dev
, 0x40180c), nv_rd32(dev
, 0x401810));
945 /* No sane way found yet -- just reset the bugger. */
946 nv_wr32(dev
, 0x400040, 0x80);
947 nv_wr32(dev
, 0x400040, 0);
948 nv_wr32(dev
, 0x401800, 0xc0000000);
949 nv_wr32(dev
, 0x400108, 0x008);
953 /* CCACHE: Handles code and c[] caches and fills them. */
954 if (status
& 0x010) {
955 ustatus
= nv_rd32(dev
, 0x405018) & 0x7fffffff;
957 NV_INFO(dev
, "PGRAPH - TRAP_CCACHE");
958 nouveau_bitfield_print(nv50_graph_trap_ccache
, ustatus
);
960 NV_INFO(dev
, "PGRAPH - TRAP_CCACHE %08x %08x %08x %08x"
962 nv_rd32(dev
, 0x405000), nv_rd32(dev
, 0x405004),
963 nv_rd32(dev
, 0x405008), nv_rd32(dev
, 0x40500c),
964 nv_rd32(dev
, 0x405010), nv_rd32(dev
, 0x405014),
965 nv_rd32(dev
, 0x40501c));
969 nv_wr32(dev
, 0x405018, 0xc0000000);
970 nv_wr32(dev
, 0x400108, 0x010);
974 /* Unknown, not seen yet... 0x402000 is the only trap status reg
975 * remaining, so try to handle it anyway. Perhaps related to that
976 * unknown DMA slot on tesla? */
978 ustatus
= nv_rd32(dev
, 0x402000) & 0x7fffffff;
980 NV_INFO(dev
, "PGRAPH - TRAP_UNKC04 0x%08x\n", ustatus
);
981 nv_wr32(dev
, 0x402000, 0xc0000000);
982 /* no status modifiction on purpose */
985 /* TEXTURE: CUDA texturing units */
986 if (status
& 0x040) {
987 nv50_pgraph_tp_trap(dev
, 6, 0x408900, 0x408600, display
,
988 "PGRAPH - TRAP_TEXTURE");
989 nv_wr32(dev
, 0x400108, 0x040);
993 /* MP: CUDA execution engines. */
994 if (status
& 0x080) {
995 nv50_pgraph_tp_trap(dev
, 7, 0x408314, 0x40831c, display
,
997 nv_wr32(dev
, 0x400108, 0x080);
1001 /* TPDMA: Handles TP-initiated uncached memory accesses:
1002 * l[], g[], stack, 2d surfaces, render targets. */
1003 if (status
& 0x100) {
1004 nv50_pgraph_tp_trap(dev
, 8, 0x408e08, 0x408708, display
,
1005 "PGRAPH - TRAP_TPDMA");
1006 nv_wr32(dev
, 0x400108, 0x100);
1012 NV_INFO(dev
, "PGRAPH - TRAP: unknown 0x%08x\n", status
);
1013 nv_wr32(dev
, 0x400108, status
);
1020 nv50_graph_isr_chid(struct drm_device
*dev
, u64 inst
)
1022 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
1023 struct nouveau_channel
*chan
;
1024 unsigned long flags
;
1027 spin_lock_irqsave(&dev_priv
->channels
.lock
, flags
);
1028 for (i
= 0; i
< dev_priv
->engine
.fifo
.channels
; i
++) {
1029 chan
= dev_priv
->channels
.ptr
[i
];
1030 if (!chan
|| !chan
->ramin
)
1033 if (inst
== chan
->ramin
->vinst
)
1036 spin_unlock_irqrestore(&dev_priv
->channels
.lock
, flags
);
1041 nv50_graph_isr(struct drm_device
*dev
)
1045 while ((stat
= nv_rd32(dev
, 0x400100))) {
1046 u64 inst
= (u64
)(nv_rd32(dev
, 0x40032c) & 0x0fffffff) << 12;
1047 u32 chid
= nv50_graph_isr_chid(dev
, inst
);
1048 u32 addr
= nv_rd32(dev
, NV04_PGRAPH_TRAPPED_ADDR
);
1049 u32 subc
= (addr
& 0x00070000) >> 16;
1050 u32 mthd
= (addr
& 0x00001ffc);
1051 u32 data
= nv_rd32(dev
, NV04_PGRAPH_TRAPPED_DATA
);
1052 u32
class = nv_rd32(dev
, 0x400814);
1055 if (stat
& 0x00000010) {
1056 if (!nouveau_gpuobj_mthd_call2(dev
, chid
, class,
1058 show
&= ~0x00000010;
1061 if (stat
& 0x00001000) {
1062 nv_wr32(dev
, 0x400500, 0x00000000);
1063 nv_wr32(dev
, 0x400100, 0x00001000);
1064 nv_mask(dev
, 0x40013c, 0x00001000, 0x00000000);
1065 nv50_graph_context_switch(dev
);
1066 stat
&= ~0x00001000;
1067 show
&= ~0x00001000;
1070 show
= (show
&& nouveau_ratelimit()) ? show
: 0;
1072 if (show
& 0x00100000) {
1073 u32 ecode
= nv_rd32(dev
, 0x400110);
1074 NV_INFO(dev
, "PGRAPH - DATA_ERROR ");
1075 nouveau_enum_print(nv50_data_error_names
, ecode
);
1079 if (stat
& 0x00200000) {
1080 if (!nv50_pgraph_trap_handler(dev
, show
, inst
, chid
))
1081 show
&= ~0x00200000;
1084 nv_wr32(dev
, 0x400100, stat
);
1085 nv_wr32(dev
, 0x400500, 0x00010001);
1088 NV_INFO(dev
, "PGRAPH -");
1089 nouveau_bitfield_print(nv50_graph_intr
, show
);
1091 NV_INFO(dev
, "PGRAPH - ch %d (0x%010llx) subc %d "
1092 "class 0x%04x mthd 0x%04x data 0x%08x\n",
1093 chid
, inst
, subc
, class, mthd
, data
);
1094 nv50_fb_vm_trap(dev
, 1);
1098 if (nv_rd32(dev
, 0x400824) & (1 << 31))
1099 nv_wr32(dev
, 0x400824, nv_rd32(dev
, 0x400824) & ~(1 << 31));