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.
28 #include "nouveau_drv.h"
29 #include "nouveau_fifo.h"
30 #include "nouveau_ramht.h"
31 #include "nouveau_dma.h"
32 #include "nouveau_vm.h"
35 struct nv50_graph_engine {
36 struct nouveau_exec_engine base;
43 nv50_graph_init(struct drm_device *dev, int engine)
45 struct drm_nouveau_private *dev_priv = dev->dev_private;
46 struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
47 u32 units = nv_rd32(dev, 0x001540);
53 nv_mask(dev, 0x000200, 0x00201000, 0x00000000);
54 nv_mask(dev, 0x000200, 0x00201000, 0x00201000);
55 nv_wr32(dev, 0x40008c, 0x00000004); /* HW_CTX_SWITCH_ENABLED */
57 /* reset/enable traps and interrupts */
58 nv_wr32(dev, 0x400804, 0xc0000000);
59 nv_wr32(dev, 0x406800, 0xc0000000);
60 nv_wr32(dev, 0x400c04, 0xc0000000);
61 nv_wr32(dev, 0x401800, 0xc0000000);
62 nv_wr32(dev, 0x405018, 0xc0000000);
63 nv_wr32(dev, 0x402000, 0xc0000000);
64 for (i = 0; i < 16; i++) {
65 if (!(units & (1 << i)))
68 if (dev_priv->chipset < 0xa0) {
69 nv_wr32(dev, 0x408900 + (i << 12), 0xc0000000);
70 nv_wr32(dev, 0x408e08 + (i << 12), 0xc0000000);
71 nv_wr32(dev, 0x408314 + (i << 12), 0xc0000000);
73 nv_wr32(dev, 0x408600 + (i << 11), 0xc0000000);
74 nv_wr32(dev, 0x408708 + (i << 11), 0xc0000000);
75 nv_wr32(dev, 0x40831c + (i << 11), 0xc0000000);
79 nv_wr32(dev, 0x400108, 0xffffffff);
80 nv_wr32(dev, 0x400138, 0xffffffff);
81 nv_wr32(dev, 0x400100, 0xffffffff);
82 nv_wr32(dev, 0x40013c, 0xffffffff);
83 nv_wr32(dev, 0x400500, 0x00010001);
85 /* upload context program, initialise ctxctl defaults */
86 nv_wr32(dev, 0x400324, 0x00000000);
87 for (i = 0; i < pgraph->ctxprog_size; i++)
88 nv_wr32(dev, 0x400328, pgraph->ctxprog[i]);
89 nv_wr32(dev, 0x400824, 0x00000000);
90 nv_wr32(dev, 0x400828, 0x00000000);
91 nv_wr32(dev, 0x40082c, 0x00000000);
92 nv_wr32(dev, 0x400830, 0x00000000);
93 nv_wr32(dev, 0x400724, 0x00000000);
94 nv_wr32(dev, 0x40032c, 0x00000000);
95 nv_wr32(dev, 0x400320, 4); /* CTXCTL_CMD = NEWCTXDMA */
97 /* some unknown zcull magic */
98 switch (dev_priv->chipset & 0xf0) {
102 nv_wr32(dev, 0x402ca8, 0x00000800);
106 nv_wr32(dev, 0x402cc0, 0x00000000);
107 if (dev_priv->chipset == 0xa0 ||
108 dev_priv->chipset == 0xaa ||
109 dev_priv->chipset == 0xac) {
110 nv_wr32(dev, 0x402ca8, 0x00000802);
112 nv_wr32(dev, 0x402cc0, 0x00000000);
113 nv_wr32(dev, 0x402ca8, 0x00000002);
119 /* zero out zcull regions */
120 for (i = 0; i < 8; i++) {
121 nv_wr32(dev, 0x402c20 + (i * 8), 0x00000000);
122 nv_wr32(dev, 0x402c24 + (i * 8), 0x00000000);
123 nv_wr32(dev, 0x402c28 + (i * 8), 0x00000000);
124 nv_wr32(dev, 0x402c2c + (i * 8), 0x00000000);
131 nv50_graph_fini(struct drm_device *dev, int engine, bool suspend)
133 nv_wr32(dev, 0x40013c, 0x00000000);
138 nv50_graph_context_new(struct nouveau_channel *chan, int engine)
140 struct drm_device *dev = chan->dev;
141 struct drm_nouveau_private *dev_priv = dev->dev_private;
142 struct nouveau_gpuobj *ramin = chan->ramin;
143 struct nouveau_gpuobj *grctx = NULL;
144 struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
147 NV_DEBUG(dev, "ch%d\n", chan->id);
149 ret = nouveau_gpuobj_new(dev, NULL, pgraph->grctx_size, 0,
150 NVOBJ_FLAG_ZERO_ALLOC |
151 NVOBJ_FLAG_ZERO_FREE, &grctx);
155 hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
156 nv_wo32(ramin, hdr + 0x00, 0x00190002);
157 nv_wo32(ramin, hdr + 0x04, grctx->vinst + grctx->size - 1);
158 nv_wo32(ramin, hdr + 0x08, grctx->vinst);
159 nv_wo32(ramin, hdr + 0x0c, 0);
160 nv_wo32(ramin, hdr + 0x10, 0);
161 nv_wo32(ramin, hdr + 0x14, 0x00010000);
163 nv50_grctx_fill(dev, grctx);
164 nv_wo32(grctx, 0x00000, chan->ramin->vinst >> 12);
166 dev_priv->engine.instmem.flush(dev);
168 atomic_inc(&chan->vm->engref[NVOBJ_ENGINE_GR]);
169 chan->engctx[NVOBJ_ENGINE_GR] = grctx;
174 nv50_graph_context_del(struct nouveau_channel *chan, int engine)
176 struct nouveau_gpuobj *grctx = chan->engctx[engine];
177 struct drm_device *dev = chan->dev;
178 struct drm_nouveau_private *dev_priv = dev->dev_private;
179 int i, hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
181 for (i = hdr; i < hdr + 24; i += 4)
182 nv_wo32(chan->ramin, i, 0);
183 dev_priv->engine.instmem.flush(dev);
185 atomic_dec(&chan->vm->engref[engine]);
186 nouveau_gpuobj_ref(NULL, &grctx);
187 chan->engctx[engine] = NULL;
191 nv50_graph_object_new(struct nouveau_channel *chan, int engine,
192 u32 handle, u16 class)
194 struct drm_device *dev = chan->dev;
195 struct drm_nouveau_private *dev_priv = dev->dev_private;
196 struct nouveau_gpuobj *obj = NULL;
199 ret = nouveau_gpuobj_new(dev, chan, 16, 16, NVOBJ_FLAG_ZERO_FREE, &obj);
205 nv_wo32(obj, 0x00, class);
206 nv_wo32(obj, 0x04, 0x00000000);
207 nv_wo32(obj, 0x08, 0x00000000);
208 nv_wo32(obj, 0x0c, 0x00000000);
209 dev_priv->engine.instmem.flush(dev);
211 ret = nouveau_ramht_insert(chan, handle, obj);
212 nouveau_gpuobj_ref(NULL, &obj);
217 nv50_graph_tlb_flush(struct drm_device *dev, int engine)
219 nv50_vm_flush_engine(dev, 0);
223 nv84_graph_tlb_flush(struct drm_device *dev, int engine)
225 struct drm_nouveau_private *dev_priv = dev->dev_private;
226 struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer;
227 bool idle, timeout = false;
232 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
233 nv_mask(dev, 0x400500, 0x00000001, 0x00000000);
235 start = ptimer->read(dev);
239 for (tmp = nv_rd32(dev, 0x400380); tmp && idle; tmp >>= 3) {
244 for (tmp = nv_rd32(dev, 0x400384); tmp && idle; tmp >>= 3) {
249 for (tmp = nv_rd32(dev, 0x400388); tmp && idle; tmp >>= 3) {
253 } while (!idle && !(timeout = ptimer->read(dev) - start > 2000000000));
256 NV_ERROR(dev, "PGRAPH TLB flush idle timeout fail: "
257 "0x%08x 0x%08x 0x%08x 0x%08x\n",
258 nv_rd32(dev, 0x400700), nv_rd32(dev, 0x400380),
259 nv_rd32(dev, 0x400384), nv_rd32(dev, 0x400388));
262 nv50_vm_flush_engine(dev, 0);
264 nv_mask(dev, 0x400500, 0x00000001, 0x00000001);
265 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
268 static struct nouveau_enum nv50_mp_exec_error_names[] = {
269 { 3, "STACK_UNDERFLOW", NULL },
270 { 4, "QUADON_ACTIVE", NULL },
271 { 8, "TIMEOUT", NULL },
272 { 0x10, "INVALID_OPCODE", NULL },
273 { 0x40, "BREAKPOINT", NULL },
277 static struct nouveau_bitfield nv50_graph_trap_m2mf[] = {
278 { 0x00000001, "NOTIFY" },
279 { 0x00000002, "IN" },
280 { 0x00000004, "OUT" },
284 static struct nouveau_bitfield nv50_graph_trap_vfetch[] = {
285 { 0x00000001, "FAULT" },
289 static struct nouveau_bitfield nv50_graph_trap_strmout[] = {
290 { 0x00000001, "FAULT" },
294 static struct nouveau_bitfield nv50_graph_trap_ccache[] = {
295 { 0x00000001, "FAULT" },
299 /* There must be a *lot* of these. Will take some time to gather them up. */
300 struct nouveau_enum nv50_data_error_names[] = {
301 { 0x00000003, "INVALID_OPERATION", NULL },
302 { 0x00000004, "INVALID_VALUE", NULL },
303 { 0x00000005, "INVALID_ENUM", NULL },
304 { 0x00000008, "INVALID_OBJECT", NULL },
305 { 0x00000009, "READ_ONLY_OBJECT", NULL },
306 { 0x0000000a, "SUPERVISOR_OBJECT", NULL },
307 { 0x0000000b, "INVALID_ADDRESS_ALIGNMENT", NULL },
308 { 0x0000000c, "INVALID_BITFIELD", NULL },
309 { 0x0000000d, "BEGIN_END_ACTIVE", NULL },
310 { 0x0000000e, "SEMANTIC_COLOR_BACK_OVER_LIMIT", NULL },
311 { 0x0000000f, "VIEWPORT_ID_NEEDS_GP", NULL },
312 { 0x00000010, "RT_DOUBLE_BIND", NULL },
313 { 0x00000011, "RT_TYPES_MISMATCH", NULL },
314 { 0x00000012, "RT_LINEAR_WITH_ZETA", NULL },
315 { 0x00000015, "FP_TOO_FEW_REGS", NULL },
316 { 0x00000016, "ZETA_FORMAT_CSAA_MISMATCH", NULL },
317 { 0x00000017, "RT_LINEAR_WITH_MSAA", NULL },
318 { 0x00000018, "FP_INTERPOLANT_START_OVER_LIMIT", NULL },
319 { 0x00000019, "SEMANTIC_LAYER_OVER_LIMIT", NULL },
320 { 0x0000001a, "RT_INVALID_ALIGNMENT", NULL },
321 { 0x0000001b, "SAMPLER_OVER_LIMIT", NULL },
322 { 0x0000001c, "TEXTURE_OVER_LIMIT", NULL },
323 { 0x0000001e, "GP_TOO_MANY_OUTPUTS", NULL },
324 { 0x0000001f, "RT_BPP128_WITH_MS8", NULL },
325 { 0x00000021, "Z_OUT_OF_BOUNDS", NULL },
326 { 0x00000023, "XY_OUT_OF_BOUNDS", NULL },
327 { 0x00000024, "VP_ZERO_INPUTS", NULL },
328 { 0x00000027, "CP_MORE_PARAMS_THAN_SHARED", NULL },
329 { 0x00000028, "CP_NO_REG_SPACE_STRIPED", NULL },
330 { 0x00000029, "CP_NO_REG_SPACE_PACKED", NULL },
331 { 0x0000002a, "CP_NOT_ENOUGH_WARPS", NULL },
332 { 0x0000002b, "CP_BLOCK_SIZE_MISMATCH", NULL },
333 { 0x0000002c, "CP_NOT_ENOUGH_LOCAL_WARPS", NULL },
334 { 0x0000002d, "CP_NOT_ENOUGH_STACK_WARPS", NULL },
335 { 0x0000002e, "CP_NO_BLOCKDIM_LATCH", NULL },
336 { 0x00000031, "ENG2D_FORMAT_MISMATCH", NULL },
337 { 0x0000003f, "PRIMITIVE_ID_NEEDS_GP", NULL },
338 { 0x00000044, "SEMANTIC_VIEWPORT_OVER_LIMIT", NULL },
339 { 0x00000045, "SEMANTIC_COLOR_FRONT_OVER_LIMIT", NULL },
340 { 0x00000046, "LAYER_ID_NEEDS_GP", NULL },
341 { 0x00000047, "SEMANTIC_CLIP_OVER_LIMIT", NULL },
342 { 0x00000048, "SEMANTIC_PTSZ_OVER_LIMIT", NULL },
346 static struct nouveau_bitfield nv50_graph_intr[] = {
347 { 0x00000001, "NOTIFY" },
348 { 0x00000002, "COMPUTE_QUERY" },
349 { 0x00000010, "ILLEGAL_MTHD" },
350 { 0x00000020, "ILLEGAL_CLASS" },
351 { 0x00000040, "DOUBLE_NOTIFY" },
352 { 0x00001000, "CONTEXT_SWITCH" },
353 { 0x00010000, "BUFFER_NOTIFY" },
354 { 0x00100000, "DATA_ERROR" },
355 { 0x00200000, "TRAP" },
356 { 0x01000000, "SINGLE_STEP" },
361 nv50_pgraph_mp_trap(struct drm_device *dev, int tpid, int display)
363 struct drm_nouveau_private *dev_priv = dev->dev_private;
364 uint32_t units = nv_rd32(dev, 0x1540);
365 uint32_t addr, mp10, status, pc, oplow, ophigh;
368 for (i = 0; i < 4; i++) {
369 if (!(units & 1 << (i+24)))
371 if (dev_priv->chipset < 0xa0)
372 addr = 0x408200 + (tpid << 12) + (i << 7);
374 addr = 0x408100 + (tpid << 11) + (i << 7);
375 mp10 = nv_rd32(dev, addr + 0x10);
376 status = nv_rd32(dev, addr + 0x14);
380 nv_rd32(dev, addr + 0x20);
381 pc = nv_rd32(dev, addr + 0x24);
382 oplow = nv_rd32(dev, addr + 0x70);
383 ophigh = nv_rd32(dev, addr + 0x74);
384 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - "
385 "TP %d MP %d: ", tpid, i);
386 nouveau_enum_print(nv50_mp_exec_error_names, status);
387 printk(" at %06x warp %d, opcode %08x %08x\n",
388 pc&0xffffff, pc >> 24,
391 nv_wr32(dev, addr + 0x10, mp10);
392 nv_wr32(dev, addr + 0x14, 0);
396 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - TP %d: "
397 "No MPs claiming errors?\n", tpid);
401 nv50_pgraph_tp_trap(struct drm_device *dev, int type, uint32_t ustatus_old,
402 uint32_t ustatus_new, int display, const char *name)
404 struct drm_nouveau_private *dev_priv = dev->dev_private;
406 uint32_t units = nv_rd32(dev, 0x1540);
408 uint32_t ustatus_addr, ustatus;
409 for (i = 0; i < 16; i++) {
410 if (!(units & (1 << i)))
412 if (dev_priv->chipset < 0xa0)
413 ustatus_addr = ustatus_old + (i << 12);
415 ustatus_addr = ustatus_new + (i << 11);
416 ustatus = nv_rd32(dev, ustatus_addr) & 0x7fffffff;
421 case 6: /* texture error... unknown for now */
423 NV_ERROR(dev, "magic set %d:\n", i);
424 for (r = ustatus_addr + 4; r <= ustatus_addr + 0x10; r += 4)
425 NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r,
429 case 7: /* MP error */
430 if (ustatus & 0x04030000) {
431 nv50_pgraph_mp_trap(dev, i, display);
432 ustatus &= ~0x04030000;
435 case 8: /* TPDMA error */
437 uint32_t e0c = nv_rd32(dev, ustatus_addr + 4);
438 uint32_t e10 = nv_rd32(dev, ustatus_addr + 8);
439 uint32_t e14 = nv_rd32(dev, ustatus_addr + 0xc);
440 uint32_t e18 = nv_rd32(dev, ustatus_addr + 0x10);
441 uint32_t e1c = nv_rd32(dev, ustatus_addr + 0x14);
442 uint32_t e20 = nv_rd32(dev, ustatus_addr + 0x18);
443 uint32_t e24 = nv_rd32(dev, ustatus_addr + 0x1c);
444 /* 2d engine destination */
445 if (ustatus & 0x00000010) {
447 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - Unknown fault at address %02x%08x\n",
449 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
450 i, e0c, e18, e1c, e20, e24);
452 ustatus &= ~0x00000010;
455 if (ustatus & 0x00000040) {
457 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - Unknown fault at address %02x%08x\n",
459 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
460 i, e0c, e18, e1c, e20, e24);
462 ustatus &= ~0x00000040;
464 /* CUDA memory: l[], g[] or stack. */
465 if (ustatus & 0x00000080) {
467 if (e18 & 0x80000000) {
468 /* g[] read fault? */
469 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global read fault at address %02x%08x\n",
470 i, e14, e10 | ((e18 >> 24) & 0x1f));
472 } else if (e18 & 0xc) {
473 /* g[] write fault? */
474 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global write fault at address %02x%08x\n",
475 i, e14, e10 | ((e18 >> 7) & 0x1f));
478 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Unknown CUDA fault at address %02x%08x\n",
481 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
482 i, e0c, e18, e1c, e20, e24);
484 ustatus &= ~0x00000080;
491 NV_INFO(dev, "%s - TP%d: Unhandled ustatus 0x%08x\n", name, i, ustatus);
493 nv_wr32(dev, ustatus_addr, 0xc0000000);
497 NV_INFO(dev, "%s - No TPs claiming errors?\n", name);
501 nv50_pgraph_trap_handler(struct drm_device *dev, u32 display, u64 inst, u32 chid)
503 u32 status = nv_rd32(dev, 0x400108);
506 if (!status && display) {
507 NV_INFO(dev, "PGRAPH - TRAP: no units reporting traps?\n");
511 /* DISPATCH: Relays commands to other units and handles NOTIFY,
512 * COND, QUERY. If you get a trap from it, the command is still stuck
513 * in DISPATCH and you need to do something about it. */
514 if (status & 0x001) {
515 ustatus = nv_rd32(dev, 0x400804) & 0x7fffffff;
516 if (!ustatus && display) {
517 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - no ustatus?\n");
520 nv_wr32(dev, 0x400500, 0x00000000);
522 /* Known to be triggered by screwed up NOTIFY and COND... */
523 if (ustatus & 0x00000001) {
524 u32 addr = nv_rd32(dev, 0x400808);
525 u32 subc = (addr & 0x00070000) >> 16;
526 u32 mthd = (addr & 0x00001ffc);
527 u32 datal = nv_rd32(dev, 0x40080c);
528 u32 datah = nv_rd32(dev, 0x400810);
529 u32 class = nv_rd32(dev, 0x400814);
530 u32 r848 = nv_rd32(dev, 0x400848);
532 NV_INFO(dev, "PGRAPH - TRAP DISPATCH_FAULT\n");
533 if (display && (addr & 0x80000000)) {
534 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
535 "subc %d class 0x%04x mthd 0x%04x "
537 "400808 0x%08x 400848 0x%08x\n",
538 chid, inst, subc, class, mthd, datah,
542 NV_INFO(dev, "PGRAPH - no stuck command?\n");
545 nv_wr32(dev, 0x400808, 0);
546 nv_wr32(dev, 0x4008e8, nv_rd32(dev, 0x4008e8) & 3);
547 nv_wr32(dev, 0x400848, 0);
548 ustatus &= ~0x00000001;
551 if (ustatus & 0x00000002) {
552 u32 addr = nv_rd32(dev, 0x40084c);
553 u32 subc = (addr & 0x00070000) >> 16;
554 u32 mthd = (addr & 0x00001ffc);
555 u32 data = nv_rd32(dev, 0x40085c);
556 u32 class = nv_rd32(dev, 0x400814);
558 NV_INFO(dev, "PGRAPH - TRAP DISPATCH_QUERY\n");
559 if (display && (addr & 0x80000000)) {
560 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
561 "subc %d class 0x%04x mthd 0x%04x "
562 "data 0x%08x 40084c 0x%08x\n",
563 chid, inst, subc, class, mthd,
567 NV_INFO(dev, "PGRAPH - no stuck command?\n");
570 nv_wr32(dev, 0x40084c, 0);
571 ustatus &= ~0x00000002;
574 if (ustatus && display) {
575 NV_INFO(dev, "PGRAPH - TRAP_DISPATCH (unknown "
576 "0x%08x)\n", ustatus);
579 nv_wr32(dev, 0x400804, 0xc0000000);
580 nv_wr32(dev, 0x400108, 0x001);
586 /* M2MF: Memory to memory copy engine. */
587 if (status & 0x002) {
588 u32 ustatus = nv_rd32(dev, 0x406800) & 0x7fffffff;
590 NV_INFO(dev, "PGRAPH - TRAP_M2MF");
591 nouveau_bitfield_print(nv50_graph_trap_m2mf, ustatus);
593 NV_INFO(dev, "PGRAPH - TRAP_M2MF %08x %08x %08x %08x\n",
594 nv_rd32(dev, 0x406804), nv_rd32(dev, 0x406808),
595 nv_rd32(dev, 0x40680c), nv_rd32(dev, 0x406810));
599 /* No sane way found yet -- just reset the bugger. */
600 nv_wr32(dev, 0x400040, 2);
601 nv_wr32(dev, 0x400040, 0);
602 nv_wr32(dev, 0x406800, 0xc0000000);
603 nv_wr32(dev, 0x400108, 0x002);
607 /* VFETCH: Fetches data from vertex buffers. */
608 if (status & 0x004) {
609 u32 ustatus = nv_rd32(dev, 0x400c04) & 0x7fffffff;
611 NV_INFO(dev, "PGRAPH - TRAP_VFETCH");
612 nouveau_bitfield_print(nv50_graph_trap_vfetch, ustatus);
614 NV_INFO(dev, "PGRAPH - TRAP_VFETCH %08x %08x %08x %08x\n",
615 nv_rd32(dev, 0x400c00), nv_rd32(dev, 0x400c08),
616 nv_rd32(dev, 0x400c0c), nv_rd32(dev, 0x400c10));
619 nv_wr32(dev, 0x400c04, 0xc0000000);
620 nv_wr32(dev, 0x400108, 0x004);
624 /* STRMOUT: DirectX streamout / OpenGL transform feedback. */
625 if (status & 0x008) {
626 ustatus = nv_rd32(dev, 0x401800) & 0x7fffffff;
628 NV_INFO(dev, "PGRAPH - TRAP_STRMOUT");
629 nouveau_bitfield_print(nv50_graph_trap_strmout, ustatus);
631 NV_INFO(dev, "PGRAPH - TRAP_STRMOUT %08x %08x %08x %08x\n",
632 nv_rd32(dev, 0x401804), nv_rd32(dev, 0x401808),
633 nv_rd32(dev, 0x40180c), nv_rd32(dev, 0x401810));
637 /* No sane way found yet -- just reset the bugger. */
638 nv_wr32(dev, 0x400040, 0x80);
639 nv_wr32(dev, 0x400040, 0);
640 nv_wr32(dev, 0x401800, 0xc0000000);
641 nv_wr32(dev, 0x400108, 0x008);
645 /* CCACHE: Handles code and c[] caches and fills them. */
646 if (status & 0x010) {
647 ustatus = nv_rd32(dev, 0x405018) & 0x7fffffff;
649 NV_INFO(dev, "PGRAPH - TRAP_CCACHE");
650 nouveau_bitfield_print(nv50_graph_trap_ccache, ustatus);
652 NV_INFO(dev, "PGRAPH - TRAP_CCACHE %08x %08x %08x %08x"
654 nv_rd32(dev, 0x405000), nv_rd32(dev, 0x405004),
655 nv_rd32(dev, 0x405008), nv_rd32(dev, 0x40500c),
656 nv_rd32(dev, 0x405010), nv_rd32(dev, 0x405014),
657 nv_rd32(dev, 0x40501c));
661 nv_wr32(dev, 0x405018, 0xc0000000);
662 nv_wr32(dev, 0x400108, 0x010);
666 /* Unknown, not seen yet... 0x402000 is the only trap status reg
667 * remaining, so try to handle it anyway. Perhaps related to that
668 * unknown DMA slot on tesla? */
670 ustatus = nv_rd32(dev, 0x402000) & 0x7fffffff;
672 NV_INFO(dev, "PGRAPH - TRAP_UNKC04 0x%08x\n", ustatus);
673 nv_wr32(dev, 0x402000, 0xc0000000);
674 /* no status modifiction on purpose */
677 /* TEXTURE: CUDA texturing units */
678 if (status & 0x040) {
679 nv50_pgraph_tp_trap(dev, 6, 0x408900, 0x408600, display,
680 "PGRAPH - TRAP_TEXTURE");
681 nv_wr32(dev, 0x400108, 0x040);
685 /* MP: CUDA execution engines. */
686 if (status & 0x080) {
687 nv50_pgraph_tp_trap(dev, 7, 0x408314, 0x40831c, display,
689 nv_wr32(dev, 0x400108, 0x080);
693 /* TPDMA: Handles TP-initiated uncached memory accesses:
694 * l[], g[], stack, 2d surfaces, render targets. */
695 if (status & 0x100) {
696 nv50_pgraph_tp_trap(dev, 8, 0x408e08, 0x408708, display,
697 "PGRAPH - TRAP_TPDMA");
698 nv_wr32(dev, 0x400108, 0x100);
704 NV_INFO(dev, "PGRAPH - TRAP: unknown 0x%08x\n", status);
705 nv_wr32(dev, 0x400108, status);
712 nv50_graph_isr_chid(struct drm_device *dev, u64 inst)
714 struct nouveau_fifo_priv *pfifo = nv_engine(dev, NVOBJ_ENGINE_FIFO);
715 struct drm_nouveau_private *dev_priv = dev->dev_private;
716 struct nouveau_channel *chan;
720 spin_lock_irqsave(&dev_priv->channels.lock, flags);
721 for (i = 0; i < pfifo->channels; i++) {
722 chan = dev_priv->channels.ptr[i];
723 if (!chan || !chan->ramin)
726 if (inst == chan->ramin->vinst)
729 spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
734 nv50_graph_isr(struct drm_device *dev)
738 while ((stat = nv_rd32(dev, 0x400100))) {
739 u64 inst = (u64)(nv_rd32(dev, 0x40032c) & 0x0fffffff) << 12;
740 u32 chid = nv50_graph_isr_chid(dev, inst);
741 u32 addr = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR);
742 u32 subc = (addr & 0x00070000) >> 16;
743 u32 mthd = (addr & 0x00001ffc);
744 u32 data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA);
745 u32 class = nv_rd32(dev, 0x400814);
748 if (stat & 0x00000010) {
749 if (!nouveau_gpuobj_mthd_call2(dev, chid, class,
754 show = (show && nouveau_ratelimit()) ? show : 0;
756 if (show & 0x00100000) {
757 u32 ecode = nv_rd32(dev, 0x400110);
758 NV_INFO(dev, "PGRAPH - DATA_ERROR ");
759 nouveau_enum_print(nv50_data_error_names, ecode);
763 if (stat & 0x00200000) {
764 if (!nv50_pgraph_trap_handler(dev, show, inst, chid))
768 nv_wr32(dev, 0x400100, stat);
769 nv_wr32(dev, 0x400500, 0x00010001);
772 NV_INFO(dev, "PGRAPH -");
773 nouveau_bitfield_print(nv50_graph_intr, show);
775 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) subc %d "
776 "class 0x%04x mthd 0x%04x data 0x%08x\n",
777 chid, inst, subc, class, mthd, data);
778 nv50_fb_vm_trap(dev, 1);
782 if (nv_rd32(dev, 0x400824) & (1 << 31))
783 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) & ~(1 << 31));
787 nv50_graph_destroy(struct drm_device *dev, int engine)
789 struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
791 NVOBJ_ENGINE_DEL(dev, GR);
793 nouveau_irq_unregister(dev, 12);
798 nv50_graph_create(struct drm_device *dev)
800 struct drm_nouveau_private *dev_priv = dev->dev_private;
801 struct nv50_graph_engine *pgraph;
804 pgraph = kzalloc(sizeof(*pgraph),GFP_KERNEL);
808 ret = nv50_grctx_init(dev, pgraph->ctxprog, ARRAY_SIZE(pgraph->ctxprog),
809 &pgraph->ctxprog_size,
810 &pgraph->grctx_size);
812 NV_ERROR(dev, "PGRAPH: ctxprog build failed\n");
817 pgraph->base.destroy = nv50_graph_destroy;
818 pgraph->base.init = nv50_graph_init;
819 pgraph->base.fini = nv50_graph_fini;
820 pgraph->base.context_new = nv50_graph_context_new;
821 pgraph->base.context_del = nv50_graph_context_del;
822 pgraph->base.object_new = nv50_graph_object_new;
823 if (dev_priv->chipset == 0x50 || dev_priv->chipset == 0xac)
824 pgraph->base.tlb_flush = nv50_graph_tlb_flush;
826 pgraph->base.tlb_flush = nv84_graph_tlb_flush;
828 nouveau_irq_register(dev, 12, nv50_graph_isr);
830 NVOBJ_ENGINE_ADD(dev, GR, &pgraph->base);
831 NVOBJ_CLASS(dev, 0x0030, GR); /* null */
832 NVOBJ_CLASS(dev, 0x5039, GR); /* m2mf */
833 NVOBJ_CLASS(dev, 0x502d, GR); /* 2d */
836 if (dev_priv->chipset == 0x50)
837 NVOBJ_CLASS(dev, 0x5097, GR); /* tesla (nv50) */
839 if (dev_priv->chipset < 0xa0)
840 NVOBJ_CLASS(dev, 0x8297, GR); /* tesla (nv8x/nv9x) */
842 switch (dev_priv->chipset) {
846 NVOBJ_CLASS(dev, 0x8397, GR);
851 NVOBJ_CLASS(dev, 0x8597, GR);
854 NVOBJ_CLASS(dev, 0x8697, GR);
860 NVOBJ_CLASS(dev, 0x50c0, GR);
861 if (dev_priv->chipset > 0xa0 &&
862 dev_priv->chipset != 0xaa &&
863 dev_priv->chipset != 0xac)
864 NVOBJ_CLASS(dev, 0x85c0, GR);