blob: 46b2c95de4d06c8fc32b0b515ba48592c45e9bc6 [file] [log] [blame]
Ben Skeggs6ee73862009-12-11 19:24:15 +10001/*
2 * Copyright (C) 2007 Ben Skeggs.
3 * All Rights Reserved.
4 *
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:
12 *
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.
16 *
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.
24 *
25 */
26
27#include "drmP.h"
28#include "drm.h"
29#include "nouveau_drv.h"
Ben Skeggsa8eaebc2010-09-01 15:24:31 +100030#include "nouveau_ramht.h"
Francisco Jerez332b2422010-10-20 23:35:40 +020031#include "nouveau_dma.h"
Ben Skeggsa11c3192010-08-27 10:00:25 +100032#include "nouveau_vm.h"
Francisco Jerez332b2422010-10-20 23:35:40 +020033#include "nv50_evo.h"
Ben Skeggs6ee73862009-12-11 19:24:15 +100034
Ben Skeggs2703c212011-04-01 09:50:18 +100035struct nv50_graph_engine {
36 struct nouveau_exec_engine base;
37 u32 ctxprog[512];
38 u32 ctxprog_size;
39 u32 grctx_size;
40};
41
Ben Skeggs2703c212011-04-01 09:50:18 +100042static int
Ben Skeggs6d6538a2011-08-12 09:30:58 +100043nv50_graph_init(struct drm_device *dev, int engine)
Ben Skeggs6ee73862009-12-11 19:24:15 +100044{
Marcin Kościelnicki304424e2010-03-01 00:18:39 +000045 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggs6d6538a2011-08-12 09:30:58 +100046 struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
47 u32 units = nv_rd32(dev, 0x001540);
Marcin Kościelnicki304424e2010-03-01 00:18:39 +000048 int i;
49
Ben Skeggs6ee73862009-12-11 19:24:15 +100050 NV_DEBUG(dev, "\n");
51
Ben Skeggs6d6538a2011-08-12 09:30:58 +100052 /* master reset */
Ben Skeggsdce411c2011-09-29 13:15:17 +100053 nv_mask(dev, 0x000200, 0x00201000, 0x00000000);
54 nv_mask(dev, 0x000200, 0x00201000, 0x00201000);
Ben Skeggs6d6538a2011-08-12 09:30:58 +100055 nv_wr32(dev, 0x40008c, 0x00000004); /* HW_CTX_SWITCH_ENABLED */
56
57 /* reset/enable traps and interrupts */
Ben Skeggs6ee73862009-12-11 19:24:15 +100058 nv_wr32(dev, 0x400804, 0xc0000000);
59 nv_wr32(dev, 0x406800, 0xc0000000);
60 nv_wr32(dev, 0x400c04, 0xc0000000);
Marcin Kościelnicki716abaa2010-01-12 18:21:56 +000061 nv_wr32(dev, 0x401800, 0xc0000000);
Ben Skeggs6ee73862009-12-11 19:24:15 +100062 nv_wr32(dev, 0x405018, 0xc0000000);
63 nv_wr32(dev, 0x402000, 0xc0000000);
Marcin Kościelnicki304424e2010-03-01 00:18:39 +000064 for (i = 0; i < 16; i++) {
Ben Skeggs6d6538a2011-08-12 09:30:58 +100065 if (!(units & (1 << i)))
66 continue;
67
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);
72 } else {
73 nv_wr32(dev, 0x408600 + (i << 11), 0xc0000000);
74 nv_wr32(dev, 0x408708 + (i << 11), 0xc0000000);
75 nv_wr32(dev, 0x40831c + (i << 11), 0xc0000000);
Marcin Kościelnicki304424e2010-03-01 00:18:39 +000076 }
77 }
78
Ben Skeggs6ee73862009-12-11 19:24:15 +100079 nv_wr32(dev, 0x400108, 0xffffffff);
Ben Skeggs6d6538a2011-08-12 09:30:58 +100080 nv_wr32(dev, 0x400138, 0xffffffff);
81 nv_wr32(dev, 0x400100, 0xffffffff);
82 nv_wr32(dev, 0x40013c, 0xffffffff);
Ben Skeggs6ee73862009-12-11 19:24:15 +100083 nv_wr32(dev, 0x400500, 0x00010001);
Ben Skeggs6ee73862009-12-11 19:24:15 +100084
Ben Skeggs6d6538a2011-08-12 09:30:58 +100085 /* 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 */
Ben Skeggs562af102011-02-23 09:00:35 +100096
Ben Skeggs6d6538a2011-08-12 09:30:58 +100097 /* some unknown zcull magic */
Ben Skeggs562af102011-02-23 09:00:35 +100098 switch (dev_priv->chipset & 0xf0) {
99 case 0x50:
100 case 0x80:
101 case 0x90:
102 nv_wr32(dev, 0x402ca8, 0x00000800);
103 break;
104 case 0xa0:
105 default:
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);
111 } else {
112 nv_wr32(dev, 0x402cc0, 0x00000000);
113 nv_wr32(dev, 0x402ca8, 0x00000002);
114 }
115
116 break;
117 }
118
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);
125 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000126
Ben Skeggs6ee73862009-12-11 19:24:15 +1000127 return 0;
128}
129
Ben Skeggs2703c212011-04-01 09:50:18 +1000130static int
Ben Skeggs6c320fe2011-07-20 11:22:33 +1000131nv50_graph_fini(struct drm_device *dev, int engine, bool suspend)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000132{
Ben Skeggs274fec92010-11-03 13:16:18 +1000133 nv_wr32(dev, 0x40013c, 0x00000000);
Ben Skeggs2703c212011-04-01 09:50:18 +1000134 return 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000135}
136
Ben Skeggs2703c212011-04-01 09:50:18 +1000137static int
138nv50_graph_context_new(struct nouveau_channel *chan, int engine)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000139{
140 struct drm_device *dev = chan->dev;
141 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000142 struct nouveau_gpuobj *ramin = chan->ramin;
Ben Skeggs2703c212011-04-01 09:50:18 +1000143 struct nouveau_gpuobj *grctx = NULL;
144 struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000145 int hdr, ret;
146
147 NV_DEBUG(dev, "ch%d\n", chan->id);
148
Ben Skeggs2703c212011-04-01 09:50:18 +1000149 ret = nouveau_gpuobj_new(dev, NULL, pgraph->grctx_size, 0,
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000150 NVOBJ_FLAG_ZERO_ALLOC |
Ben Skeggs2703c212011-04-01 09:50:18 +1000151 NVOBJ_FLAG_ZERO_FREE, &grctx);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000152 if (ret)
153 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000154
Ben Skeggsac94a342010-07-08 15:28:48 +1000155 hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
Ben Skeggsb3beb162010-09-01 15:24:29 +1000156 nv_wo32(ramin, hdr + 0x00, 0x00190002);
Ben Skeggs2703c212011-04-01 09:50:18 +1000157 nv_wo32(ramin, hdr + 0x04, grctx->vinst + grctx->size - 1);
158 nv_wo32(ramin, hdr + 0x08, grctx->vinst);
Ben Skeggsb3beb162010-09-01 15:24:29 +1000159 nv_wo32(ramin, hdr + 0x0c, 0);
160 nv_wo32(ramin, hdr + 0x10, 0);
161 nv_wo32(ramin, hdr + 0x14, 0x00010000);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000162
Ben Skeggsd58086d2012-04-20 11:54:33 +1000163 nv50_grctx_fill(dev, grctx);
Ben Skeggs2703c212011-04-01 09:50:18 +1000164 nv_wo32(grctx, 0x00000, chan->ramin->vinst >> 12);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000165
Ben Skeggsf56cb862010-07-08 11:29:10 +1000166 dev_priv->engine.instmem.flush(dev);
Ben Skeggs2703c212011-04-01 09:50:18 +1000167
168 atomic_inc(&chan->vm->engref[NVOBJ_ENGINE_GR]);
169 chan->engctx[NVOBJ_ENGINE_GR] = grctx;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000170 return 0;
171}
172
Ben Skeggs2703c212011-04-01 09:50:18 +1000173static void
174nv50_graph_context_del(struct nouveau_channel *chan, int engine)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000175{
Ben Skeggs2703c212011-04-01 09:50:18 +1000176 struct nouveau_gpuobj *grctx = chan->engctx[engine];
Ben Skeggs6ee73862009-12-11 19:24:15 +1000177 struct drm_device *dev = chan->dev;
178 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsac94a342010-07-08 15:28:48 +1000179 int i, hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
Francisco Jerez3945e472010-10-18 03:53:39 +0200180
Ben Skeggs6ee73862009-12-11 19:24:15 +1000181 for (i = hdr; i < hdr + 24; i += 4)
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000182 nv_wo32(chan->ramin, i, 0);
Ben Skeggsf56cb862010-07-08 11:29:10 +1000183 dev_priv->engine.instmem.flush(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000184
Ben Skeggs2703c212011-04-01 09:50:18 +1000185 atomic_dec(&chan->vm->engref[engine]);
Ben Skeggs5511d492012-05-01 16:46:28 +1000186 nouveau_gpuobj_ref(NULL, &grctx);
Ben Skeggs2703c212011-04-01 09:50:18 +1000187 chan->engctx[engine] = NULL;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000188}
189
190static int
Ben Skeggs2703c212011-04-01 09:50:18 +1000191nv50_graph_object_new(struct nouveau_channel *chan, int engine,
192 u32 handle, u16 class)
Ben Skeggs4ea52f82011-03-31 13:44:16 +1000193{
194 struct drm_device *dev = chan->dev;
195 struct drm_nouveau_private *dev_priv = dev->dev_private;
196 struct nouveau_gpuobj *obj = NULL;
197 int ret;
198
199 ret = nouveau_gpuobj_new(dev, chan, 16, 16, NVOBJ_FLAG_ZERO_FREE, &obj);
200 if (ret)
201 return ret;
202 obj->engine = 1;
203 obj->class = class;
204
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);
210
211 ret = nouveau_ramht_insert(chan, handle, obj);
212 nouveau_gpuobj_ref(NULL, &obj);
213 return ret;
214}
215
Ben Skeggs274fec92010-11-03 13:16:18 +1000216static void
Ben Skeggs2703c212011-04-01 09:50:18 +1000217nv50_graph_tlb_flush(struct drm_device *dev, int engine)
Ben Skeggs56ac7472010-10-22 10:26:24 +1000218{
Ben Skeggsa11c3192010-08-27 10:00:25 +1000219 nv50_vm_flush_engine(dev, 0);
Ben Skeggs56ac7472010-10-22 10:26:24 +1000220}
221
Ben Skeggs2703c212011-04-01 09:50:18 +1000222static void
223nv84_graph_tlb_flush(struct drm_device *dev, int engine)
Ben Skeggs56ac7472010-10-22 10:26:24 +1000224{
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;
228 unsigned long flags;
229 u64 start;
230 u32 tmp;
231
232 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
233 nv_mask(dev, 0x400500, 0x00000001, 0x00000000);
234
235 start = ptimer->read(dev);
236 do {
237 idle = true;
238
239 for (tmp = nv_rd32(dev, 0x400380); tmp && idle; tmp >>= 3) {
240 if ((tmp & 7) == 1)
241 idle = false;
242 }
243
244 for (tmp = nv_rd32(dev, 0x400384); tmp && idle; tmp >>= 3) {
245 if ((tmp & 7) == 1)
246 idle = false;
247 }
248
249 for (tmp = nv_rd32(dev, 0x400388); tmp && idle; tmp >>= 3) {
250 if ((tmp & 7) == 1)
251 idle = false;
252 }
253 } while (!idle && !(timeout = ptimer->read(dev) - start > 2000000000));
254
255 if (timeout) {
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));
260 }
261
Ben Skeggsa11c3192010-08-27 10:00:25 +1000262 nv50_vm_flush_engine(dev, 0);
Ben Skeggs56ac7472010-10-22 10:26:24 +1000263
264 nv_mask(dev, 0x400500, 0x00000001, 0x00000001);
265 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
266}
Ben Skeggs274fec92010-11-03 13:16:18 +1000267
Emil Velikovf9ec8f62011-03-19 23:31:53 +0000268static struct nouveau_enum nv50_mp_exec_error_names[] = {
Ben Skeggsbb9b18a2011-03-08 08:39:43 +1000269 { 3, "STACK_UNDERFLOW", NULL },
270 { 4, "QUADON_ACTIVE", NULL },
271 { 8, "TIMEOUT", NULL },
272 { 0x10, "INVALID_OPCODE", NULL },
273 { 0x40, "BREAKPOINT", NULL },
Ben Skeggs274fec92010-11-03 13:16:18 +1000274 {}
275};
276
277static struct nouveau_bitfield nv50_graph_trap_m2mf[] = {
278 { 0x00000001, "NOTIFY" },
279 { 0x00000002, "IN" },
280 { 0x00000004, "OUT" },
281 {}
282};
283
284static struct nouveau_bitfield nv50_graph_trap_vfetch[] = {
285 { 0x00000001, "FAULT" },
286 {}
287};
288
289static struct nouveau_bitfield nv50_graph_trap_strmout[] = {
290 { 0x00000001, "FAULT" },
291 {}
292};
293
294static struct nouveau_bitfield nv50_graph_trap_ccache[] = {
295 { 0x00000001, "FAULT" },
296 {}
297};
298
299/* There must be a *lot* of these. Will take some time to gather them up. */
Ben Skeggs6effe392010-12-30 11:48:03 +1000300struct nouveau_enum nv50_data_error_names[] = {
Ben Skeggsbb9b18a2011-03-08 08:39:43 +1000301 { 0x00000003, "INVALID_QUERY_OR_TEXTURE", 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 { 0x00000027, "CP_MORE_PARAMS_THAN_SHARED", NULL },
328 { 0x00000028, "CP_NO_REG_SPACE_STRIPED", NULL },
329 { 0x00000029, "CP_NO_REG_SPACE_PACKED", NULL },
330 { 0x0000002a, "CP_NOT_ENOUGH_WARPS", NULL },
331 { 0x0000002b, "CP_BLOCK_SIZE_MISMATCH", NULL },
332 { 0x0000002c, "CP_NOT_ENOUGH_LOCAL_WARPS", NULL },
333 { 0x0000002d, "CP_NOT_ENOUGH_STACK_WARPS", NULL },
334 { 0x0000002e, "CP_NO_BLOCKDIM_LATCH", NULL },
335 { 0x00000031, "ENG2D_FORMAT_MISMATCH", NULL },
336 { 0x0000003f, "PRIMITIVE_ID_NEEDS_GP", NULL },
337 { 0x00000044, "SEMANTIC_VIEWPORT_OVER_LIMIT", NULL },
338 { 0x00000045, "SEMANTIC_COLOR_FRONT_OVER_LIMIT", NULL },
339 { 0x00000046, "LAYER_ID_NEEDS_GP", NULL },
340 { 0x00000047, "SEMANTIC_CLIP_OVER_LIMIT", NULL },
341 { 0x00000048, "SEMANTIC_PTSZ_OVER_LIMIT", NULL },
Ben Skeggs274fec92010-11-03 13:16:18 +1000342 {}
343};
344
345static struct nouveau_bitfield nv50_graph_intr[] = {
346 { 0x00000001, "NOTIFY" },
347 { 0x00000002, "COMPUTE_QUERY" },
348 { 0x00000010, "ILLEGAL_MTHD" },
349 { 0x00000020, "ILLEGAL_CLASS" },
350 { 0x00000040, "DOUBLE_NOTIFY" },
351 { 0x00001000, "CONTEXT_SWITCH" },
352 { 0x00010000, "BUFFER_NOTIFY" },
353 { 0x00100000, "DATA_ERROR" },
354 { 0x00200000, "TRAP" },
355 { 0x01000000, "SINGLE_STEP" },
356 {}
357};
358
359static void
360nv50_pgraph_mp_trap(struct drm_device *dev, int tpid, int display)
361{
362 struct drm_nouveau_private *dev_priv = dev->dev_private;
363 uint32_t units = nv_rd32(dev, 0x1540);
364 uint32_t addr, mp10, status, pc, oplow, ophigh;
365 int i;
366 int mps = 0;
367 for (i = 0; i < 4; i++) {
368 if (!(units & 1 << (i+24)))
369 continue;
370 if (dev_priv->chipset < 0xa0)
371 addr = 0x408200 + (tpid << 12) + (i << 7);
372 else
373 addr = 0x408100 + (tpid << 11) + (i << 7);
374 mp10 = nv_rd32(dev, addr + 0x10);
375 status = nv_rd32(dev, addr + 0x14);
376 if (!status)
377 continue;
378 if (display) {
379 nv_rd32(dev, addr + 0x20);
380 pc = nv_rd32(dev, addr + 0x24);
381 oplow = nv_rd32(dev, addr + 0x70);
Emil Velikov0b89a072011-03-19 23:31:54 +0000382 ophigh = nv_rd32(dev, addr + 0x74);
Ben Skeggs274fec92010-11-03 13:16:18 +1000383 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - "
384 "TP %d MP %d: ", tpid, i);
385 nouveau_enum_print(nv50_mp_exec_error_names, status);
386 printk(" at %06x warp %d, opcode %08x %08x\n",
387 pc&0xffffff, pc >> 24,
388 oplow, ophigh);
389 }
390 nv_wr32(dev, addr + 0x10, mp10);
391 nv_wr32(dev, addr + 0x14, 0);
392 mps++;
393 }
394 if (!mps && display)
395 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - TP %d: "
396 "No MPs claiming errors?\n", tpid);
397}
398
399static void
400nv50_pgraph_tp_trap(struct drm_device *dev, int type, uint32_t ustatus_old,
401 uint32_t ustatus_new, int display, const char *name)
402{
403 struct drm_nouveau_private *dev_priv = dev->dev_private;
404 int tps = 0;
405 uint32_t units = nv_rd32(dev, 0x1540);
406 int i, r;
407 uint32_t ustatus_addr, ustatus;
408 for (i = 0; i < 16; i++) {
409 if (!(units & (1 << i)))
410 continue;
411 if (dev_priv->chipset < 0xa0)
412 ustatus_addr = ustatus_old + (i << 12);
413 else
414 ustatus_addr = ustatus_new + (i << 11);
415 ustatus = nv_rd32(dev, ustatus_addr) & 0x7fffffff;
416 if (!ustatus)
417 continue;
418 tps++;
419 switch (type) {
420 case 6: /* texture error... unknown for now */
Ben Skeggs274fec92010-11-03 13:16:18 +1000421 if (display) {
422 NV_ERROR(dev, "magic set %d:\n", i);
423 for (r = ustatus_addr + 4; r <= ustatus_addr + 0x10; r += 4)
424 NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r,
425 nv_rd32(dev, r));
426 }
427 break;
428 case 7: /* MP error */
Maxim Levitskyc983e6f2011-10-09 22:58:32 +0200429 if (ustatus & 0x04030000) {
Ben Skeggs274fec92010-11-03 13:16:18 +1000430 nv50_pgraph_mp_trap(dev, i, display);
Maxim Levitskyc983e6f2011-10-09 22:58:32 +0200431 ustatus &= ~0x04030000;
Ben Skeggs274fec92010-11-03 13:16:18 +1000432 }
433 break;
434 case 8: /* TPDMA error */
435 {
436 uint32_t e0c = nv_rd32(dev, ustatus_addr + 4);
437 uint32_t e10 = nv_rd32(dev, ustatus_addr + 8);
438 uint32_t e14 = nv_rd32(dev, ustatus_addr + 0xc);
439 uint32_t e18 = nv_rd32(dev, ustatus_addr + 0x10);
440 uint32_t e1c = nv_rd32(dev, ustatus_addr + 0x14);
441 uint32_t e20 = nv_rd32(dev, ustatus_addr + 0x18);
442 uint32_t e24 = nv_rd32(dev, ustatus_addr + 0x1c);
Ben Skeggs274fec92010-11-03 13:16:18 +1000443 /* 2d engine destination */
444 if (ustatus & 0x00000010) {
445 if (display) {
446 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - Unknown fault at address %02x%08x\n",
447 i, e14, e10);
448 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
449 i, e0c, e18, e1c, e20, e24);
450 }
451 ustatus &= ~0x00000010;
452 }
453 /* Render target */
454 if (ustatus & 0x00000040) {
455 if (display) {
456 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - Unknown fault at address %02x%08x\n",
457 i, e14, e10);
458 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
459 i, e0c, e18, e1c, e20, e24);
460 }
461 ustatus &= ~0x00000040;
462 }
463 /* CUDA memory: l[], g[] or stack. */
464 if (ustatus & 0x00000080) {
465 if (display) {
466 if (e18 & 0x80000000) {
467 /* g[] read fault? */
468 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global read fault at address %02x%08x\n",
469 i, e14, e10 | ((e18 >> 24) & 0x1f));
470 e18 &= ~0x1f000000;
471 } else if (e18 & 0xc) {
472 /* g[] write fault? */
473 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global write fault at address %02x%08x\n",
474 i, e14, e10 | ((e18 >> 7) & 0x1f));
475 e18 &= ~0x00000f80;
476 } else {
477 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Unknown CUDA fault at address %02x%08x\n",
478 i, e14, e10);
479 }
480 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
481 i, e0c, e18, e1c, e20, e24);
482 }
483 ustatus &= ~0x00000080;
484 }
485 }
486 break;
487 }
488 if (ustatus) {
489 if (display)
490 NV_INFO(dev, "%s - TP%d: Unhandled ustatus 0x%08x\n", name, i, ustatus);
491 }
492 nv_wr32(dev, ustatus_addr, 0xc0000000);
493 }
494
495 if (!tps && display)
496 NV_INFO(dev, "%s - No TPs claiming errors?\n", name);
497}
498
499static int
500nv50_pgraph_trap_handler(struct drm_device *dev, u32 display, u64 inst, u32 chid)
501{
502 u32 status = nv_rd32(dev, 0x400108);
503 u32 ustatus;
504
505 if (!status && display) {
506 NV_INFO(dev, "PGRAPH - TRAP: no units reporting traps?\n");
507 return 1;
508 }
509
510 /* DISPATCH: Relays commands to other units and handles NOTIFY,
511 * COND, QUERY. If you get a trap from it, the command is still stuck
512 * in DISPATCH and you need to do something about it. */
513 if (status & 0x001) {
514 ustatus = nv_rd32(dev, 0x400804) & 0x7fffffff;
515 if (!ustatus && display) {
516 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - no ustatus?\n");
517 }
518
519 nv_wr32(dev, 0x400500, 0x00000000);
520
521 /* Known to be triggered by screwed up NOTIFY and COND... */
522 if (ustatus & 0x00000001) {
523 u32 addr = nv_rd32(dev, 0x400808);
524 u32 subc = (addr & 0x00070000) >> 16;
525 u32 mthd = (addr & 0x00001ffc);
526 u32 datal = nv_rd32(dev, 0x40080c);
527 u32 datah = nv_rd32(dev, 0x400810);
528 u32 class = nv_rd32(dev, 0x400814);
529 u32 r848 = nv_rd32(dev, 0x400848);
530
531 NV_INFO(dev, "PGRAPH - TRAP DISPATCH_FAULT\n");
532 if (display && (addr & 0x80000000)) {
533 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
534 "subc %d class 0x%04x mthd 0x%04x "
535 "data 0x%08x%08x "
536 "400808 0x%08x 400848 0x%08x\n",
537 chid, inst, subc, class, mthd, datah,
538 datal, addr, r848);
539 } else
540 if (display) {
541 NV_INFO(dev, "PGRAPH - no stuck command?\n");
542 }
543
544 nv_wr32(dev, 0x400808, 0);
545 nv_wr32(dev, 0x4008e8, nv_rd32(dev, 0x4008e8) & 3);
546 nv_wr32(dev, 0x400848, 0);
547 ustatus &= ~0x00000001;
548 }
549
550 if (ustatus & 0x00000002) {
551 u32 addr = nv_rd32(dev, 0x40084c);
552 u32 subc = (addr & 0x00070000) >> 16;
553 u32 mthd = (addr & 0x00001ffc);
554 u32 data = nv_rd32(dev, 0x40085c);
555 u32 class = nv_rd32(dev, 0x400814);
556
557 NV_INFO(dev, "PGRAPH - TRAP DISPATCH_QUERY\n");
558 if (display && (addr & 0x80000000)) {
559 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
560 "subc %d class 0x%04x mthd 0x%04x "
561 "data 0x%08x 40084c 0x%08x\n",
562 chid, inst, subc, class, mthd,
563 data, addr);
564 } else
565 if (display) {
566 NV_INFO(dev, "PGRAPH - no stuck command?\n");
567 }
568
569 nv_wr32(dev, 0x40084c, 0);
570 ustatus &= ~0x00000002;
571 }
572
573 if (ustatus && display) {
574 NV_INFO(dev, "PGRAPH - TRAP_DISPATCH (unknown "
575 "0x%08x)\n", ustatus);
576 }
577
578 nv_wr32(dev, 0x400804, 0xc0000000);
579 nv_wr32(dev, 0x400108, 0x001);
580 status &= ~0x001;
581 if (!status)
582 return 0;
583 }
584
585 /* M2MF: Memory to memory copy engine. */
586 if (status & 0x002) {
587 u32 ustatus = nv_rd32(dev, 0x406800) & 0x7fffffff;
588 if (display) {
589 NV_INFO(dev, "PGRAPH - TRAP_M2MF");
590 nouveau_bitfield_print(nv50_graph_trap_m2mf, ustatus);
591 printk("\n");
592 NV_INFO(dev, "PGRAPH - TRAP_M2MF %08x %08x %08x %08x\n",
593 nv_rd32(dev, 0x406804), nv_rd32(dev, 0x406808),
594 nv_rd32(dev, 0x40680c), nv_rd32(dev, 0x406810));
595
596 }
597
598 /* No sane way found yet -- just reset the bugger. */
599 nv_wr32(dev, 0x400040, 2);
600 nv_wr32(dev, 0x400040, 0);
601 nv_wr32(dev, 0x406800, 0xc0000000);
602 nv_wr32(dev, 0x400108, 0x002);
603 status &= ~0x002;
604 }
605
606 /* VFETCH: Fetches data from vertex buffers. */
607 if (status & 0x004) {
608 u32 ustatus = nv_rd32(dev, 0x400c04) & 0x7fffffff;
609 if (display) {
610 NV_INFO(dev, "PGRAPH - TRAP_VFETCH");
611 nouveau_bitfield_print(nv50_graph_trap_vfetch, ustatus);
612 printk("\n");
613 NV_INFO(dev, "PGRAPH - TRAP_VFETCH %08x %08x %08x %08x\n",
614 nv_rd32(dev, 0x400c00), nv_rd32(dev, 0x400c08),
615 nv_rd32(dev, 0x400c0c), nv_rd32(dev, 0x400c10));
616 }
617
618 nv_wr32(dev, 0x400c04, 0xc0000000);
619 nv_wr32(dev, 0x400108, 0x004);
620 status &= ~0x004;
621 }
622
623 /* STRMOUT: DirectX streamout / OpenGL transform feedback. */
624 if (status & 0x008) {
625 ustatus = nv_rd32(dev, 0x401800) & 0x7fffffff;
626 if (display) {
627 NV_INFO(dev, "PGRAPH - TRAP_STRMOUT");
628 nouveau_bitfield_print(nv50_graph_trap_strmout, ustatus);
629 printk("\n");
630 NV_INFO(dev, "PGRAPH - TRAP_STRMOUT %08x %08x %08x %08x\n",
631 nv_rd32(dev, 0x401804), nv_rd32(dev, 0x401808),
632 nv_rd32(dev, 0x40180c), nv_rd32(dev, 0x401810));
633
634 }
635
636 /* No sane way found yet -- just reset the bugger. */
637 nv_wr32(dev, 0x400040, 0x80);
638 nv_wr32(dev, 0x400040, 0);
639 nv_wr32(dev, 0x401800, 0xc0000000);
640 nv_wr32(dev, 0x400108, 0x008);
641 status &= ~0x008;
642 }
643
644 /* CCACHE: Handles code and c[] caches and fills them. */
645 if (status & 0x010) {
646 ustatus = nv_rd32(dev, 0x405018) & 0x7fffffff;
647 if (display) {
648 NV_INFO(dev, "PGRAPH - TRAP_CCACHE");
649 nouveau_bitfield_print(nv50_graph_trap_ccache, ustatus);
650 printk("\n");
651 NV_INFO(dev, "PGRAPH - TRAP_CCACHE %08x %08x %08x %08x"
652 " %08x %08x %08x\n",
Marcin Slusarz4dcf9052011-02-13 20:46:41 +0100653 nv_rd32(dev, 0x405000), nv_rd32(dev, 0x405004),
654 nv_rd32(dev, 0x405008), nv_rd32(dev, 0x40500c),
655 nv_rd32(dev, 0x405010), nv_rd32(dev, 0x405014),
656 nv_rd32(dev, 0x40501c));
Ben Skeggs274fec92010-11-03 13:16:18 +1000657
658 }
659
660 nv_wr32(dev, 0x405018, 0xc0000000);
661 nv_wr32(dev, 0x400108, 0x010);
662 status &= ~0x010;
663 }
664
665 /* Unknown, not seen yet... 0x402000 is the only trap status reg
666 * remaining, so try to handle it anyway. Perhaps related to that
667 * unknown DMA slot on tesla? */
668 if (status & 0x20) {
669 ustatus = nv_rd32(dev, 0x402000) & 0x7fffffff;
670 if (display)
671 NV_INFO(dev, "PGRAPH - TRAP_UNKC04 0x%08x\n", ustatus);
672 nv_wr32(dev, 0x402000, 0xc0000000);
673 /* no status modifiction on purpose */
674 }
675
676 /* TEXTURE: CUDA texturing units */
677 if (status & 0x040) {
678 nv50_pgraph_tp_trap(dev, 6, 0x408900, 0x408600, display,
679 "PGRAPH - TRAP_TEXTURE");
680 nv_wr32(dev, 0x400108, 0x040);
681 status &= ~0x040;
682 }
683
684 /* MP: CUDA execution engines. */
685 if (status & 0x080) {
686 nv50_pgraph_tp_trap(dev, 7, 0x408314, 0x40831c, display,
687 "PGRAPH - TRAP_MP");
688 nv_wr32(dev, 0x400108, 0x080);
689 status &= ~0x080;
690 }
691
692 /* TPDMA: Handles TP-initiated uncached memory accesses:
693 * l[], g[], stack, 2d surfaces, render targets. */
694 if (status & 0x100) {
695 nv50_pgraph_tp_trap(dev, 8, 0x408e08, 0x408708, display,
696 "PGRAPH - TRAP_TPDMA");
697 nv_wr32(dev, 0x400108, 0x100);
698 status &= ~0x100;
699 }
700
701 if (status) {
702 if (display)
703 NV_INFO(dev, "PGRAPH - TRAP: unknown 0x%08x\n", status);
704 nv_wr32(dev, 0x400108, status);
705 }
706
707 return 1;
708}
709
Ben Skeggs7ff54412011-03-18 10:25:59 +1000710int
Ben Skeggs274fec92010-11-03 13:16:18 +1000711nv50_graph_isr_chid(struct drm_device *dev, u64 inst)
712{
713 struct drm_nouveau_private *dev_priv = dev->dev_private;
714 struct nouveau_channel *chan;
715 unsigned long flags;
716 int i;
717
718 spin_lock_irqsave(&dev_priv->channels.lock, flags);
719 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
720 chan = dev_priv->channels.ptr[i];
721 if (!chan || !chan->ramin)
722 continue;
723
724 if (inst == chan->ramin->vinst)
725 break;
726 }
727 spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
728 return i;
729}
730
731static void
732nv50_graph_isr(struct drm_device *dev)
733{
734 u32 stat;
735
736 while ((stat = nv_rd32(dev, 0x400100))) {
737 u64 inst = (u64)(nv_rd32(dev, 0x40032c) & 0x0fffffff) << 12;
738 u32 chid = nv50_graph_isr_chid(dev, inst);
739 u32 addr = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR);
740 u32 subc = (addr & 0x00070000) >> 16;
741 u32 mthd = (addr & 0x00001ffc);
742 u32 data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA);
743 u32 class = nv_rd32(dev, 0x400814);
744 u32 show = stat;
745
746 if (stat & 0x00000010) {
747 if (!nouveau_gpuobj_mthd_call2(dev, chid, class,
748 mthd, data))
749 show &= ~0x00000010;
750 }
751
Ben Skeggs274fec92010-11-03 13:16:18 +1000752 show = (show && nouveau_ratelimit()) ? show : 0;
753
754 if (show & 0x00100000) {
755 u32 ecode = nv_rd32(dev, 0x400110);
756 NV_INFO(dev, "PGRAPH - DATA_ERROR ");
757 nouveau_enum_print(nv50_data_error_names, ecode);
758 printk("\n");
759 }
760
761 if (stat & 0x00200000) {
762 if (!nv50_pgraph_trap_handler(dev, show, inst, chid))
763 show &= ~0x00200000;
764 }
765
766 nv_wr32(dev, 0x400100, stat);
767 nv_wr32(dev, 0x400500, 0x00010001);
768
769 if (show) {
770 NV_INFO(dev, "PGRAPH -");
771 nouveau_bitfield_print(nv50_graph_intr, show);
772 printk("\n");
773 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) subc %d "
774 "class 0x%04x mthd 0x%04x data 0x%08x\n",
775 chid, inst, subc, class, mthd, data);
Ben Skeggs6fdb3832011-03-08 09:57:17 +1000776 nv50_fb_vm_trap(dev, 1);
Ben Skeggs274fec92010-11-03 13:16:18 +1000777 }
778 }
779
780 if (nv_rd32(dev, 0x400824) & (1 << 31))
781 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) & ~(1 << 31));
782}
Ben Skeggs2703c212011-04-01 09:50:18 +1000783
784static void
785nv50_graph_destroy(struct drm_device *dev, int engine)
786{
787 struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
788
789 NVOBJ_ENGINE_DEL(dev, GR);
790
791 nouveau_irq_unregister(dev, 12);
792 kfree(pgraph);
793}
794
795int
796nv50_graph_create(struct drm_device *dev)
797{
798 struct drm_nouveau_private *dev_priv = dev->dev_private;
799 struct nv50_graph_engine *pgraph;
Ben Skeggs2703c212011-04-01 09:50:18 +1000800 int ret;
801
802 pgraph = kzalloc(sizeof(*pgraph),GFP_KERNEL);
803 if (!pgraph)
804 return -ENOMEM;
805
Ben Skeggsd58086d2012-04-20 11:54:33 +1000806 ret = nv50_grctx_init(dev, pgraph->ctxprog, ARRAY_SIZE(pgraph->ctxprog),
807 &pgraph->ctxprog_size,
808 &pgraph->grctx_size);
Ben Skeggs2703c212011-04-01 09:50:18 +1000809 if (ret) {
810 NV_ERROR(dev, "PGRAPH: ctxprog build failed\n");
Ben Skeggs2703c212011-04-01 09:50:18 +1000811 kfree(pgraph);
812 return 0;
813 }
814
Ben Skeggs2703c212011-04-01 09:50:18 +1000815 pgraph->base.destroy = nv50_graph_destroy;
816 pgraph->base.init = nv50_graph_init;
817 pgraph->base.fini = nv50_graph_fini;
818 pgraph->base.context_new = nv50_graph_context_new;
819 pgraph->base.context_del = nv50_graph_context_del;
820 pgraph->base.object_new = nv50_graph_object_new;
821 if (dev_priv->chipset == 0x50 || dev_priv->chipset == 0xac)
822 pgraph->base.tlb_flush = nv50_graph_tlb_flush;
823 else
824 pgraph->base.tlb_flush = nv84_graph_tlb_flush;
825
826 nouveau_irq_register(dev, 12, nv50_graph_isr);
827
Ben Skeggs2703c212011-04-01 09:50:18 +1000828 NVOBJ_ENGINE_ADD(dev, GR, &pgraph->base);
829 NVOBJ_CLASS(dev, 0x0030, GR); /* null */
830 NVOBJ_CLASS(dev, 0x5039, GR); /* m2mf */
831 NVOBJ_CLASS(dev, 0x502d, GR); /* 2d */
832
833 /* tesla */
834 if (dev_priv->chipset == 0x50)
835 NVOBJ_CLASS(dev, 0x5097, GR); /* tesla (nv50) */
836 else
837 if (dev_priv->chipset < 0xa0)
838 NVOBJ_CLASS(dev, 0x8297, GR); /* tesla (nv8x/nv9x) */
839 else {
840 switch (dev_priv->chipset) {
841 case 0xa0:
842 case 0xaa:
843 case 0xac:
844 NVOBJ_CLASS(dev, 0x8397, GR);
845 break;
846 case 0xa3:
847 case 0xa5:
848 case 0xa8:
849 NVOBJ_CLASS(dev, 0x8597, GR);
850 break;
851 case 0xaf:
852 NVOBJ_CLASS(dev, 0x8697, GR);
853 break;
854 }
855 }
856
857 /* compute */
858 NVOBJ_CLASS(dev, 0x50c0, GR);
859 if (dev_priv->chipset > 0xa0 &&
860 dev_priv->chipset != 0xaa &&
861 dev_priv->chipset != 0xac)
862 NVOBJ_CLASS(dev, 0x85c0, GR);
863
864 return 0;
865}