2 * Copyright 2012 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #include <core/class.h>
27 #include <core/client.h>
28 #include <core/handle.h>
29 #include <core/engctx.h>
30 #include <core/enum.h>
32 #include <subdev/fb.h>
33 #include <subdev/vm.h>
34 #include <subdev/timer.h>
36 #include <engine/fifo.h>
37 #include <engine/graph.h>
41 struct nv50_graph_priv {
42 struct nouveau_graph base;
47 struct nv50_graph_chan {
48 struct nouveau_graph_chan base;
52 nv50_graph_units(struct nouveau_graph *graph)
54 struct nv50_graph_priv *priv = (void *)graph;
56 return nv_rd32(priv, 0x1540);
59 /*******************************************************************************
60 * Graphics object classes
61 ******************************************************************************/
64 nv50_graph_object_ctor(struct nouveau_object *parent,
65 struct nouveau_object *engine,
66 struct nouveau_oclass *oclass, void *data, u32 size,
67 struct nouveau_object **pobject)
69 struct nouveau_gpuobj *obj;
72 ret = nouveau_gpuobj_create(parent, engine, oclass, 0, parent,
74 *pobject = nv_object(obj);
78 nv_wo32(obj, 0x00, nv_mclass(obj));
79 nv_wo32(obj, 0x04, 0x00000000);
80 nv_wo32(obj, 0x08, 0x00000000);
81 nv_wo32(obj, 0x0c, 0x00000000);
85 static struct nouveau_ofuncs
87 .ctor = nv50_graph_object_ctor,
88 .dtor = _nouveau_gpuobj_dtor,
89 .init = _nouveau_gpuobj_init,
90 .fini = _nouveau_gpuobj_fini,
91 .rd32 = _nouveau_gpuobj_rd32,
92 .wr32 = _nouveau_gpuobj_wr32,
95 static struct nouveau_oclass
96 nv50_graph_sclass[] = {
97 { 0x0030, &nv50_graph_ofuncs },
98 { 0x502d, &nv50_graph_ofuncs },
99 { 0x5039, &nv50_graph_ofuncs },
100 { 0x5097, &nv50_graph_ofuncs },
101 { 0x50c0, &nv50_graph_ofuncs },
105 static struct nouveau_oclass
106 nv84_graph_sclass[] = {
107 { 0x0030, &nv50_graph_ofuncs },
108 { 0x502d, &nv50_graph_ofuncs },
109 { 0x5039, &nv50_graph_ofuncs },
110 { 0x50c0, &nv50_graph_ofuncs },
111 { 0x8297, &nv50_graph_ofuncs },
115 static struct nouveau_oclass
116 nva0_graph_sclass[] = {
117 { 0x0030, &nv50_graph_ofuncs },
118 { 0x502d, &nv50_graph_ofuncs },
119 { 0x5039, &nv50_graph_ofuncs },
120 { 0x50c0, &nv50_graph_ofuncs },
121 { 0x8397, &nv50_graph_ofuncs },
125 static struct nouveau_oclass
126 nva3_graph_sclass[] = {
127 { 0x0030, &nv50_graph_ofuncs },
128 { 0x502d, &nv50_graph_ofuncs },
129 { 0x5039, &nv50_graph_ofuncs },
130 { 0x50c0, &nv50_graph_ofuncs },
131 { 0x8597, &nv50_graph_ofuncs },
132 { 0x85c0, &nv50_graph_ofuncs },
136 static struct nouveau_oclass
137 nvaf_graph_sclass[] = {
138 { 0x0030, &nv50_graph_ofuncs },
139 { 0x502d, &nv50_graph_ofuncs },
140 { 0x5039, &nv50_graph_ofuncs },
141 { 0x50c0, &nv50_graph_ofuncs },
142 { 0x85c0, &nv50_graph_ofuncs },
143 { 0x8697, &nv50_graph_ofuncs },
147 /*******************************************************************************
149 ******************************************************************************/
152 nv50_graph_context_ctor(struct nouveau_object *parent,
153 struct nouveau_object *engine,
154 struct nouveau_oclass *oclass, void *data, u32 size,
155 struct nouveau_object **pobject)
157 struct nv50_graph_priv *priv = (void *)engine;
158 struct nv50_graph_chan *chan;
161 ret = nouveau_graph_context_create(parent, engine, oclass, NULL,
163 NVOBJ_FLAG_ZERO_ALLOC, &chan);
164 *pobject = nv_object(chan);
168 nv50_grctx_fill(nv_device(priv), nv_gpuobj(chan));
172 static struct nouveau_oclass
173 nv50_graph_cclass = {
174 .handle = NV_ENGCTX(GR, 0x50),
175 .ofuncs = &(struct nouveau_ofuncs) {
176 .ctor = nv50_graph_context_ctor,
177 .dtor = _nouveau_graph_context_dtor,
178 .init = _nouveau_graph_context_init,
179 .fini = _nouveau_graph_context_fini,
180 .rd32 = _nouveau_graph_context_rd32,
181 .wr32 = _nouveau_graph_context_wr32,
185 /*******************************************************************************
186 * PGRAPH engine/subdev functions
187 ******************************************************************************/
189 static const struct nouveau_bitfield nv50_pgraph_status[] = {
190 { 0x00000001, "BUSY" }, /* set when any bit is set */
191 { 0x00000002, "DISPATCH" },
192 { 0x00000004, "UNK2" },
193 { 0x00000008, "UNK3" },
194 { 0x00000010, "UNK4" },
195 { 0x00000020, "UNK5" },
196 { 0x00000040, "M2MF" },
197 { 0x00000080, "UNK7" },
198 { 0x00000100, "CTXPROG" },
199 { 0x00000200, "VFETCH" },
200 { 0x00000400, "CCACHE_UNK4" },
201 { 0x00000800, "STRMOUT_GSCHED_UNK5" },
202 { 0x00001000, "UNK14XX" },
203 { 0x00002000, "UNK24XX_CSCHED" },
204 { 0x00004000, "UNK1CXX" },
205 { 0x00008000, "CLIPID" },
206 { 0x00010000, "ZCULL" },
207 { 0x00020000, "ENG2D" },
208 { 0x00040000, "UNK34XX" },
209 { 0x00080000, "TPRAST" },
210 { 0x00100000, "TPROP" },
211 { 0x00200000, "TEX" },
212 { 0x00400000, "TPVP" },
213 { 0x00800000, "MP" },
214 { 0x01000000, "ROP" },
218 static const char *const nv50_pgraph_vstatus_0[] = {
219 "VFETCH", "CCACHE", "UNK4", "UNK5", "GSCHED", "STRMOUT", "UNK14XX", NULL
222 static const char *const nv50_pgraph_vstatus_1[] = {
223 "TPRAST", "TPROP", "TEXTURE", "TPVP", "MP", NULL
226 static const char *const nv50_pgraph_vstatus_2[] = {
227 "UNK24XX", "CSCHED", "UNK1CXX", "CLIPID", "ZCULL", "ENG2D", "UNK34XX",
231 static void nouveau_pgraph_vstatus_print(struct nv50_graph_priv *priv, int r,
232 const char *const units[], u32 status)
236 nv_error(priv, "PGRAPH_VSTATUS%d: 0x%08x", r, status);
238 for (i = 0; units[i] && status; i++) {
239 if ((status & 7) == 1)
240 pr_cont(" %s", units[i]);
244 pr_cont(" (invalid: 0x%x)", status);
249 nv84_graph_tlb_flush(struct nouveau_engine *engine)
251 struct nouveau_timer *ptimer = nouveau_timer(engine);
252 struct nv50_graph_priv *priv = (void *)engine;
253 bool idle, timeout = false;
258 spin_lock_irqsave(&priv->lock, flags);
259 nv_mask(priv, 0x400500, 0x00000001, 0x00000000);
261 start = ptimer->read(ptimer);
265 for (tmp = nv_rd32(priv, 0x400380); tmp && idle; tmp >>= 3) {
270 for (tmp = nv_rd32(priv, 0x400384); tmp && idle; tmp >>= 3) {
275 for (tmp = nv_rd32(priv, 0x400388); tmp && idle; tmp >>= 3) {
280 !(timeout = ptimer->read(ptimer) - start > 2000000000));
283 nv_error(priv, "PGRAPH TLB flush idle timeout fail\n");
285 tmp = nv_rd32(priv, 0x400700);
286 nv_error(priv, "PGRAPH_STATUS : 0x%08x", tmp);
287 nouveau_bitfield_print(nv50_pgraph_status, tmp);
290 nouveau_pgraph_vstatus_print(priv, 0, nv50_pgraph_vstatus_0,
291 nv_rd32(priv, 0x400380));
292 nouveau_pgraph_vstatus_print(priv, 1, nv50_pgraph_vstatus_1,
293 nv_rd32(priv, 0x400384));
294 nouveau_pgraph_vstatus_print(priv, 2, nv50_pgraph_vstatus_2,
295 nv_rd32(priv, 0x400388));
299 nv_wr32(priv, 0x100c80, 0x00000001);
300 if (!nv_wait(priv, 0x100c80, 0x00000001, 0x00000000))
301 nv_error(priv, "vm flush timeout\n");
302 nv_mask(priv, 0x400500, 0x00000001, 0x00000001);
303 spin_unlock_irqrestore(&priv->lock, flags);
304 return timeout ? -EBUSY : 0;
307 static const struct nouveau_bitfield nv50_mp_exec_errors[] = {
308 { 0x01, "STACK_UNDERFLOW" },
309 { 0x02, "STACK_MISMATCH" },
310 { 0x04, "QUADON_ACTIVE" },
312 { 0x10, "INVALID_OPCODE" },
313 { 0x20, "PM_OVERFLOW" },
314 { 0x40, "BREAKPOINT" },
318 static const struct nouveau_bitfield nv50_graph_trap_m2mf[] = {
319 { 0x00000001, "NOTIFY" },
320 { 0x00000002, "IN" },
321 { 0x00000004, "OUT" },
325 static const struct nouveau_bitfield nv50_graph_trap_vfetch[] = {
326 { 0x00000001, "FAULT" },
330 static const struct nouveau_bitfield nv50_graph_trap_strmout[] = {
331 { 0x00000001, "FAULT" },
335 static const struct nouveau_bitfield nv50_graph_trap_ccache[] = {
336 { 0x00000001, "FAULT" },
340 /* There must be a *lot* of these. Will take some time to gather them up. */
341 const struct nouveau_enum nv50_data_error_names[] = {
342 { 0x00000003, "INVALID_OPERATION", NULL },
343 { 0x00000004, "INVALID_VALUE", NULL },
344 { 0x00000005, "INVALID_ENUM", NULL },
345 { 0x00000008, "INVALID_OBJECT", NULL },
346 { 0x00000009, "READ_ONLY_OBJECT", NULL },
347 { 0x0000000a, "SUPERVISOR_OBJECT", NULL },
348 { 0x0000000b, "INVALID_ADDRESS_ALIGNMENT", NULL },
349 { 0x0000000c, "INVALID_BITFIELD", NULL },
350 { 0x0000000d, "BEGIN_END_ACTIVE", NULL },
351 { 0x0000000e, "SEMANTIC_COLOR_BACK_OVER_LIMIT", NULL },
352 { 0x0000000f, "VIEWPORT_ID_NEEDS_GP", NULL },
353 { 0x00000010, "RT_DOUBLE_BIND", NULL },
354 { 0x00000011, "RT_TYPES_MISMATCH", NULL },
355 { 0x00000012, "RT_LINEAR_WITH_ZETA", NULL },
356 { 0x00000015, "FP_TOO_FEW_REGS", NULL },
357 { 0x00000016, "ZETA_FORMAT_CSAA_MISMATCH", NULL },
358 { 0x00000017, "RT_LINEAR_WITH_MSAA", NULL },
359 { 0x00000018, "FP_INTERPOLANT_START_OVER_LIMIT", NULL },
360 { 0x00000019, "SEMANTIC_LAYER_OVER_LIMIT", NULL },
361 { 0x0000001a, "RT_INVALID_ALIGNMENT", NULL },
362 { 0x0000001b, "SAMPLER_OVER_LIMIT", NULL },
363 { 0x0000001c, "TEXTURE_OVER_LIMIT", NULL },
364 { 0x0000001e, "GP_TOO_MANY_OUTPUTS", NULL },
365 { 0x0000001f, "RT_BPP128_WITH_MS8", NULL },
366 { 0x00000021, "Z_OUT_OF_BOUNDS", NULL },
367 { 0x00000023, "XY_OUT_OF_BOUNDS", NULL },
368 { 0x00000024, "VP_ZERO_INPUTS", NULL },
369 { 0x00000027, "CP_MORE_PARAMS_THAN_SHARED", NULL },
370 { 0x00000028, "CP_NO_REG_SPACE_STRIPED", NULL },
371 { 0x00000029, "CP_NO_REG_SPACE_PACKED", NULL },
372 { 0x0000002a, "CP_NOT_ENOUGH_WARPS", NULL },
373 { 0x0000002b, "CP_BLOCK_SIZE_MISMATCH", NULL },
374 { 0x0000002c, "CP_NOT_ENOUGH_LOCAL_WARPS", NULL },
375 { 0x0000002d, "CP_NOT_ENOUGH_STACK_WARPS", NULL },
376 { 0x0000002e, "CP_NO_BLOCKDIM_LATCH", NULL },
377 { 0x00000031, "ENG2D_FORMAT_MISMATCH", NULL },
378 { 0x0000003f, "PRIMITIVE_ID_NEEDS_GP", NULL },
379 { 0x00000044, "SEMANTIC_VIEWPORT_OVER_LIMIT", NULL },
380 { 0x00000045, "SEMANTIC_COLOR_FRONT_OVER_LIMIT", NULL },
381 { 0x00000046, "LAYER_ID_NEEDS_GP", NULL },
382 { 0x00000047, "SEMANTIC_CLIP_OVER_LIMIT", NULL },
383 { 0x00000048, "SEMANTIC_PTSZ_OVER_LIMIT", NULL },
387 static const struct nouveau_bitfield nv50_graph_intr_name[] = {
388 { 0x00000001, "NOTIFY" },
389 { 0x00000002, "COMPUTE_QUERY" },
390 { 0x00000010, "ILLEGAL_MTHD" },
391 { 0x00000020, "ILLEGAL_CLASS" },
392 { 0x00000040, "DOUBLE_NOTIFY" },
393 { 0x00001000, "CONTEXT_SWITCH" },
394 { 0x00010000, "BUFFER_NOTIFY" },
395 { 0x00100000, "DATA_ERROR" },
396 { 0x00200000, "TRAP" },
397 { 0x01000000, "SINGLE_STEP" },
401 static const struct nouveau_bitfield nv50_graph_trap_prop[] = {
402 { 0x00000004, "SURF_WIDTH_OVERRUN" },
403 { 0x00000008, "SURF_HEIGHT_OVERRUN" },
404 { 0x00000010, "DST2D_FAULT" },
405 { 0x00000020, "ZETA_FAULT" },
406 { 0x00000040, "RT_FAULT" },
407 { 0x00000080, "CUDA_FAULT" },
408 { 0x00000100, "DST2D_STORAGE_TYPE_MISMATCH" },
409 { 0x00000200, "ZETA_STORAGE_TYPE_MISMATCH" },
410 { 0x00000400, "RT_STORAGE_TYPE_MISMATCH" },
411 { 0x00000800, "DST2D_LINEAR_MISMATCH" },
412 { 0x00001000, "RT_LINEAR_MISMATCH" },
417 nv50_priv_prop_trap(struct nv50_graph_priv *priv,
418 u32 ustatus_addr, u32 ustatus, u32 tp)
420 u32 e0c = nv_rd32(priv, ustatus_addr + 0x04);
421 u32 e10 = nv_rd32(priv, ustatus_addr + 0x08);
422 u32 e14 = nv_rd32(priv, ustatus_addr + 0x0c);
423 u32 e18 = nv_rd32(priv, ustatus_addr + 0x10);
424 u32 e1c = nv_rd32(priv, ustatus_addr + 0x14);
425 u32 e20 = nv_rd32(priv, ustatus_addr + 0x18);
426 u32 e24 = nv_rd32(priv, ustatus_addr + 0x1c);
428 /* CUDA memory: l[], g[] or stack. */
429 if (ustatus & 0x00000080) {
430 if (e18 & 0x80000000) {
431 /* g[] read fault? */
432 nv_error(priv, "TRAP_PROP - TP %d - CUDA_FAULT - Global read fault at address %02x%08x\n",
433 tp, e14, e10 | ((e18 >> 24) & 0x1f));
435 } else if (e18 & 0xc) {
436 /* g[] write fault? */
437 nv_error(priv, "TRAP_PROP - TP %d - CUDA_FAULT - Global write fault at address %02x%08x\n",
438 tp, e14, e10 | ((e18 >> 7) & 0x1f));
441 nv_error(priv, "TRAP_PROP - TP %d - Unknown CUDA fault at address %02x%08x\n",
444 ustatus &= ~0x00000080;
447 nv_error(priv, "TRAP_PROP - TP %d -", tp);
448 nouveau_bitfield_print(nv50_graph_trap_prop, ustatus);
449 pr_cont(" - Address %02x%08x\n", e14, e10);
451 nv_error(priv, "TRAP_PROP - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
452 tp, e0c, e18, e1c, e20, e24);
456 nv50_priv_mp_trap(struct nv50_graph_priv *priv, int tpid, int display)
458 u32 units = nv_rd32(priv, 0x1540);
459 u32 addr, mp10, status, pc, oplow, ophigh;
462 for (i = 0; i < 4; i++) {
463 if (!(units & 1 << (i+24)))
465 if (nv_device(priv)->chipset < 0xa0)
466 addr = 0x408200 + (tpid << 12) + (i << 7);
468 addr = 0x408100 + (tpid << 11) + (i << 7);
469 mp10 = nv_rd32(priv, addr + 0x10);
470 status = nv_rd32(priv, addr + 0x14);
474 nv_rd32(priv, addr + 0x20);
475 pc = nv_rd32(priv, addr + 0x24);
476 oplow = nv_rd32(priv, addr + 0x70);
477 ophigh = nv_rd32(priv, addr + 0x74);
478 nv_error(priv, "TRAP_MP_EXEC - "
479 "TP %d MP %d:", tpid, i);
480 nouveau_bitfield_print(nv50_mp_exec_errors, status);
481 pr_cont(" at %06x warp %d, opcode %08x %08x\n",
482 pc&0xffffff, pc >> 24,
485 nv_wr32(priv, addr + 0x10, mp10);
486 nv_wr32(priv, addr + 0x14, 0);
490 nv_error(priv, "TRAP_MP_EXEC - TP %d: "
491 "No MPs claiming errors?\n", tpid);
495 nv50_priv_tp_trap(struct nv50_graph_priv *priv, int type, u32 ustatus_old,
496 u32 ustatus_new, int display, const char *name)
499 u32 units = nv_rd32(priv, 0x1540);
501 u32 ustatus_addr, ustatus;
502 for (i = 0; i < 16; i++) {
503 if (!(units & (1 << i)))
505 if (nv_device(priv)->chipset < 0xa0)
506 ustatus_addr = ustatus_old + (i << 12);
508 ustatus_addr = ustatus_new + (i << 11);
509 ustatus = nv_rd32(priv, ustatus_addr) & 0x7fffffff;
514 case 6: /* texture error... unknown for now */
516 nv_error(priv, "magic set %d:\n", i);
517 for (r = ustatus_addr + 4; r <= ustatus_addr + 0x10; r += 4)
518 nv_error(priv, "\t0x%08x: 0x%08x\n", r,
522 case 7: /* MP error */
523 if (ustatus & 0x04030000) {
524 nv50_priv_mp_trap(priv, i, display);
525 ustatus &= ~0x04030000;
528 case 8: /* PROP error */
531 priv, ustatus_addr, ustatus, i);
537 nv_error(priv, "%s - TP%d: Unhandled ustatus 0x%08x\n", name, i, ustatus);
539 nv_wr32(priv, ustatus_addr, 0xc0000000);
543 nv_warn(priv, "%s - No TPs claiming errors?\n", name);
547 nv50_graph_trap_handler(struct nv50_graph_priv *priv, u32 display,
548 int chid, u64 inst, struct nouveau_object *engctx)
550 u32 status = nv_rd32(priv, 0x400108);
553 if (!status && display) {
554 nv_error(priv, "TRAP: no units reporting traps?\n");
558 /* DISPATCH: Relays commands to other units and handles NOTIFY,
559 * COND, QUERY. If you get a trap from it, the command is still stuck
560 * in DISPATCH and you need to do something about it. */
561 if (status & 0x001) {
562 ustatus = nv_rd32(priv, 0x400804) & 0x7fffffff;
563 if (!ustatus && display) {
564 nv_error(priv, "TRAP_DISPATCH - no ustatus?\n");
567 nv_wr32(priv, 0x400500, 0x00000000);
569 /* Known to be triggered by screwed up NOTIFY and COND... */
570 if (ustatus & 0x00000001) {
571 u32 addr = nv_rd32(priv, 0x400808);
572 u32 subc = (addr & 0x00070000) >> 16;
573 u32 mthd = (addr & 0x00001ffc);
574 u32 datal = nv_rd32(priv, 0x40080c);
575 u32 datah = nv_rd32(priv, 0x400810);
576 u32 class = nv_rd32(priv, 0x400814);
577 u32 r848 = nv_rd32(priv, 0x400848);
579 nv_error(priv, "TRAP DISPATCH_FAULT\n");
580 if (display && (addr & 0x80000000)) {
582 "ch %d [0x%010llx %s] subc %d class 0x%04x mthd 0x%04x data 0x%08x%08x 400808 0x%08x 400848 0x%08x\n",
584 nouveau_client_name(engctx), subc,
585 class, mthd, datah, datal, addr, r848);
588 nv_error(priv, "no stuck command?\n");
591 nv_wr32(priv, 0x400808, 0);
592 nv_wr32(priv, 0x4008e8, nv_rd32(priv, 0x4008e8) & 3);
593 nv_wr32(priv, 0x400848, 0);
594 ustatus &= ~0x00000001;
597 if (ustatus & 0x00000002) {
598 u32 addr = nv_rd32(priv, 0x40084c);
599 u32 subc = (addr & 0x00070000) >> 16;
600 u32 mthd = (addr & 0x00001ffc);
601 u32 data = nv_rd32(priv, 0x40085c);
602 u32 class = nv_rd32(priv, 0x400814);
604 nv_error(priv, "TRAP DISPATCH_QUERY\n");
605 if (display && (addr & 0x80000000)) {
607 "ch %d [0x%010llx %s] subc %d class 0x%04x mthd 0x%04x data 0x%08x 40084c 0x%08x\n",
609 nouveau_client_name(engctx), subc,
610 class, mthd, data, addr);
613 nv_error(priv, "no stuck command?\n");
616 nv_wr32(priv, 0x40084c, 0);
617 ustatus &= ~0x00000002;
620 if (ustatus && display) {
621 nv_error(priv, "TRAP_DISPATCH (unknown "
622 "0x%08x)\n", ustatus);
625 nv_wr32(priv, 0x400804, 0xc0000000);
626 nv_wr32(priv, 0x400108, 0x001);
632 /* M2MF: Memory to memory copy engine. */
633 if (status & 0x002) {
634 u32 ustatus = nv_rd32(priv, 0x406800) & 0x7fffffff;
636 nv_error(priv, "TRAP_M2MF");
637 nouveau_bitfield_print(nv50_graph_trap_m2mf, ustatus);
639 nv_error(priv, "TRAP_M2MF %08x %08x %08x %08x\n",
640 nv_rd32(priv, 0x406804), nv_rd32(priv, 0x406808),
641 nv_rd32(priv, 0x40680c), nv_rd32(priv, 0x406810));
645 /* No sane way found yet -- just reset the bugger. */
646 nv_wr32(priv, 0x400040, 2);
647 nv_wr32(priv, 0x400040, 0);
648 nv_wr32(priv, 0x406800, 0xc0000000);
649 nv_wr32(priv, 0x400108, 0x002);
653 /* VFETCH: Fetches data from vertex buffers. */
654 if (status & 0x004) {
655 u32 ustatus = nv_rd32(priv, 0x400c04) & 0x7fffffff;
657 nv_error(priv, "TRAP_VFETCH");
658 nouveau_bitfield_print(nv50_graph_trap_vfetch, ustatus);
660 nv_error(priv, "TRAP_VFETCH %08x %08x %08x %08x\n",
661 nv_rd32(priv, 0x400c00), nv_rd32(priv, 0x400c08),
662 nv_rd32(priv, 0x400c0c), nv_rd32(priv, 0x400c10));
665 nv_wr32(priv, 0x400c04, 0xc0000000);
666 nv_wr32(priv, 0x400108, 0x004);
670 /* STRMOUT: DirectX streamout / OpenGL transform feedback. */
671 if (status & 0x008) {
672 ustatus = nv_rd32(priv, 0x401800) & 0x7fffffff;
674 nv_error(priv, "TRAP_STRMOUT");
675 nouveau_bitfield_print(nv50_graph_trap_strmout, ustatus);
677 nv_error(priv, "TRAP_STRMOUT %08x %08x %08x %08x\n",
678 nv_rd32(priv, 0x401804), nv_rd32(priv, 0x401808),
679 nv_rd32(priv, 0x40180c), nv_rd32(priv, 0x401810));
683 /* No sane way found yet -- just reset the bugger. */
684 nv_wr32(priv, 0x400040, 0x80);
685 nv_wr32(priv, 0x400040, 0);
686 nv_wr32(priv, 0x401800, 0xc0000000);
687 nv_wr32(priv, 0x400108, 0x008);
691 /* CCACHE: Handles code and c[] caches and fills them. */
692 if (status & 0x010) {
693 ustatus = nv_rd32(priv, 0x405018) & 0x7fffffff;
695 nv_error(priv, "TRAP_CCACHE");
696 nouveau_bitfield_print(nv50_graph_trap_ccache, ustatus);
698 nv_error(priv, "TRAP_CCACHE %08x %08x %08x %08x"
700 nv_rd32(priv, 0x405000), nv_rd32(priv, 0x405004),
701 nv_rd32(priv, 0x405008), nv_rd32(priv, 0x40500c),
702 nv_rd32(priv, 0x405010), nv_rd32(priv, 0x405014),
703 nv_rd32(priv, 0x40501c));
707 nv_wr32(priv, 0x405018, 0xc0000000);
708 nv_wr32(priv, 0x400108, 0x010);
712 /* Unknown, not seen yet... 0x402000 is the only trap status reg
713 * remaining, so try to handle it anyway. Perhaps related to that
714 * unknown DMA slot on tesla? */
716 ustatus = nv_rd32(priv, 0x402000) & 0x7fffffff;
718 nv_error(priv, "TRAP_UNKC04 0x%08x\n", ustatus);
719 nv_wr32(priv, 0x402000, 0xc0000000);
720 /* no status modifiction on purpose */
723 /* TEXTURE: CUDA texturing units */
724 if (status & 0x040) {
725 nv50_priv_tp_trap(priv, 6, 0x408900, 0x408600, display,
727 nv_wr32(priv, 0x400108, 0x040);
731 /* MP: CUDA execution engines. */
732 if (status & 0x080) {
733 nv50_priv_tp_trap(priv, 7, 0x408314, 0x40831c, display,
735 nv_wr32(priv, 0x400108, 0x080);
739 /* PROP: Handles TP-initiated uncached memory accesses:
740 * l[], g[], stack, 2d surfaces, render targets. */
741 if (status & 0x100) {
742 nv50_priv_tp_trap(priv, 8, 0x408e08, 0x408708, display,
744 nv_wr32(priv, 0x400108, 0x100);
750 nv_error(priv, "TRAP: unknown 0x%08x\n", status);
751 nv_wr32(priv, 0x400108, status);
758 nv50_graph_intr(struct nouveau_subdev *subdev)
760 struct nouveau_fifo *pfifo = nouveau_fifo(subdev);
761 struct nouveau_engine *engine = nv_engine(subdev);
762 struct nouveau_object *engctx;
763 struct nouveau_handle *handle = NULL;
764 struct nv50_graph_priv *priv = (void *)subdev;
765 u32 stat = nv_rd32(priv, 0x400100);
766 u32 inst = nv_rd32(priv, 0x40032c) & 0x0fffffff;
767 u32 addr = nv_rd32(priv, 0x400704);
768 u32 subc = (addr & 0x00070000) >> 16;
769 u32 mthd = (addr & 0x00001ffc);
770 u32 data = nv_rd32(priv, 0x400708);
771 u32 class = nv_rd32(priv, 0x400814);
772 u32 show = stat, show_bitfield = stat;
775 engctx = nouveau_engctx_get(engine, inst);
776 chid = pfifo->chid(pfifo, engctx);
778 if (stat & 0x00000010) {
779 handle = nouveau_handle_get_class(engctx, class);
780 if (handle && !nv_call(handle->object, mthd, data))
782 nouveau_handle_put(handle);
785 if (show & 0x00100000) {
786 u32 ecode = nv_rd32(priv, 0x400110);
787 nv_error(priv, "DATA_ERROR ");
788 nouveau_enum_print(nv50_data_error_names, ecode);
790 show_bitfield &= ~0x00100000;
793 if (stat & 0x00200000) {
794 if (!nv50_graph_trap_handler(priv, show, chid, (u64)inst << 12,
797 show_bitfield &= ~0x00200000;
800 nv_wr32(priv, 0x400100, stat);
801 nv_wr32(priv, 0x400500, 0x00010001);
804 show &= show_bitfield;
806 nv_error(priv, "%s", "");
807 nouveau_bitfield_print(nv50_graph_intr_name, show);
811 "ch %d [0x%010llx %s] subc %d class 0x%04x mthd 0x%04x data 0x%08x\n",
812 chid, (u64)inst << 12, nouveau_client_name(engctx),
813 subc, class, mthd, data);
816 if (nv_rd32(priv, 0x400824) & (1 << 31))
817 nv_wr32(priv, 0x400824, nv_rd32(priv, 0x400824) & ~(1 << 31));
819 nouveau_engctx_put(engctx);
823 nv50_graph_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
824 struct nouveau_oclass *oclass, void *data, u32 size,
825 struct nouveau_object **pobject)
827 struct nv50_graph_priv *priv;
830 ret = nouveau_graph_create(parent, engine, oclass, true, &priv);
831 *pobject = nv_object(priv);
835 nv_subdev(priv)->unit = 0x00201000;
836 nv_subdev(priv)->intr = nv50_graph_intr;
837 nv_engine(priv)->cclass = &nv50_graph_cclass;
839 priv->base.units = nv50_graph_units;
841 switch (nv_device(priv)->chipset) {
843 nv_engine(priv)->sclass = nv50_graph_sclass;
851 nv_engine(priv)->sclass = nv84_graph_sclass;
856 nv_engine(priv)->sclass = nva0_graph_sclass;
861 nv_engine(priv)->sclass = nva3_graph_sclass;
864 nv_engine(priv)->sclass = nvaf_graph_sclass;
869 /* unfortunate hw bug workaround... */
870 if (nv_device(priv)->chipset != 0x50 &&
871 nv_device(priv)->chipset != 0xac)
872 nv_engine(priv)->tlb_flush = nv84_graph_tlb_flush;
874 spin_lock_init(&priv->lock);
879 nv50_graph_init(struct nouveau_object *object)
881 struct nv50_graph_priv *priv = (void *)object;
884 ret = nouveau_graph_init(&priv->base);
888 /* NV_PGRAPH_DEBUG_3_HW_CTX_SWITCH_ENABLED */
889 nv_wr32(priv, 0x40008c, 0x00000004);
891 /* reset/enable traps and interrupts */
892 nv_wr32(priv, 0x400804, 0xc0000000);
893 nv_wr32(priv, 0x406800, 0xc0000000);
894 nv_wr32(priv, 0x400c04, 0xc0000000);
895 nv_wr32(priv, 0x401800, 0xc0000000);
896 nv_wr32(priv, 0x405018, 0xc0000000);
897 nv_wr32(priv, 0x402000, 0xc0000000);
899 units = nv_rd32(priv, 0x001540);
900 for (i = 0; i < 16; i++) {
901 if (!(units & (1 << i)))
904 if (nv_device(priv)->chipset < 0xa0) {
905 nv_wr32(priv, 0x408900 + (i << 12), 0xc0000000);
906 nv_wr32(priv, 0x408e08 + (i << 12), 0xc0000000);
907 nv_wr32(priv, 0x408314 + (i << 12), 0xc0000000);
909 nv_wr32(priv, 0x408600 + (i << 11), 0xc0000000);
910 nv_wr32(priv, 0x408708 + (i << 11), 0xc0000000);
911 nv_wr32(priv, 0x40831c + (i << 11), 0xc0000000);
915 nv_wr32(priv, 0x400108, 0xffffffff);
916 nv_wr32(priv, 0x400138, 0xffffffff);
917 nv_wr32(priv, 0x400100, 0xffffffff);
918 nv_wr32(priv, 0x40013c, 0xffffffff);
919 nv_wr32(priv, 0x400500, 0x00010001);
921 /* upload context program, initialise ctxctl defaults */
922 ret = nv50_grctx_init(nv_device(priv), &priv->size);
926 nv_wr32(priv, 0x400824, 0x00000000);
927 nv_wr32(priv, 0x400828, 0x00000000);
928 nv_wr32(priv, 0x40082c, 0x00000000);
929 nv_wr32(priv, 0x400830, 0x00000000);
930 nv_wr32(priv, 0x40032c, 0x00000000);
931 nv_wr32(priv, 0x400330, 0x00000000);
933 /* some unknown zcull magic */
934 switch (nv_device(priv)->chipset & 0xf0) {
938 nv_wr32(priv, 0x402ca8, 0x00000800);
942 nv_wr32(priv, 0x402cc0, 0x00000000);
943 if (nv_device(priv)->chipset == 0xa0 ||
944 nv_device(priv)->chipset == 0xaa ||
945 nv_device(priv)->chipset == 0xac) {
946 nv_wr32(priv, 0x402ca8, 0x00000802);
948 nv_wr32(priv, 0x402cc0, 0x00000000);
949 nv_wr32(priv, 0x402ca8, 0x00000002);
955 /* zero out zcull regions */
956 for (i = 0; i < 8; i++) {
957 nv_wr32(priv, 0x402c20 + (i * 8), 0x00000000);
958 nv_wr32(priv, 0x402c24 + (i * 8), 0x00000000);
959 nv_wr32(priv, 0x402c28 + (i * 8), 0x00000000);
960 nv_wr32(priv, 0x402c2c + (i * 8), 0x00000000);
965 struct nouveau_oclass
966 nv50_graph_oclass = {
967 .handle = NV_ENGINE(GR, 0x50),
968 .ofuncs = &(struct nouveau_ofuncs) {
969 .ctor = nv50_graph_ctor,
970 .dtor = _nouveau_graph_dtor,
971 .init = nv50_graph_init,
972 .fini = _nouveau_graph_fini,