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);
130 nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) & ~pmc_e);
131 nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) | pmc_e);
135 nv50_graph_init_intr(struct drm_device *dev)
139 nv_wr32(dev, NV03_PGRAPH_INTR, 0xffffffff);
140 nv_wr32(dev, 0x400138, 0xffffffff);
141 nv_wr32(dev, NV40_PGRAPH_INTR_EN, 0xffffffff);
145 nv50_graph_init_regs__nv(struct drm_device *dev)
147 struct drm_nouveau_private *dev_priv = dev->dev_private;
148 uint32_t units = nv_rd32(dev, 0x1540);
153 nv_wr32(dev, 0x400804, 0xc0000000);
154 nv_wr32(dev, 0x406800, 0xc0000000);
155 nv_wr32(dev, 0x400c04, 0xc0000000);
156 nv_wr32(dev, 0x401800, 0xc0000000);
157 nv_wr32(dev, 0x405018, 0xc0000000);
158 nv_wr32(dev, 0x402000, 0xc0000000);
160 for (i = 0; i < 16; i++) {
161 if (units & 1 << i) {
162 if (dev_priv->chipset < 0xa0) {
163 nv_wr32(dev, 0x408900 + (i << 12), 0xc0000000);
164 nv_wr32(dev, 0x408e08 + (i << 12), 0xc0000000);
165 nv_wr32(dev, 0x408314 + (i << 12), 0xc0000000);
167 nv_wr32(dev, 0x408600 + (i << 11), 0xc0000000);
168 nv_wr32(dev, 0x408708 + (i << 11), 0xc0000000);
169 nv_wr32(dev, 0x40831c + (i << 11), 0xc0000000);
174 nv_wr32(dev, 0x400108, 0xffffffff);
176 nv_wr32(dev, 0x400824, 0x00004000);
177 nv_wr32(dev, 0x400500, 0x00010001);
181 nv50_graph_init_zcull(struct drm_device *dev)
183 struct drm_nouveau_private *dev_priv = dev->dev_private;
188 switch (dev_priv->chipset & 0xf0) {
192 nv_wr32(dev, 0x402ca8, 0x00000800);
196 nv_wr32(dev, 0x402cc0, 0x00000000);
197 if (dev_priv->chipset == 0xa0 ||
198 dev_priv->chipset == 0xaa ||
199 dev_priv->chipset == 0xac) {
200 nv_wr32(dev, 0x402ca8, 0x00000802);
202 nv_wr32(dev, 0x402cc0, 0x00000000);
203 nv_wr32(dev, 0x402ca8, 0x00000002);
209 /* zero out zcull regions */
210 for (i = 0; i < 8; i++) {
211 nv_wr32(dev, 0x402c20 + (i * 8), 0x00000000);
212 nv_wr32(dev, 0x402c24 + (i * 8), 0x00000000);
213 nv_wr32(dev, 0x402c28 + (i * 8), 0x00000000);
214 nv_wr32(dev, 0x402c2c + (i * 8), 0x00000000);
219 nv50_graph_init_ctxctl(struct drm_device *dev)
221 struct nv50_graph_engine *pgraph = nv_engine(dev, NVOBJ_ENGINE_GR);
226 nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0);
227 for (i = 0; i < pgraph->ctxprog_size; i++)
228 nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_DATA, pgraph->ctxprog[i]);
230 nv_wr32(dev, 0x40008c, 0x00000004); /* HW_CTX_SWITCH_ENABLED */
231 nv_wr32(dev, 0x400320, 4);
232 nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, 0);
233 nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, 0);
238 nv50_graph_init(struct drm_device *dev, int engine)
244 nv50_graph_init_reset(dev);
245 nv50_graph_init_regs__nv(dev);
246 nv50_graph_init_zcull(dev);
248 ret = nv50_graph_init_ctxctl(dev);
252 nv50_graph_init_intr(dev);
257 nv50_graph_fini(struct drm_device *dev, int engine, bool suspend)
259 nv50_graph_unload_context(dev);
260 nv_wr32(dev, 0x40013c, 0x00000000);
265 nv50_graph_context_new(struct nouveau_channel *chan, int engine)
267 struct drm_device *dev = chan->dev;
268 struct drm_nouveau_private *dev_priv = dev->dev_private;
269 struct nouveau_gpuobj *ramin = chan->ramin;
270 struct nouveau_gpuobj *grctx = NULL;
271 struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
272 struct nouveau_grctx ctx = {};
275 NV_DEBUG(dev, "ch%d\n", chan->id);
277 ret = nouveau_gpuobj_new(dev, NULL, pgraph->grctx_size, 0,
278 NVOBJ_FLAG_ZERO_ALLOC |
279 NVOBJ_FLAG_ZERO_FREE, &grctx);
283 hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
284 nv_wo32(ramin, hdr + 0x00, 0x00190002);
285 nv_wo32(ramin, hdr + 0x04, grctx->vinst + grctx->size - 1);
286 nv_wo32(ramin, hdr + 0x08, grctx->vinst);
287 nv_wo32(ramin, hdr + 0x0c, 0);
288 nv_wo32(ramin, hdr + 0x10, 0);
289 nv_wo32(ramin, hdr + 0x14, 0x00010000);
292 ctx.mode = NOUVEAU_GRCTX_VALS;
294 nv50_grctx_init(&ctx);
296 nv_wo32(grctx, 0x00000, chan->ramin->vinst >> 12);
298 dev_priv->engine.instmem.flush(dev);
300 atomic_inc(&chan->vm->engref[NVOBJ_ENGINE_GR]);
301 chan->engctx[NVOBJ_ENGINE_GR] = grctx;
306 nv50_graph_context_del(struct nouveau_channel *chan, int engine)
308 struct nouveau_gpuobj *grctx = chan->engctx[engine];
309 struct drm_device *dev = chan->dev;
310 struct drm_nouveau_private *dev_priv = dev->dev_private;
311 struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
312 int i, hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
315 NV_DEBUG(dev, "ch%d\n", chan->id);
320 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
321 pfifo->reassign(dev, false);
322 nv50_graph_fifo_access(dev, false);
324 if (nv50_graph_channel(dev) == chan)
325 nv50_graph_unload_context(dev);
327 for (i = hdr; i < hdr + 24; i += 4)
328 nv_wo32(chan->ramin, i, 0);
329 dev_priv->engine.instmem.flush(dev);
331 nv50_graph_fifo_access(dev, true);
332 pfifo->reassign(dev, true);
333 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
335 nouveau_gpuobj_ref(NULL, &grctx);
337 atomic_dec(&chan->vm->engref[engine]);
338 chan->engctx[engine] = NULL;
342 nv50_graph_object_new(struct nouveau_channel *chan, int engine,
343 u32 handle, u16 class)
345 struct drm_device *dev = chan->dev;
346 struct drm_nouveau_private *dev_priv = dev->dev_private;
347 struct nouveau_gpuobj *obj = NULL;
350 ret = nouveau_gpuobj_new(dev, chan, 16, 16, NVOBJ_FLAG_ZERO_FREE, &obj);
356 nv_wo32(obj, 0x00, class);
357 nv_wo32(obj, 0x04, 0x00000000);
358 nv_wo32(obj, 0x08, 0x00000000);
359 nv_wo32(obj, 0x0c, 0x00000000);
360 dev_priv->engine.instmem.flush(dev);
362 ret = nouveau_ramht_insert(chan, handle, obj);
363 nouveau_gpuobj_ref(NULL, &obj);
368 nv50_graph_context_switch(struct drm_device *dev)
372 nv50_graph_unload_context(dev);
374 inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_NEXT);
375 inst &= NV50_PGRAPH_CTXCTL_NEXT_INSTANCE;
376 nv50_graph_do_load_context(dev, inst);
378 nv_wr32(dev, NV40_PGRAPH_INTR_EN, nv_rd32(dev,
379 NV40_PGRAPH_INTR_EN) | NV_PGRAPH_INTR_CONTEXT_SWITCH);
383 nv50_graph_nvsw_dma_vblsem(struct nouveau_channel *chan,
384 u32 class, u32 mthd, u32 data)
386 struct nouveau_gpuobj *gpuobj;
388 gpuobj = nouveau_ramht_find(chan, data);
392 if (nouveau_notifier_offset(gpuobj, NULL))
395 chan->nvsw.vblsem = gpuobj;
396 chan->nvsw.vblsem_offset = ~0;
401 nv50_graph_nvsw_vblsem_offset(struct nouveau_channel *chan,
402 u32 class, u32 mthd, u32 data)
404 if (nouveau_notifier_offset(chan->nvsw.vblsem, &data))
407 chan->nvsw.vblsem_offset = data >> 2;
412 nv50_graph_nvsw_vblsem_release_val(struct nouveau_channel *chan,
413 u32 class, u32 mthd, u32 data)
415 chan->nvsw.vblsem_rval = data;
420 nv50_graph_nvsw_vblsem_release(struct nouveau_channel *chan,
421 u32 class, u32 mthd, u32 data)
423 struct drm_device *dev = chan->dev;
424 struct drm_nouveau_private *dev_priv = dev->dev_private;
426 if (!chan->nvsw.vblsem || chan->nvsw.vblsem_offset == ~0 || data > 1)
429 drm_vblank_get(dev, data);
431 chan->nvsw.vblsem_head = data;
432 list_add(&chan->nvsw.vbl_wait, &dev_priv->vbl_waiting);
438 nv50_graph_nvsw_mthd_page_flip(struct nouveau_channel *chan,
439 u32 class, u32 mthd, u32 data)
441 nouveau_finish_page_flip(chan, NULL);
447 nv50_graph_tlb_flush(struct drm_device *dev, int engine)
449 nv50_vm_flush_engine(dev, 0);
453 nv84_graph_tlb_flush(struct drm_device *dev, int engine)
455 struct drm_nouveau_private *dev_priv = dev->dev_private;
456 struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer;
457 bool idle, timeout = false;
462 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
463 nv_mask(dev, 0x400500, 0x00000001, 0x00000000);
465 start = ptimer->read(dev);
469 for (tmp = nv_rd32(dev, 0x400380); tmp && idle; tmp >>= 3) {
474 for (tmp = nv_rd32(dev, 0x400384); tmp && idle; tmp >>= 3) {
479 for (tmp = nv_rd32(dev, 0x400388); tmp && idle; tmp >>= 3) {
483 } while (!idle && !(timeout = ptimer->read(dev) - start > 2000000000));
486 NV_ERROR(dev, "PGRAPH TLB flush idle timeout fail: "
487 "0x%08x 0x%08x 0x%08x 0x%08x\n",
488 nv_rd32(dev, 0x400700), nv_rd32(dev, 0x400380),
489 nv_rd32(dev, 0x400384), nv_rd32(dev, 0x400388));
492 nv50_vm_flush_engine(dev, 0);
494 nv_mask(dev, 0x400500, 0x00000001, 0x00000001);
495 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
498 static struct nouveau_enum nv50_mp_exec_error_names[] = {
499 { 3, "STACK_UNDERFLOW", NULL },
500 { 4, "QUADON_ACTIVE", NULL },
501 { 8, "TIMEOUT", NULL },
502 { 0x10, "INVALID_OPCODE", NULL },
503 { 0x40, "BREAKPOINT", NULL },
507 static struct nouveau_bitfield nv50_graph_trap_m2mf[] = {
508 { 0x00000001, "NOTIFY" },
509 { 0x00000002, "IN" },
510 { 0x00000004, "OUT" },
514 static struct nouveau_bitfield nv50_graph_trap_vfetch[] = {
515 { 0x00000001, "FAULT" },
519 static struct nouveau_bitfield nv50_graph_trap_strmout[] = {
520 { 0x00000001, "FAULT" },
524 static struct nouveau_bitfield nv50_graph_trap_ccache[] = {
525 { 0x00000001, "FAULT" },
529 /* There must be a *lot* of these. Will take some time to gather them up. */
530 struct nouveau_enum nv50_data_error_names[] = {
531 { 0x00000003, "INVALID_QUERY_OR_TEXTURE", NULL },
532 { 0x00000004, "INVALID_VALUE", NULL },
533 { 0x00000005, "INVALID_ENUM", NULL },
534 { 0x00000008, "INVALID_OBJECT", NULL },
535 { 0x00000009, "READ_ONLY_OBJECT", NULL },
536 { 0x0000000a, "SUPERVISOR_OBJECT", NULL },
537 { 0x0000000b, "INVALID_ADDRESS_ALIGNMENT", NULL },
538 { 0x0000000c, "INVALID_BITFIELD", NULL },
539 { 0x0000000d, "BEGIN_END_ACTIVE", NULL },
540 { 0x0000000e, "SEMANTIC_COLOR_BACK_OVER_LIMIT", NULL },
541 { 0x0000000f, "VIEWPORT_ID_NEEDS_GP", NULL },
542 { 0x00000010, "RT_DOUBLE_BIND", NULL },
543 { 0x00000011, "RT_TYPES_MISMATCH", NULL },
544 { 0x00000012, "RT_LINEAR_WITH_ZETA", NULL },
545 { 0x00000015, "FP_TOO_FEW_REGS", NULL },
546 { 0x00000016, "ZETA_FORMAT_CSAA_MISMATCH", NULL },
547 { 0x00000017, "RT_LINEAR_WITH_MSAA", NULL },
548 { 0x00000018, "FP_INTERPOLANT_START_OVER_LIMIT", NULL },
549 { 0x00000019, "SEMANTIC_LAYER_OVER_LIMIT", NULL },
550 { 0x0000001a, "RT_INVALID_ALIGNMENT", NULL },
551 { 0x0000001b, "SAMPLER_OVER_LIMIT", NULL },
552 { 0x0000001c, "TEXTURE_OVER_LIMIT", NULL },
553 { 0x0000001e, "GP_TOO_MANY_OUTPUTS", NULL },
554 { 0x0000001f, "RT_BPP128_WITH_MS8", NULL },
555 { 0x00000021, "Z_OUT_OF_BOUNDS", NULL },
556 { 0x00000023, "XY_OUT_OF_BOUNDS", NULL },
557 { 0x00000027, "CP_MORE_PARAMS_THAN_SHARED", NULL },
558 { 0x00000028, "CP_NO_REG_SPACE_STRIPED", NULL },
559 { 0x00000029, "CP_NO_REG_SPACE_PACKED", NULL },
560 { 0x0000002a, "CP_NOT_ENOUGH_WARPS", NULL },
561 { 0x0000002b, "CP_BLOCK_SIZE_MISMATCH", NULL },
562 { 0x0000002c, "CP_NOT_ENOUGH_LOCAL_WARPS", NULL },
563 { 0x0000002d, "CP_NOT_ENOUGH_STACK_WARPS", NULL },
564 { 0x0000002e, "CP_NO_BLOCKDIM_LATCH", NULL },
565 { 0x00000031, "ENG2D_FORMAT_MISMATCH", NULL },
566 { 0x0000003f, "PRIMITIVE_ID_NEEDS_GP", NULL },
567 { 0x00000044, "SEMANTIC_VIEWPORT_OVER_LIMIT", NULL },
568 { 0x00000045, "SEMANTIC_COLOR_FRONT_OVER_LIMIT", NULL },
569 { 0x00000046, "LAYER_ID_NEEDS_GP", NULL },
570 { 0x00000047, "SEMANTIC_CLIP_OVER_LIMIT", NULL },
571 { 0x00000048, "SEMANTIC_PTSZ_OVER_LIMIT", NULL },
575 static struct nouveau_bitfield nv50_graph_intr[] = {
576 { 0x00000001, "NOTIFY" },
577 { 0x00000002, "COMPUTE_QUERY" },
578 { 0x00000010, "ILLEGAL_MTHD" },
579 { 0x00000020, "ILLEGAL_CLASS" },
580 { 0x00000040, "DOUBLE_NOTIFY" },
581 { 0x00001000, "CONTEXT_SWITCH" },
582 { 0x00010000, "BUFFER_NOTIFY" },
583 { 0x00100000, "DATA_ERROR" },
584 { 0x00200000, "TRAP" },
585 { 0x01000000, "SINGLE_STEP" },
590 nv50_pgraph_mp_trap(struct drm_device *dev, int tpid, int display)
592 struct drm_nouveau_private *dev_priv = dev->dev_private;
593 uint32_t units = nv_rd32(dev, 0x1540);
594 uint32_t addr, mp10, status, pc, oplow, ophigh;
597 for (i = 0; i < 4; i++) {
598 if (!(units & 1 << (i+24)))
600 if (dev_priv->chipset < 0xa0)
601 addr = 0x408200 + (tpid << 12) + (i << 7);
603 addr = 0x408100 + (tpid << 11) + (i << 7);
604 mp10 = nv_rd32(dev, addr + 0x10);
605 status = nv_rd32(dev, addr + 0x14);
609 nv_rd32(dev, addr + 0x20);
610 pc = nv_rd32(dev, addr + 0x24);
611 oplow = nv_rd32(dev, addr + 0x70);
612 ophigh = nv_rd32(dev, addr + 0x74);
613 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - "
614 "TP %d MP %d: ", tpid, i);
615 nouveau_enum_print(nv50_mp_exec_error_names, status);
616 printk(" at %06x warp %d, opcode %08x %08x\n",
617 pc&0xffffff, pc >> 24,
620 nv_wr32(dev, addr + 0x10, mp10);
621 nv_wr32(dev, addr + 0x14, 0);
625 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - TP %d: "
626 "No MPs claiming errors?\n", tpid);
630 nv50_pgraph_tp_trap(struct drm_device *dev, int type, uint32_t ustatus_old,
631 uint32_t ustatus_new, int display, const char *name)
633 struct drm_nouveau_private *dev_priv = dev->dev_private;
635 uint32_t units = nv_rd32(dev, 0x1540);
637 uint32_t ustatus_addr, ustatus;
638 for (i = 0; i < 16; i++) {
639 if (!(units & (1 << i)))
641 if (dev_priv->chipset < 0xa0)
642 ustatus_addr = ustatus_old + (i << 12);
644 ustatus_addr = ustatus_new + (i << 11);
645 ustatus = nv_rd32(dev, ustatus_addr) & 0x7fffffff;
650 case 6: /* texture error... unknown for now */
652 NV_ERROR(dev, "magic set %d:\n", i);
653 for (r = ustatus_addr + 4; r <= ustatus_addr + 0x10; r += 4)
654 NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r,
658 case 7: /* MP error */
659 if (ustatus & 0x00010000) {
660 nv50_pgraph_mp_trap(dev, i, display);
661 ustatus &= ~0x00010000;
664 case 8: /* TPDMA error */
666 uint32_t e0c = nv_rd32(dev, ustatus_addr + 4);
667 uint32_t e10 = nv_rd32(dev, ustatus_addr + 8);
668 uint32_t e14 = nv_rd32(dev, ustatus_addr + 0xc);
669 uint32_t e18 = nv_rd32(dev, ustatus_addr + 0x10);
670 uint32_t e1c = nv_rd32(dev, ustatus_addr + 0x14);
671 uint32_t e20 = nv_rd32(dev, ustatus_addr + 0x18);
672 uint32_t e24 = nv_rd32(dev, ustatus_addr + 0x1c);
673 /* 2d engine destination */
674 if (ustatus & 0x00000010) {
676 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - Unknown fault at address %02x%08x\n",
678 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
679 i, e0c, e18, e1c, e20, e24);
681 ustatus &= ~0x00000010;
684 if (ustatus & 0x00000040) {
686 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - Unknown fault at address %02x%08x\n",
688 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
689 i, e0c, e18, e1c, e20, e24);
691 ustatus &= ~0x00000040;
693 /* CUDA memory: l[], g[] or stack. */
694 if (ustatus & 0x00000080) {
696 if (e18 & 0x80000000) {
697 /* g[] read fault? */
698 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global read fault at address %02x%08x\n",
699 i, e14, e10 | ((e18 >> 24) & 0x1f));
701 } else if (e18 & 0xc) {
702 /* g[] write fault? */
703 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global write fault at address %02x%08x\n",
704 i, e14, e10 | ((e18 >> 7) & 0x1f));
707 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Unknown CUDA fault at address %02x%08x\n",
710 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
711 i, e0c, e18, e1c, e20, e24);
713 ustatus &= ~0x00000080;
720 NV_INFO(dev, "%s - TP%d: Unhandled ustatus 0x%08x\n", name, i, ustatus);
722 nv_wr32(dev, ustatus_addr, 0xc0000000);
726 NV_INFO(dev, "%s - No TPs claiming errors?\n", name);
730 nv50_pgraph_trap_handler(struct drm_device *dev, u32 display, u64 inst, u32 chid)
732 u32 status = nv_rd32(dev, 0x400108);
735 if (!status && display) {
736 NV_INFO(dev, "PGRAPH - TRAP: no units reporting traps?\n");
740 /* DISPATCH: Relays commands to other units and handles NOTIFY,
741 * COND, QUERY. If you get a trap from it, the command is still stuck
742 * in DISPATCH and you need to do something about it. */
743 if (status & 0x001) {
744 ustatus = nv_rd32(dev, 0x400804) & 0x7fffffff;
745 if (!ustatus && display) {
746 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - no ustatus?\n");
749 nv_wr32(dev, 0x400500, 0x00000000);
751 /* Known to be triggered by screwed up NOTIFY and COND... */
752 if (ustatus & 0x00000001) {
753 u32 addr = nv_rd32(dev, 0x400808);
754 u32 subc = (addr & 0x00070000) >> 16;
755 u32 mthd = (addr & 0x00001ffc);
756 u32 datal = nv_rd32(dev, 0x40080c);
757 u32 datah = nv_rd32(dev, 0x400810);
758 u32 class = nv_rd32(dev, 0x400814);
759 u32 r848 = nv_rd32(dev, 0x400848);
761 NV_INFO(dev, "PGRAPH - TRAP DISPATCH_FAULT\n");
762 if (display && (addr & 0x80000000)) {
763 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
764 "subc %d class 0x%04x mthd 0x%04x "
766 "400808 0x%08x 400848 0x%08x\n",
767 chid, inst, subc, class, mthd, datah,
771 NV_INFO(dev, "PGRAPH - no stuck command?\n");
774 nv_wr32(dev, 0x400808, 0);
775 nv_wr32(dev, 0x4008e8, nv_rd32(dev, 0x4008e8) & 3);
776 nv_wr32(dev, 0x400848, 0);
777 ustatus &= ~0x00000001;
780 if (ustatus & 0x00000002) {
781 u32 addr = nv_rd32(dev, 0x40084c);
782 u32 subc = (addr & 0x00070000) >> 16;
783 u32 mthd = (addr & 0x00001ffc);
784 u32 data = nv_rd32(dev, 0x40085c);
785 u32 class = nv_rd32(dev, 0x400814);
787 NV_INFO(dev, "PGRAPH - TRAP DISPATCH_QUERY\n");
788 if (display && (addr & 0x80000000)) {
789 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
790 "subc %d class 0x%04x mthd 0x%04x "
791 "data 0x%08x 40084c 0x%08x\n",
792 chid, inst, subc, class, mthd,
796 NV_INFO(dev, "PGRAPH - no stuck command?\n");
799 nv_wr32(dev, 0x40084c, 0);
800 ustatus &= ~0x00000002;
803 if (ustatus && display) {
804 NV_INFO(dev, "PGRAPH - TRAP_DISPATCH (unknown "
805 "0x%08x)\n", ustatus);
808 nv_wr32(dev, 0x400804, 0xc0000000);
809 nv_wr32(dev, 0x400108, 0x001);
815 /* M2MF: Memory to memory copy engine. */
816 if (status & 0x002) {
817 u32 ustatus = nv_rd32(dev, 0x406800) & 0x7fffffff;
819 NV_INFO(dev, "PGRAPH - TRAP_M2MF");
820 nouveau_bitfield_print(nv50_graph_trap_m2mf, ustatus);
822 NV_INFO(dev, "PGRAPH - TRAP_M2MF %08x %08x %08x %08x\n",
823 nv_rd32(dev, 0x406804), nv_rd32(dev, 0x406808),
824 nv_rd32(dev, 0x40680c), nv_rd32(dev, 0x406810));
828 /* No sane way found yet -- just reset the bugger. */
829 nv_wr32(dev, 0x400040, 2);
830 nv_wr32(dev, 0x400040, 0);
831 nv_wr32(dev, 0x406800, 0xc0000000);
832 nv_wr32(dev, 0x400108, 0x002);
836 /* VFETCH: Fetches data from vertex buffers. */
837 if (status & 0x004) {
838 u32 ustatus = nv_rd32(dev, 0x400c04) & 0x7fffffff;
840 NV_INFO(dev, "PGRAPH - TRAP_VFETCH");
841 nouveau_bitfield_print(nv50_graph_trap_vfetch, ustatus);
843 NV_INFO(dev, "PGRAPH - TRAP_VFETCH %08x %08x %08x %08x\n",
844 nv_rd32(dev, 0x400c00), nv_rd32(dev, 0x400c08),
845 nv_rd32(dev, 0x400c0c), nv_rd32(dev, 0x400c10));
848 nv_wr32(dev, 0x400c04, 0xc0000000);
849 nv_wr32(dev, 0x400108, 0x004);
853 /* STRMOUT: DirectX streamout / OpenGL transform feedback. */
854 if (status & 0x008) {
855 ustatus = nv_rd32(dev, 0x401800) & 0x7fffffff;
857 NV_INFO(dev, "PGRAPH - TRAP_STRMOUT");
858 nouveau_bitfield_print(nv50_graph_trap_strmout, ustatus);
860 NV_INFO(dev, "PGRAPH - TRAP_STRMOUT %08x %08x %08x %08x\n",
861 nv_rd32(dev, 0x401804), nv_rd32(dev, 0x401808),
862 nv_rd32(dev, 0x40180c), nv_rd32(dev, 0x401810));
866 /* No sane way found yet -- just reset the bugger. */
867 nv_wr32(dev, 0x400040, 0x80);
868 nv_wr32(dev, 0x400040, 0);
869 nv_wr32(dev, 0x401800, 0xc0000000);
870 nv_wr32(dev, 0x400108, 0x008);
874 /* CCACHE: Handles code and c[] caches and fills them. */
875 if (status & 0x010) {
876 ustatus = nv_rd32(dev, 0x405018) & 0x7fffffff;
878 NV_INFO(dev, "PGRAPH - TRAP_CCACHE");
879 nouveau_bitfield_print(nv50_graph_trap_ccache, ustatus);
881 NV_INFO(dev, "PGRAPH - TRAP_CCACHE %08x %08x %08x %08x"
883 nv_rd32(dev, 0x405000), nv_rd32(dev, 0x405004),
884 nv_rd32(dev, 0x405008), nv_rd32(dev, 0x40500c),
885 nv_rd32(dev, 0x405010), nv_rd32(dev, 0x405014),
886 nv_rd32(dev, 0x40501c));
890 nv_wr32(dev, 0x405018, 0xc0000000);
891 nv_wr32(dev, 0x400108, 0x010);
895 /* Unknown, not seen yet... 0x402000 is the only trap status reg
896 * remaining, so try to handle it anyway. Perhaps related to that
897 * unknown DMA slot on tesla? */
899 ustatus = nv_rd32(dev, 0x402000) & 0x7fffffff;
901 NV_INFO(dev, "PGRAPH - TRAP_UNKC04 0x%08x\n", ustatus);
902 nv_wr32(dev, 0x402000, 0xc0000000);
903 /* no status modifiction on purpose */
906 /* TEXTURE: CUDA texturing units */
907 if (status & 0x040) {
908 nv50_pgraph_tp_trap(dev, 6, 0x408900, 0x408600, display,
909 "PGRAPH - TRAP_TEXTURE");
910 nv_wr32(dev, 0x400108, 0x040);
914 /* MP: CUDA execution engines. */
915 if (status & 0x080) {
916 nv50_pgraph_tp_trap(dev, 7, 0x408314, 0x40831c, display,
918 nv_wr32(dev, 0x400108, 0x080);
922 /* TPDMA: Handles TP-initiated uncached memory accesses:
923 * l[], g[], stack, 2d surfaces, render targets. */
924 if (status & 0x100) {
925 nv50_pgraph_tp_trap(dev, 8, 0x408e08, 0x408708, display,
926 "PGRAPH - TRAP_TPDMA");
927 nv_wr32(dev, 0x400108, 0x100);
933 NV_INFO(dev, "PGRAPH - TRAP: unknown 0x%08x\n", status);
934 nv_wr32(dev, 0x400108, status);
941 nv50_graph_isr_chid(struct drm_device *dev, u64 inst)
943 struct drm_nouveau_private *dev_priv = dev->dev_private;
944 struct nouveau_channel *chan;
948 spin_lock_irqsave(&dev_priv->channels.lock, flags);
949 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
950 chan = dev_priv->channels.ptr[i];
951 if (!chan || !chan->ramin)
954 if (inst == chan->ramin->vinst)
957 spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
962 nv50_graph_isr(struct drm_device *dev)
966 while ((stat = nv_rd32(dev, 0x400100))) {
967 u64 inst = (u64)(nv_rd32(dev, 0x40032c) & 0x0fffffff) << 12;
968 u32 chid = nv50_graph_isr_chid(dev, inst);
969 u32 addr = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR);
970 u32 subc = (addr & 0x00070000) >> 16;
971 u32 mthd = (addr & 0x00001ffc);
972 u32 data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA);
973 u32 class = nv_rd32(dev, 0x400814);
976 if (stat & 0x00000010) {
977 if (!nouveau_gpuobj_mthd_call2(dev, chid, class,
982 if (stat & 0x00001000) {
983 nv_wr32(dev, 0x400500, 0x00000000);
984 nv_wr32(dev, 0x400100, 0x00001000);
985 nv_mask(dev, 0x40013c, 0x00001000, 0x00000000);
986 nv50_graph_context_switch(dev);
991 show = (show && nouveau_ratelimit()) ? show : 0;
993 if (show & 0x00100000) {
994 u32 ecode = nv_rd32(dev, 0x400110);
995 NV_INFO(dev, "PGRAPH - DATA_ERROR ");
996 nouveau_enum_print(nv50_data_error_names, ecode);
1000 if (stat & 0x00200000) {
1001 if (!nv50_pgraph_trap_handler(dev, show, inst, chid))
1002 show &= ~0x00200000;
1005 nv_wr32(dev, 0x400100, stat);
1006 nv_wr32(dev, 0x400500, 0x00010001);
1009 NV_INFO(dev, "PGRAPH -");
1010 nouveau_bitfield_print(nv50_graph_intr, show);
1012 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) subc %d "
1013 "class 0x%04x mthd 0x%04x data 0x%08x\n",
1014 chid, inst, subc, class, mthd, data);
1015 nv50_fb_vm_trap(dev, 1);
1019 if (nv_rd32(dev, 0x400824) & (1 << 31))
1020 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) & ~(1 << 31));
1024 nv50_graph_destroy(struct drm_device *dev, int engine)
1026 struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
1028 NVOBJ_ENGINE_DEL(dev, GR);
1030 nouveau_irq_unregister(dev, 12);
1035 nv50_graph_create(struct drm_device *dev)
1037 struct drm_nouveau_private *dev_priv = dev->dev_private;
1038 struct nv50_graph_engine *pgraph;
1039 struct nouveau_grctx ctx = {};
1042 pgraph = kzalloc(sizeof(*pgraph),GFP_KERNEL);
1047 ctx.mode = NOUVEAU_GRCTX_PROG;
1048 ctx.data = pgraph->ctxprog;
1049 ctx.ctxprog_max = ARRAY_SIZE(pgraph->ctxprog);
1051 ret = nv50_grctx_init(&ctx);
1053 NV_ERROR(dev, "PGRAPH: ctxprog build failed\n");
1058 pgraph->grctx_size = ctx.ctxvals_pos * 4;
1059 pgraph->ctxprog_size = ctx.ctxprog_len;
1061 pgraph->base.destroy = nv50_graph_destroy;
1062 pgraph->base.init = nv50_graph_init;
1063 pgraph->base.fini = nv50_graph_fini;
1064 pgraph->base.context_new = nv50_graph_context_new;
1065 pgraph->base.context_del = nv50_graph_context_del;
1066 pgraph->base.object_new = nv50_graph_object_new;
1067 if (dev_priv->chipset == 0x50 || dev_priv->chipset == 0xac)
1068 pgraph->base.tlb_flush = nv50_graph_tlb_flush;
1070 pgraph->base.tlb_flush = nv84_graph_tlb_flush;
1072 nouveau_irq_register(dev, 12, nv50_graph_isr);
1074 /* NVSW really doesn't live here... */
1075 NVOBJ_CLASS(dev, 0x506e, SW); /* nvsw */
1076 NVOBJ_MTHD (dev, 0x506e, 0x018c, nv50_graph_nvsw_dma_vblsem);
1077 NVOBJ_MTHD (dev, 0x506e, 0x0400, nv50_graph_nvsw_vblsem_offset);
1078 NVOBJ_MTHD (dev, 0x506e, 0x0404, nv50_graph_nvsw_vblsem_release_val);
1079 NVOBJ_MTHD (dev, 0x506e, 0x0408, nv50_graph_nvsw_vblsem_release);
1080 NVOBJ_MTHD (dev, 0x506e, 0x0500, nv50_graph_nvsw_mthd_page_flip);
1082 NVOBJ_ENGINE_ADD(dev, GR, &pgraph->base);
1083 NVOBJ_CLASS(dev, 0x0030, GR); /* null */
1084 NVOBJ_CLASS(dev, 0x5039, GR); /* m2mf */
1085 NVOBJ_CLASS(dev, 0x502d, GR); /* 2d */
1088 if (dev_priv->chipset == 0x50)
1089 NVOBJ_CLASS(dev, 0x5097, GR); /* tesla (nv50) */
1091 if (dev_priv->chipset < 0xa0)
1092 NVOBJ_CLASS(dev, 0x8297, GR); /* tesla (nv8x/nv9x) */
1094 switch (dev_priv->chipset) {
1098 NVOBJ_CLASS(dev, 0x8397, GR);
1103 NVOBJ_CLASS(dev, 0x8597, GR);
1106 NVOBJ_CLASS(dev, 0x8697, GR);
1112 NVOBJ_CLASS(dev, 0x50c0, GR);
1113 if (dev_priv->chipset > 0xa0 &&
1114 dev_priv->chipset != 0xaa &&
1115 dev_priv->chipset != 0xac)
1116 NVOBJ_CLASS(dev, 0x85c0, GR);