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 struct nv50_graph_engine
{
38 struct nouveau_exec_engine base
;
45 nv50_graph_fifo_access(struct drm_device
*dev
, bool enabled
)
47 const uint32_t mask
= 0x00010001;
50 nv_wr32(dev
, 0x400500, nv_rd32(dev
, 0x400500) | mask
);
52 nv_wr32(dev
, 0x400500, nv_rd32(dev
, 0x400500) & ~mask
);
55 static struct nouveau_channel
*
56 nv50_graph_channel(struct drm_device
*dev
)
58 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
62 /* Be sure we're not in the middle of a context switch or bad things
63 * will happen, such as unloading the wrong pgraph context.
65 if (!nv_wait(dev
, 0x400300, 0x00000001, 0x00000000))
66 NV_ERROR(dev
, "Ctxprog is still running\n");
68 inst
= nv_rd32(dev
, NV50_PGRAPH_CTXCTL_CUR
);
69 if (!(inst
& NV50_PGRAPH_CTXCTL_CUR_LOADED
))
71 inst
= (inst
& NV50_PGRAPH_CTXCTL_CUR_INSTANCE
) << 12;
73 for (i
= 0; i
< dev_priv
->engine
.fifo
.channels
; i
++) {
74 struct nouveau_channel
*chan
= dev_priv
->channels
.ptr
[i
];
76 if (chan
&& chan
->ramin
&& chan
->ramin
->vinst
== inst
)
84 nv50_graph_do_load_context(struct drm_device
*dev
, uint32_t inst
)
86 uint32_t fifo
= nv_rd32(dev
, 0x400500);
88 nv_wr32(dev
, 0x400500, fifo
& ~1);
89 nv_wr32(dev
, 0x400784, inst
);
90 nv_wr32(dev
, 0x400824, nv_rd32(dev
, 0x400824) | 0x40);
91 nv_wr32(dev
, 0x400320, nv_rd32(dev
, 0x400320) | 0x11);
92 nv_wr32(dev
, 0x400040, 0xffffffff);
93 (void)nv_rd32(dev
, 0x400040);
94 nv_wr32(dev
, 0x400040, 0x00000000);
95 nv_wr32(dev
, 0x400304, nv_rd32(dev
, 0x400304) | 1);
97 if (nouveau_wait_for_idle(dev
))
98 nv_wr32(dev
, 0x40032c, inst
| (1<<31));
99 nv_wr32(dev
, 0x400500, fifo
);
105 nv50_graph_unload_context(struct drm_device
*dev
)
109 inst
= nv_rd32(dev
, NV50_PGRAPH_CTXCTL_CUR
);
110 if (!(inst
& NV50_PGRAPH_CTXCTL_CUR_LOADED
))
112 inst
&= NV50_PGRAPH_CTXCTL_CUR_INSTANCE
;
114 nouveau_wait_for_idle(dev
);
115 nv_wr32(dev
, 0x400784, inst
);
116 nv_wr32(dev
, 0x400824, nv_rd32(dev
, 0x400824) | 0x20);
117 nv_wr32(dev
, 0x400304, nv_rd32(dev
, 0x400304) | 0x01);
118 nouveau_wait_for_idle(dev
);
120 nv_wr32(dev
, NV50_PGRAPH_CTXCTL_CUR
, inst
);
125 nv50_graph_init_reset(struct drm_device
*dev
)
127 uint32_t pmc_e
= NV_PMC_ENABLE_PGRAPH
| (1 << 21);
131 nv_wr32(dev
, NV03_PMC_ENABLE
, nv_rd32(dev
, NV03_PMC_ENABLE
) & ~pmc_e
);
132 nv_wr32(dev
, NV03_PMC_ENABLE
, nv_rd32(dev
, NV03_PMC_ENABLE
) | pmc_e
);
136 nv50_graph_init_intr(struct drm_device
*dev
)
140 nv_wr32(dev
, NV03_PGRAPH_INTR
, 0xffffffff);
141 nv_wr32(dev
, 0x400138, 0xffffffff);
142 nv_wr32(dev
, NV40_PGRAPH_INTR_EN
, 0xffffffff);
146 nv50_graph_init_regs__nv(struct drm_device
*dev
)
148 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
149 uint32_t units
= nv_rd32(dev
, 0x1540);
154 nv_wr32(dev
, 0x400804, 0xc0000000);
155 nv_wr32(dev
, 0x406800, 0xc0000000);
156 nv_wr32(dev
, 0x400c04, 0xc0000000);
157 nv_wr32(dev
, 0x401800, 0xc0000000);
158 nv_wr32(dev
, 0x405018, 0xc0000000);
159 nv_wr32(dev
, 0x402000, 0xc0000000);
161 for (i
= 0; i
< 16; i
++) {
162 if (units
& 1 << i
) {
163 if (dev_priv
->chipset
< 0xa0) {
164 nv_wr32(dev
, 0x408900 + (i
<< 12), 0xc0000000);
165 nv_wr32(dev
, 0x408e08 + (i
<< 12), 0xc0000000);
166 nv_wr32(dev
, 0x408314 + (i
<< 12), 0xc0000000);
168 nv_wr32(dev
, 0x408600 + (i
<< 11), 0xc0000000);
169 nv_wr32(dev
, 0x408708 + (i
<< 11), 0xc0000000);
170 nv_wr32(dev
, 0x40831c + (i
<< 11), 0xc0000000);
175 nv_wr32(dev
, 0x400108, 0xffffffff);
177 nv_wr32(dev
, 0x400824, 0x00004000);
178 nv_wr32(dev
, 0x400500, 0x00010001);
182 nv50_graph_init_zcull(struct drm_device
*dev
)
184 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
189 switch (dev_priv
->chipset
& 0xf0) {
193 nv_wr32(dev
, 0x402ca8, 0x00000800);
197 nv_wr32(dev
, 0x402cc0, 0x00000000);
198 if (dev_priv
->chipset
== 0xa0 ||
199 dev_priv
->chipset
== 0xaa ||
200 dev_priv
->chipset
== 0xac) {
201 nv_wr32(dev
, 0x402ca8, 0x00000802);
203 nv_wr32(dev
, 0x402cc0, 0x00000000);
204 nv_wr32(dev
, 0x402ca8, 0x00000002);
210 /* zero out zcull regions */
211 for (i
= 0; i
< 8; i
++) {
212 nv_wr32(dev
, 0x402c20 + (i
* 8), 0x00000000);
213 nv_wr32(dev
, 0x402c24 + (i
* 8), 0x00000000);
214 nv_wr32(dev
, 0x402c28 + (i
* 8), 0x00000000);
215 nv_wr32(dev
, 0x402c2c + (i
* 8), 0x00000000);
220 nv50_graph_init_ctxctl(struct drm_device
*dev
)
222 struct nv50_graph_engine
*pgraph
= nv_engine(dev
, NVOBJ_ENGINE_GR
);
227 nv_wr32(dev
, NV40_PGRAPH_CTXCTL_UCODE_INDEX
, 0);
228 for (i
= 0; i
< pgraph
->ctxprog_size
; i
++)
229 nv_wr32(dev
, NV40_PGRAPH_CTXCTL_UCODE_DATA
, pgraph
->ctxprog
[i
]);
231 nv_wr32(dev
, 0x40008c, 0x00000004); /* HW_CTX_SWITCH_ENABLED */
232 nv_wr32(dev
, 0x400320, 4);
233 nv_wr32(dev
, NV40_PGRAPH_CTXCTL_CUR
, 0);
234 nv_wr32(dev
, NV20_PGRAPH_CHANNEL_CTX_POINTER
, 0);
239 nv50_graph_init(struct drm_device
*dev
, int engine
)
245 nv50_graph_init_reset(dev
);
246 nv50_graph_init_regs__nv(dev
);
247 nv50_graph_init_zcull(dev
);
249 ret
= nv50_graph_init_ctxctl(dev
);
253 nv50_graph_init_intr(dev
);
258 nv50_graph_fini(struct drm_device
*dev
, int engine
)
261 nv50_graph_unload_context(dev
);
262 nv_wr32(dev
, 0x40013c, 0x00000000);
267 nv50_graph_context_new(struct nouveau_channel
*chan
, int engine
)
269 struct drm_device
*dev
= chan
->dev
;
270 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
271 struct nouveau_gpuobj
*ramin
= chan
->ramin
;
272 struct nouveau_gpuobj
*grctx
= NULL
;
273 struct nv50_graph_engine
*pgraph
= nv_engine(dev
, engine
);
274 struct nouveau_grctx ctx
= {};
277 NV_DEBUG(dev
, "ch%d\n", chan
->id
);
279 ret
= nouveau_gpuobj_new(dev
, NULL
, pgraph
->grctx_size
, 0,
280 NVOBJ_FLAG_ZERO_ALLOC
|
281 NVOBJ_FLAG_ZERO_FREE
, &grctx
);
285 hdr
= (dev_priv
->chipset
== 0x50) ? 0x200 : 0x20;
286 nv_wo32(ramin
, hdr
+ 0x00, 0x00190002);
287 nv_wo32(ramin
, hdr
+ 0x04, grctx
->vinst
+ grctx
->size
- 1);
288 nv_wo32(ramin
, hdr
+ 0x08, grctx
->vinst
);
289 nv_wo32(ramin
, hdr
+ 0x0c, 0);
290 nv_wo32(ramin
, hdr
+ 0x10, 0);
291 nv_wo32(ramin
, hdr
+ 0x14, 0x00010000);
294 ctx
.mode
= NOUVEAU_GRCTX_VALS
;
296 nv50_grctx_init(&ctx
);
298 nv_wo32(grctx
, 0x00000, chan
->ramin
->vinst
>> 12);
300 dev_priv
->engine
.instmem
.flush(dev
);
302 atomic_inc(&chan
->vm
->engref
[NVOBJ_ENGINE_GR
]);
303 chan
->engctx
[NVOBJ_ENGINE_GR
] = grctx
;
308 nv50_graph_context_del(struct nouveau_channel
*chan
, int engine
)
310 struct nouveau_gpuobj
*grctx
= chan
->engctx
[engine
];
311 struct drm_device
*dev
= chan
->dev
;
312 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
313 struct nouveau_fifo_engine
*pfifo
= &dev_priv
->engine
.fifo
;
314 int i
, hdr
= (dev_priv
->chipset
== 0x50) ? 0x200 : 0x20;
317 NV_DEBUG(dev
, "ch%d\n", chan
->id
);
322 spin_lock_irqsave(&dev_priv
->context_switch_lock
, flags
);
323 pfifo
->reassign(dev
, false);
324 nv50_graph_fifo_access(dev
, false);
326 if (nv50_graph_channel(dev
) == chan
)
327 nv50_graph_unload_context(dev
);
329 for (i
= hdr
; i
< hdr
+ 24; i
+= 4)
330 nv_wo32(chan
->ramin
, i
, 0);
331 dev_priv
->engine
.instmem
.flush(dev
);
333 nv50_graph_fifo_access(dev
, true);
334 pfifo
->reassign(dev
, true);
335 spin_unlock_irqrestore(&dev_priv
->context_switch_lock
, flags
);
337 nouveau_gpuobj_ref(NULL
, &grctx
);
339 atomic_dec(&chan
->vm
->engref
[engine
]);
340 chan
->engctx
[engine
] = NULL
;
344 nv50_graph_object_new(struct nouveau_channel
*chan
, int engine
,
345 u32 handle
, u16
class)
347 struct drm_device
*dev
= chan
->dev
;
348 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
349 struct nouveau_gpuobj
*obj
= NULL
;
352 ret
= nouveau_gpuobj_new(dev
, chan
, 16, 16, NVOBJ_FLAG_ZERO_FREE
, &obj
);
358 nv_wo32(obj
, 0x00, class);
359 nv_wo32(obj
, 0x04, 0x00000000);
360 nv_wo32(obj
, 0x08, 0x00000000);
361 nv_wo32(obj
, 0x0c, 0x00000000);
362 dev_priv
->engine
.instmem
.flush(dev
);
364 ret
= nouveau_ramht_insert(chan
, handle
, obj
);
365 nouveau_gpuobj_ref(NULL
, &obj
);
370 nv50_graph_context_switch(struct drm_device
*dev
)
374 nv50_graph_unload_context(dev
);
376 inst
= nv_rd32(dev
, NV50_PGRAPH_CTXCTL_NEXT
);
377 inst
&= NV50_PGRAPH_CTXCTL_NEXT_INSTANCE
;
378 nv50_graph_do_load_context(dev
, inst
);
380 nv_wr32(dev
, NV40_PGRAPH_INTR_EN
, nv_rd32(dev
,
381 NV40_PGRAPH_INTR_EN
) | NV_PGRAPH_INTR_CONTEXT_SWITCH
);
385 nv50_graph_nvsw_dma_vblsem(struct nouveau_channel
*chan
,
386 u32
class, u32 mthd
, u32 data
)
388 struct nouveau_gpuobj
*gpuobj
;
390 gpuobj
= nouveau_ramht_find(chan
, data
);
394 if (nouveau_notifier_offset(gpuobj
, NULL
))
397 chan
->nvsw
.vblsem
= gpuobj
;
398 chan
->nvsw
.vblsem_offset
= ~0;
403 nv50_graph_nvsw_vblsem_offset(struct nouveau_channel
*chan
,
404 u32
class, u32 mthd
, u32 data
)
406 if (nouveau_notifier_offset(chan
->nvsw
.vblsem
, &data
))
409 chan
->nvsw
.vblsem_offset
= data
>> 2;
414 nv50_graph_nvsw_vblsem_release_val(struct nouveau_channel
*chan
,
415 u32
class, u32 mthd
, u32 data
)
417 chan
->nvsw
.vblsem_rval
= data
;
422 nv50_graph_nvsw_vblsem_release(struct nouveau_channel
*chan
,
423 u32
class, u32 mthd
, u32 data
)
425 struct drm_device
*dev
= chan
->dev
;
426 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
428 if (!chan
->nvsw
.vblsem
|| chan
->nvsw
.vblsem_offset
== ~0 || data
> 1)
431 drm_vblank_get(dev
, data
);
433 chan
->nvsw
.vblsem_head
= data
;
434 list_add(&chan
->nvsw
.vbl_wait
, &dev_priv
->vbl_waiting
);
440 nv50_graph_nvsw_mthd_page_flip(struct nouveau_channel
*chan
,
441 u32
class, u32 mthd
, u32 data
)
443 nouveau_finish_page_flip(chan
, NULL
);
449 nv50_graph_tlb_flush(struct drm_device
*dev
, int engine
)
451 nv50_vm_flush_engine(dev
, 0);
455 nv84_graph_tlb_flush(struct drm_device
*dev
, int engine
)
457 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
458 struct nouveau_timer_engine
*ptimer
= &dev_priv
->engine
.timer
;
459 bool idle
, timeout
= false;
464 spin_lock_irqsave(&dev_priv
->context_switch_lock
, flags
);
465 nv_mask(dev
, 0x400500, 0x00000001, 0x00000000);
467 start
= ptimer
->read(dev
);
471 for (tmp
= nv_rd32(dev
, 0x400380); tmp
&& idle
; tmp
>>= 3) {
476 for (tmp
= nv_rd32(dev
, 0x400384); tmp
&& idle
; tmp
>>= 3) {
481 for (tmp
= nv_rd32(dev
, 0x400388); tmp
&& idle
; tmp
>>= 3) {
485 } while (!idle
&& !(timeout
= ptimer
->read(dev
) - start
> 2000000000));
488 NV_ERROR(dev
, "PGRAPH TLB flush idle timeout fail: "
489 "0x%08x 0x%08x 0x%08x 0x%08x\n",
490 nv_rd32(dev
, 0x400700), nv_rd32(dev
, 0x400380),
491 nv_rd32(dev
, 0x400384), nv_rd32(dev
, 0x400388));
494 nv50_vm_flush_engine(dev
, 0);
496 nv_mask(dev
, 0x400500, 0x00000001, 0x00000001);
497 spin_unlock_irqrestore(&dev_priv
->context_switch_lock
, flags
);
500 static struct nouveau_enum nv50_mp_exec_error_names
[] = {
501 { 3, "STACK_UNDERFLOW", NULL
},
502 { 4, "QUADON_ACTIVE", NULL
},
503 { 8, "TIMEOUT", NULL
},
504 { 0x10, "INVALID_OPCODE", NULL
},
505 { 0x40, "BREAKPOINT", NULL
},
509 static struct nouveau_bitfield nv50_graph_trap_m2mf
[] = {
510 { 0x00000001, "NOTIFY" },
511 { 0x00000002, "IN" },
512 { 0x00000004, "OUT" },
516 static struct nouveau_bitfield nv50_graph_trap_vfetch
[] = {
517 { 0x00000001, "FAULT" },
521 static struct nouveau_bitfield nv50_graph_trap_strmout
[] = {
522 { 0x00000001, "FAULT" },
526 static struct nouveau_bitfield nv50_graph_trap_ccache
[] = {
527 { 0x00000001, "FAULT" },
531 /* There must be a *lot* of these. Will take some time to gather them up. */
532 struct nouveau_enum nv50_data_error_names
[] = {
533 { 0x00000003, "INVALID_QUERY_OR_TEXTURE", NULL
},
534 { 0x00000004, "INVALID_VALUE", NULL
},
535 { 0x00000005, "INVALID_ENUM", NULL
},
536 { 0x00000008, "INVALID_OBJECT", NULL
},
537 { 0x00000009, "READ_ONLY_OBJECT", NULL
},
538 { 0x0000000a, "SUPERVISOR_OBJECT", NULL
},
539 { 0x0000000b, "INVALID_ADDRESS_ALIGNMENT", NULL
},
540 { 0x0000000c, "INVALID_BITFIELD", NULL
},
541 { 0x0000000d, "BEGIN_END_ACTIVE", NULL
},
542 { 0x0000000e, "SEMANTIC_COLOR_BACK_OVER_LIMIT", NULL
},
543 { 0x0000000f, "VIEWPORT_ID_NEEDS_GP", NULL
},
544 { 0x00000010, "RT_DOUBLE_BIND", NULL
},
545 { 0x00000011, "RT_TYPES_MISMATCH", NULL
},
546 { 0x00000012, "RT_LINEAR_WITH_ZETA", NULL
},
547 { 0x00000015, "FP_TOO_FEW_REGS", NULL
},
548 { 0x00000016, "ZETA_FORMAT_CSAA_MISMATCH", NULL
},
549 { 0x00000017, "RT_LINEAR_WITH_MSAA", NULL
},
550 { 0x00000018, "FP_INTERPOLANT_START_OVER_LIMIT", NULL
},
551 { 0x00000019, "SEMANTIC_LAYER_OVER_LIMIT", NULL
},
552 { 0x0000001a, "RT_INVALID_ALIGNMENT", NULL
},
553 { 0x0000001b, "SAMPLER_OVER_LIMIT", NULL
},
554 { 0x0000001c, "TEXTURE_OVER_LIMIT", NULL
},
555 { 0x0000001e, "GP_TOO_MANY_OUTPUTS", NULL
},
556 { 0x0000001f, "RT_BPP128_WITH_MS8", NULL
},
557 { 0x00000021, "Z_OUT_OF_BOUNDS", NULL
},
558 { 0x00000023, "XY_OUT_OF_BOUNDS", NULL
},
559 { 0x00000027, "CP_MORE_PARAMS_THAN_SHARED", NULL
},
560 { 0x00000028, "CP_NO_REG_SPACE_STRIPED", NULL
},
561 { 0x00000029, "CP_NO_REG_SPACE_PACKED", NULL
},
562 { 0x0000002a, "CP_NOT_ENOUGH_WARPS", NULL
},
563 { 0x0000002b, "CP_BLOCK_SIZE_MISMATCH", NULL
},
564 { 0x0000002c, "CP_NOT_ENOUGH_LOCAL_WARPS", NULL
},
565 { 0x0000002d, "CP_NOT_ENOUGH_STACK_WARPS", NULL
},
566 { 0x0000002e, "CP_NO_BLOCKDIM_LATCH", NULL
},
567 { 0x00000031, "ENG2D_FORMAT_MISMATCH", NULL
},
568 { 0x0000003f, "PRIMITIVE_ID_NEEDS_GP", NULL
},
569 { 0x00000044, "SEMANTIC_VIEWPORT_OVER_LIMIT", NULL
},
570 { 0x00000045, "SEMANTIC_COLOR_FRONT_OVER_LIMIT", NULL
},
571 { 0x00000046, "LAYER_ID_NEEDS_GP", NULL
},
572 { 0x00000047, "SEMANTIC_CLIP_OVER_LIMIT", NULL
},
573 { 0x00000048, "SEMANTIC_PTSZ_OVER_LIMIT", NULL
},
577 static struct nouveau_bitfield nv50_graph_intr
[] = {
578 { 0x00000001, "NOTIFY" },
579 { 0x00000002, "COMPUTE_QUERY" },
580 { 0x00000010, "ILLEGAL_MTHD" },
581 { 0x00000020, "ILLEGAL_CLASS" },
582 { 0x00000040, "DOUBLE_NOTIFY" },
583 { 0x00001000, "CONTEXT_SWITCH" },
584 { 0x00010000, "BUFFER_NOTIFY" },
585 { 0x00100000, "DATA_ERROR" },
586 { 0x00200000, "TRAP" },
587 { 0x01000000, "SINGLE_STEP" },
592 nv50_pgraph_mp_trap(struct drm_device
*dev
, int tpid
, int display
)
594 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
595 uint32_t units
= nv_rd32(dev
, 0x1540);
596 uint32_t addr
, mp10
, status
, pc
, oplow
, ophigh
;
599 for (i
= 0; i
< 4; i
++) {
600 if (!(units
& 1 << (i
+24)))
602 if (dev_priv
->chipset
< 0xa0)
603 addr
= 0x408200 + (tpid
<< 12) + (i
<< 7);
605 addr
= 0x408100 + (tpid
<< 11) + (i
<< 7);
606 mp10
= nv_rd32(dev
, addr
+ 0x10);
607 status
= nv_rd32(dev
, addr
+ 0x14);
611 nv_rd32(dev
, addr
+ 0x20);
612 pc
= nv_rd32(dev
, addr
+ 0x24);
613 oplow
= nv_rd32(dev
, addr
+ 0x70);
614 ophigh
= nv_rd32(dev
, addr
+ 0x74);
615 NV_INFO(dev
, "PGRAPH_TRAP_MP_EXEC - "
616 "TP %d MP %d: ", tpid
, i
);
617 nouveau_enum_print(nv50_mp_exec_error_names
, status
);
618 printk(" at %06x warp %d, opcode %08x %08x\n",
619 pc
&0xffffff, pc
>> 24,
622 nv_wr32(dev
, addr
+ 0x10, mp10
);
623 nv_wr32(dev
, addr
+ 0x14, 0);
627 NV_INFO(dev
, "PGRAPH_TRAP_MP_EXEC - TP %d: "
628 "No MPs claiming errors?\n", tpid
);
632 nv50_pgraph_tp_trap(struct drm_device
*dev
, int type
, uint32_t ustatus_old
,
633 uint32_t ustatus_new
, int display
, const char *name
)
635 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
637 uint32_t units
= nv_rd32(dev
, 0x1540);
639 uint32_t ustatus_addr
, ustatus
;
640 for (i
= 0; i
< 16; i
++) {
641 if (!(units
& (1 << i
)))
643 if (dev_priv
->chipset
< 0xa0)
644 ustatus_addr
= ustatus_old
+ (i
<< 12);
646 ustatus_addr
= ustatus_new
+ (i
<< 11);
647 ustatus
= nv_rd32(dev
, ustatus_addr
) & 0x7fffffff;
652 case 6: /* texture error... unknown for now */
654 NV_ERROR(dev
, "magic set %d:\n", i
);
655 for (r
= ustatus_addr
+ 4; r
<= ustatus_addr
+ 0x10; r
+= 4)
656 NV_ERROR(dev
, "\t0x%08x: 0x%08x\n", r
,
660 case 7: /* MP error */
661 if (ustatus
& 0x00010000) {
662 nv50_pgraph_mp_trap(dev
, i
, display
);
663 ustatus
&= ~0x00010000;
666 case 8: /* TPDMA error */
668 uint32_t e0c
= nv_rd32(dev
, ustatus_addr
+ 4);
669 uint32_t e10
= nv_rd32(dev
, ustatus_addr
+ 8);
670 uint32_t e14
= nv_rd32(dev
, ustatus_addr
+ 0xc);
671 uint32_t e18
= nv_rd32(dev
, ustatus_addr
+ 0x10);
672 uint32_t e1c
= nv_rd32(dev
, ustatus_addr
+ 0x14);
673 uint32_t e20
= nv_rd32(dev
, ustatus_addr
+ 0x18);
674 uint32_t e24
= nv_rd32(dev
, ustatus_addr
+ 0x1c);
675 /* 2d engine destination */
676 if (ustatus
& 0x00000010) {
678 NV_INFO(dev
, "PGRAPH_TRAP_TPDMA_2D - TP %d - Unknown fault at address %02x%08x\n",
680 NV_INFO(dev
, "PGRAPH_TRAP_TPDMA_2D - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
681 i
, e0c
, e18
, e1c
, e20
, e24
);
683 ustatus
&= ~0x00000010;
686 if (ustatus
& 0x00000040) {
688 NV_INFO(dev
, "PGRAPH_TRAP_TPDMA_RT - TP %d - Unknown fault at address %02x%08x\n",
690 NV_INFO(dev
, "PGRAPH_TRAP_TPDMA_RT - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
691 i
, e0c
, e18
, e1c
, e20
, e24
);
693 ustatus
&= ~0x00000040;
695 /* CUDA memory: l[], g[] or stack. */
696 if (ustatus
& 0x00000080) {
698 if (e18
& 0x80000000) {
699 /* g[] read fault? */
700 NV_INFO(dev
, "PGRAPH_TRAP_TPDMA - TP %d - Global read fault at address %02x%08x\n",
701 i
, e14
, e10
| ((e18
>> 24) & 0x1f));
703 } else if (e18
& 0xc) {
704 /* g[] write fault? */
705 NV_INFO(dev
, "PGRAPH_TRAP_TPDMA - TP %d - Global write fault at address %02x%08x\n",
706 i
, e14
, e10
| ((e18
>> 7) & 0x1f));
709 NV_INFO(dev
, "PGRAPH_TRAP_TPDMA - TP %d - Unknown CUDA fault at address %02x%08x\n",
712 NV_INFO(dev
, "PGRAPH_TRAP_TPDMA - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
713 i
, e0c
, e18
, e1c
, e20
, e24
);
715 ustatus
&= ~0x00000080;
722 NV_INFO(dev
, "%s - TP%d: Unhandled ustatus 0x%08x\n", name
, i
, ustatus
);
724 nv_wr32(dev
, ustatus_addr
, 0xc0000000);
728 NV_INFO(dev
, "%s - No TPs claiming errors?\n", name
);
732 nv50_pgraph_trap_handler(struct drm_device
*dev
, u32 display
, u64 inst
, u32 chid
)
734 u32 status
= nv_rd32(dev
, 0x400108);
737 if (!status
&& display
) {
738 NV_INFO(dev
, "PGRAPH - TRAP: no units reporting traps?\n");
742 /* DISPATCH: Relays commands to other units and handles NOTIFY,
743 * COND, QUERY. If you get a trap from it, the command is still stuck
744 * in DISPATCH and you need to do something about it. */
745 if (status
& 0x001) {
746 ustatus
= nv_rd32(dev
, 0x400804) & 0x7fffffff;
747 if (!ustatus
&& display
) {
748 NV_INFO(dev
, "PGRAPH_TRAP_DISPATCH - no ustatus?\n");
751 nv_wr32(dev
, 0x400500, 0x00000000);
753 /* Known to be triggered by screwed up NOTIFY and COND... */
754 if (ustatus
& 0x00000001) {
755 u32 addr
= nv_rd32(dev
, 0x400808);
756 u32 subc
= (addr
& 0x00070000) >> 16;
757 u32 mthd
= (addr
& 0x00001ffc);
758 u32 datal
= nv_rd32(dev
, 0x40080c);
759 u32 datah
= nv_rd32(dev
, 0x400810);
760 u32
class = nv_rd32(dev
, 0x400814);
761 u32 r848
= nv_rd32(dev
, 0x400848);
763 NV_INFO(dev
, "PGRAPH - TRAP DISPATCH_FAULT\n");
764 if (display
&& (addr
& 0x80000000)) {
765 NV_INFO(dev
, "PGRAPH - ch %d (0x%010llx) "
766 "subc %d class 0x%04x mthd 0x%04x "
768 "400808 0x%08x 400848 0x%08x\n",
769 chid
, inst
, subc
, class, mthd
, datah
,
773 NV_INFO(dev
, "PGRAPH - no stuck command?\n");
776 nv_wr32(dev
, 0x400808, 0);
777 nv_wr32(dev
, 0x4008e8, nv_rd32(dev
, 0x4008e8) & 3);
778 nv_wr32(dev
, 0x400848, 0);
779 ustatus
&= ~0x00000001;
782 if (ustatus
& 0x00000002) {
783 u32 addr
= nv_rd32(dev
, 0x40084c);
784 u32 subc
= (addr
& 0x00070000) >> 16;
785 u32 mthd
= (addr
& 0x00001ffc);
786 u32 data
= nv_rd32(dev
, 0x40085c);
787 u32
class = nv_rd32(dev
, 0x400814);
789 NV_INFO(dev
, "PGRAPH - TRAP DISPATCH_QUERY\n");
790 if (display
&& (addr
& 0x80000000)) {
791 NV_INFO(dev
, "PGRAPH - ch %d (0x%010llx) "
792 "subc %d class 0x%04x mthd 0x%04x "
793 "data 0x%08x 40084c 0x%08x\n",
794 chid
, inst
, subc
, class, mthd
,
798 NV_INFO(dev
, "PGRAPH - no stuck command?\n");
801 nv_wr32(dev
, 0x40084c, 0);
802 ustatus
&= ~0x00000002;
805 if (ustatus
&& display
) {
806 NV_INFO(dev
, "PGRAPH - TRAP_DISPATCH (unknown "
807 "0x%08x)\n", ustatus
);
810 nv_wr32(dev
, 0x400804, 0xc0000000);
811 nv_wr32(dev
, 0x400108, 0x001);
817 /* M2MF: Memory to memory copy engine. */
818 if (status
& 0x002) {
819 u32 ustatus
= nv_rd32(dev
, 0x406800) & 0x7fffffff;
821 NV_INFO(dev
, "PGRAPH - TRAP_M2MF");
822 nouveau_bitfield_print(nv50_graph_trap_m2mf
, ustatus
);
824 NV_INFO(dev
, "PGRAPH - TRAP_M2MF %08x %08x %08x %08x\n",
825 nv_rd32(dev
, 0x406804), nv_rd32(dev
, 0x406808),
826 nv_rd32(dev
, 0x40680c), nv_rd32(dev
, 0x406810));
830 /* No sane way found yet -- just reset the bugger. */
831 nv_wr32(dev
, 0x400040, 2);
832 nv_wr32(dev
, 0x400040, 0);
833 nv_wr32(dev
, 0x406800, 0xc0000000);
834 nv_wr32(dev
, 0x400108, 0x002);
838 /* VFETCH: Fetches data from vertex buffers. */
839 if (status
& 0x004) {
840 u32 ustatus
= nv_rd32(dev
, 0x400c04) & 0x7fffffff;
842 NV_INFO(dev
, "PGRAPH - TRAP_VFETCH");
843 nouveau_bitfield_print(nv50_graph_trap_vfetch
, ustatus
);
845 NV_INFO(dev
, "PGRAPH - TRAP_VFETCH %08x %08x %08x %08x\n",
846 nv_rd32(dev
, 0x400c00), nv_rd32(dev
, 0x400c08),
847 nv_rd32(dev
, 0x400c0c), nv_rd32(dev
, 0x400c10));
850 nv_wr32(dev
, 0x400c04, 0xc0000000);
851 nv_wr32(dev
, 0x400108, 0x004);
855 /* STRMOUT: DirectX streamout / OpenGL transform feedback. */
856 if (status
& 0x008) {
857 ustatus
= nv_rd32(dev
, 0x401800) & 0x7fffffff;
859 NV_INFO(dev
, "PGRAPH - TRAP_STRMOUT");
860 nouveau_bitfield_print(nv50_graph_trap_strmout
, ustatus
);
862 NV_INFO(dev
, "PGRAPH - TRAP_STRMOUT %08x %08x %08x %08x\n",
863 nv_rd32(dev
, 0x401804), nv_rd32(dev
, 0x401808),
864 nv_rd32(dev
, 0x40180c), nv_rd32(dev
, 0x401810));
868 /* No sane way found yet -- just reset the bugger. */
869 nv_wr32(dev
, 0x400040, 0x80);
870 nv_wr32(dev
, 0x400040, 0);
871 nv_wr32(dev
, 0x401800, 0xc0000000);
872 nv_wr32(dev
, 0x400108, 0x008);
876 /* CCACHE: Handles code and c[] caches and fills them. */
877 if (status
& 0x010) {
878 ustatus
= nv_rd32(dev
, 0x405018) & 0x7fffffff;
880 NV_INFO(dev
, "PGRAPH - TRAP_CCACHE");
881 nouveau_bitfield_print(nv50_graph_trap_ccache
, ustatus
);
883 NV_INFO(dev
, "PGRAPH - TRAP_CCACHE %08x %08x %08x %08x"
885 nv_rd32(dev
, 0x405000), nv_rd32(dev
, 0x405004),
886 nv_rd32(dev
, 0x405008), nv_rd32(dev
, 0x40500c),
887 nv_rd32(dev
, 0x405010), nv_rd32(dev
, 0x405014),
888 nv_rd32(dev
, 0x40501c));
892 nv_wr32(dev
, 0x405018, 0xc0000000);
893 nv_wr32(dev
, 0x400108, 0x010);
897 /* Unknown, not seen yet... 0x402000 is the only trap status reg
898 * remaining, so try to handle it anyway. Perhaps related to that
899 * unknown DMA slot on tesla? */
901 ustatus
= nv_rd32(dev
, 0x402000) & 0x7fffffff;
903 NV_INFO(dev
, "PGRAPH - TRAP_UNKC04 0x%08x\n", ustatus
);
904 nv_wr32(dev
, 0x402000, 0xc0000000);
905 /* no status modifiction on purpose */
908 /* TEXTURE: CUDA texturing units */
909 if (status
& 0x040) {
910 nv50_pgraph_tp_trap(dev
, 6, 0x408900, 0x408600, display
,
911 "PGRAPH - TRAP_TEXTURE");
912 nv_wr32(dev
, 0x400108, 0x040);
916 /* MP: CUDA execution engines. */
917 if (status
& 0x080) {
918 nv50_pgraph_tp_trap(dev
, 7, 0x408314, 0x40831c, display
,
920 nv_wr32(dev
, 0x400108, 0x080);
924 /* TPDMA: Handles TP-initiated uncached memory accesses:
925 * l[], g[], stack, 2d surfaces, render targets. */
926 if (status
& 0x100) {
927 nv50_pgraph_tp_trap(dev
, 8, 0x408e08, 0x408708, display
,
928 "PGRAPH - TRAP_TPDMA");
929 nv_wr32(dev
, 0x400108, 0x100);
935 NV_INFO(dev
, "PGRAPH - TRAP: unknown 0x%08x\n", status
);
936 nv_wr32(dev
, 0x400108, status
);
943 nv50_graph_isr_chid(struct drm_device
*dev
, u64 inst
)
945 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
946 struct nouveau_channel
*chan
;
950 spin_lock_irqsave(&dev_priv
->channels
.lock
, flags
);
951 for (i
= 0; i
< dev_priv
->engine
.fifo
.channels
; i
++) {
952 chan
= dev_priv
->channels
.ptr
[i
];
953 if (!chan
|| !chan
->ramin
)
956 if (inst
== chan
->ramin
->vinst
)
959 spin_unlock_irqrestore(&dev_priv
->channels
.lock
, flags
);
964 nv50_graph_isr(struct drm_device
*dev
)
968 while ((stat
= nv_rd32(dev
, 0x400100))) {
969 u64 inst
= (u64
)(nv_rd32(dev
, 0x40032c) & 0x0fffffff) << 12;
970 u32 chid
= nv50_graph_isr_chid(dev
, inst
);
971 u32 addr
= nv_rd32(dev
, NV04_PGRAPH_TRAPPED_ADDR
);
972 u32 subc
= (addr
& 0x00070000) >> 16;
973 u32 mthd
= (addr
& 0x00001ffc);
974 u32 data
= nv_rd32(dev
, NV04_PGRAPH_TRAPPED_DATA
);
975 u32
class = nv_rd32(dev
, 0x400814);
978 if (stat
& 0x00000010) {
979 if (!nouveau_gpuobj_mthd_call2(dev
, chid
, class,
984 if (stat
& 0x00001000) {
985 nv_wr32(dev
, 0x400500, 0x00000000);
986 nv_wr32(dev
, 0x400100, 0x00001000);
987 nv_mask(dev
, 0x40013c, 0x00001000, 0x00000000);
988 nv50_graph_context_switch(dev
);
993 show
= (show
&& nouveau_ratelimit()) ? show
: 0;
995 if (show
& 0x00100000) {
996 u32 ecode
= nv_rd32(dev
, 0x400110);
997 NV_INFO(dev
, "PGRAPH - DATA_ERROR ");
998 nouveau_enum_print(nv50_data_error_names
, ecode
);
1002 if (stat
& 0x00200000) {
1003 if (!nv50_pgraph_trap_handler(dev
, show
, inst
, chid
))
1004 show
&= ~0x00200000;
1007 nv_wr32(dev
, 0x400100, stat
);
1008 nv_wr32(dev
, 0x400500, 0x00010001);
1011 NV_INFO(dev
, "PGRAPH -");
1012 nouveau_bitfield_print(nv50_graph_intr
, show
);
1014 NV_INFO(dev
, "PGRAPH - ch %d (0x%010llx) subc %d "
1015 "class 0x%04x mthd 0x%04x data 0x%08x\n",
1016 chid
, inst
, subc
, class, mthd
, data
);
1017 nv50_fb_vm_trap(dev
, 1);
1021 if (nv_rd32(dev
, 0x400824) & (1 << 31))
1022 nv_wr32(dev
, 0x400824, nv_rd32(dev
, 0x400824) & ~(1 << 31));
1026 nv50_graph_destroy(struct drm_device
*dev
, int engine
)
1028 struct nv50_graph_engine
*pgraph
= nv_engine(dev
, engine
);
1030 NVOBJ_ENGINE_DEL(dev
, GR
);
1032 nouveau_irq_unregister(dev
, 12);
1037 nv50_graph_create(struct drm_device
*dev
)
1039 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
1040 struct nv50_graph_engine
*pgraph
;
1041 struct nouveau_grctx ctx
= {};
1044 pgraph
= kzalloc(sizeof(*pgraph
),GFP_KERNEL
);
1049 ctx
.mode
= NOUVEAU_GRCTX_PROG
;
1050 ctx
.data
= pgraph
->ctxprog
;
1051 ctx
.ctxprog_max
= ARRAY_SIZE(pgraph
->ctxprog
);
1053 ret
= nv50_grctx_init(&ctx
);
1055 NV_ERROR(dev
, "PGRAPH: ctxprog build failed\n");
1060 pgraph
->grctx_size
= ctx
.ctxvals_pos
* 4;
1061 pgraph
->ctxprog_size
= ctx
.ctxprog_len
;
1063 pgraph
->base
.destroy
= nv50_graph_destroy
;
1064 pgraph
->base
.init
= nv50_graph_init
;
1065 pgraph
->base
.fini
= nv50_graph_fini
;
1066 pgraph
->base
.context_new
= nv50_graph_context_new
;
1067 pgraph
->base
.context_del
= nv50_graph_context_del
;
1068 pgraph
->base
.object_new
= nv50_graph_object_new
;
1069 if (dev_priv
->chipset
== 0x50 || dev_priv
->chipset
== 0xac)
1070 pgraph
->base
.tlb_flush
= nv50_graph_tlb_flush
;
1072 pgraph
->base
.tlb_flush
= nv84_graph_tlb_flush
;
1074 nouveau_irq_register(dev
, 12, nv50_graph_isr
);
1076 /* NVSW really doesn't live here... */
1077 NVOBJ_CLASS(dev
, 0x506e, SW
); /* nvsw */
1078 NVOBJ_MTHD (dev
, 0x506e, 0x018c, nv50_graph_nvsw_dma_vblsem
);
1079 NVOBJ_MTHD (dev
, 0x506e, 0x0400, nv50_graph_nvsw_vblsem_offset
);
1080 NVOBJ_MTHD (dev
, 0x506e, 0x0404, nv50_graph_nvsw_vblsem_release_val
);
1081 NVOBJ_MTHD (dev
, 0x506e, 0x0408, nv50_graph_nvsw_vblsem_release
);
1082 NVOBJ_MTHD (dev
, 0x506e, 0x0500, nv50_graph_nvsw_mthd_page_flip
);
1084 NVOBJ_ENGINE_ADD(dev
, GR
, &pgraph
->base
);
1085 NVOBJ_CLASS(dev
, 0x0030, GR
); /* null */
1086 NVOBJ_CLASS(dev
, 0x5039, GR
); /* m2mf */
1087 NVOBJ_CLASS(dev
, 0x502d, GR
); /* 2d */
1090 if (dev_priv
->chipset
== 0x50)
1091 NVOBJ_CLASS(dev
, 0x5097, GR
); /* tesla (nv50) */
1093 if (dev_priv
->chipset
< 0xa0)
1094 NVOBJ_CLASS(dev
, 0x8297, GR
); /* tesla (nv8x/nv9x) */
1096 switch (dev_priv
->chipset
) {
1100 NVOBJ_CLASS(dev
, 0x8397, GR
);
1105 NVOBJ_CLASS(dev
, 0x8597, GR
);
1108 NVOBJ_CLASS(dev
, 0x8697, GR
);
1114 NVOBJ_CLASS(dev
, 0x50c0, GR
);
1115 if (dev_priv
->chipset
> 0xa0 &&
1116 dev_priv
->chipset
!= 0xaa &&
1117 dev_priv
->chipset
!= 0xac)
1118 NVOBJ_CLASS(dev
, 0x85c0, GR
);