blob: 69be4d190778c0d4e403798764d65e71479d1b4c [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
43nv50_graph_do_load_context(struct drm_device *dev, uint32_t inst)
44{
45 uint32_t fifo = nv_rd32(dev, 0x400500);
46
47 nv_wr32(dev, 0x400500, fifo & ~1);
48 nv_wr32(dev, 0x400784, inst);
49 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) | 0x40);
50 nv_wr32(dev, 0x400320, nv_rd32(dev, 0x400320) | 0x11);
51 nv_wr32(dev, 0x400040, 0xffffffff);
52 (void)nv_rd32(dev, 0x400040);
53 nv_wr32(dev, 0x400040, 0x00000000);
54 nv_wr32(dev, 0x400304, nv_rd32(dev, 0x400304) | 1);
55
56 if (nouveau_wait_for_idle(dev))
57 nv_wr32(dev, 0x40032c, inst | (1<<31));
58 nv_wr32(dev, 0x400500, fifo);
59
60 return 0;
61}
62
63static int
64nv50_graph_unload_context(struct drm_device *dev)
65{
66 uint32_t inst;
67
68 inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_CUR);
69 if (!(inst & NV50_PGRAPH_CTXCTL_CUR_LOADED))
70 return 0;
71 inst &= NV50_PGRAPH_CTXCTL_CUR_INSTANCE;
72
73 nouveau_wait_for_idle(dev);
74 nv_wr32(dev, 0x400784, inst);
75 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) | 0x20);
76 nv_wr32(dev, 0x400304, nv_rd32(dev, 0x400304) | 0x01);
77 nouveau_wait_for_idle(dev);
78
79 nv_wr32(dev, NV50_PGRAPH_CTXCTL_CUR, inst);
80 return 0;
81}
Ben Skeggsb8c157d2010-10-20 10:39:35 +100082
Ben Skeggs6d6538a2011-08-12 09:30:58 +100083static int
84nv50_graph_init(struct drm_device *dev, int engine)
Ben Skeggs6ee73862009-12-11 19:24:15 +100085{
Marcin Kościelnicki304424e2010-03-01 00:18:39 +000086 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggs6d6538a2011-08-12 09:30:58 +100087 struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
88 u32 units = nv_rd32(dev, 0x001540);
Marcin Kościelnicki304424e2010-03-01 00:18:39 +000089 int i;
90
Ben Skeggs6ee73862009-12-11 19:24:15 +100091 NV_DEBUG(dev, "\n");
92
Ben Skeggs6d6538a2011-08-12 09:30:58 +100093 /* master reset */
Ben Skeggsdce411c2011-09-29 13:15:17 +100094 nv_mask(dev, 0x000200, 0x00201000, 0x00000000);
95 nv_mask(dev, 0x000200, 0x00201000, 0x00201000);
Ben Skeggs6d6538a2011-08-12 09:30:58 +100096 nv_wr32(dev, 0x40008c, 0x00000004); /* HW_CTX_SWITCH_ENABLED */
97
98 /* reset/enable traps and interrupts */
Ben Skeggs6ee73862009-12-11 19:24:15 +100099 nv_wr32(dev, 0x400804, 0xc0000000);
100 nv_wr32(dev, 0x406800, 0xc0000000);
101 nv_wr32(dev, 0x400c04, 0xc0000000);
Marcin Kościelnicki716abaa2010-01-12 18:21:56 +0000102 nv_wr32(dev, 0x401800, 0xc0000000);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000103 nv_wr32(dev, 0x405018, 0xc0000000);
104 nv_wr32(dev, 0x402000, 0xc0000000);
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000105 for (i = 0; i < 16; i++) {
Ben Skeggs6d6538a2011-08-12 09:30:58 +1000106 if (!(units & (1 << i)))
107 continue;
108
109 if (dev_priv->chipset < 0xa0) {
110 nv_wr32(dev, 0x408900 + (i << 12), 0xc0000000);
111 nv_wr32(dev, 0x408e08 + (i << 12), 0xc0000000);
112 nv_wr32(dev, 0x408314 + (i << 12), 0xc0000000);
113 } else {
114 nv_wr32(dev, 0x408600 + (i << 11), 0xc0000000);
115 nv_wr32(dev, 0x408708 + (i << 11), 0xc0000000);
116 nv_wr32(dev, 0x40831c + (i << 11), 0xc0000000);
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000117 }
118 }
119
Ben Skeggs6ee73862009-12-11 19:24:15 +1000120 nv_wr32(dev, 0x400108, 0xffffffff);
Ben Skeggs6d6538a2011-08-12 09:30:58 +1000121 nv_wr32(dev, 0x400138, 0xffffffff);
122 nv_wr32(dev, 0x400100, 0xffffffff);
123 nv_wr32(dev, 0x40013c, 0xffffffff);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000124 nv_wr32(dev, 0x400500, 0x00010001);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000125
Ben Skeggs6d6538a2011-08-12 09:30:58 +1000126 /* upload context program, initialise ctxctl defaults */
127 nv_wr32(dev, 0x400324, 0x00000000);
128 for (i = 0; i < pgraph->ctxprog_size; i++)
129 nv_wr32(dev, 0x400328, pgraph->ctxprog[i]);
130 nv_wr32(dev, 0x400824, 0x00000000);
131 nv_wr32(dev, 0x400828, 0x00000000);
132 nv_wr32(dev, 0x40082c, 0x00000000);
133 nv_wr32(dev, 0x400830, 0x00000000);
134 nv_wr32(dev, 0x400724, 0x00000000);
135 nv_wr32(dev, 0x40032c, 0x00000000);
136 nv_wr32(dev, 0x400320, 4); /* CTXCTL_CMD = NEWCTXDMA */
Ben Skeggs562af102011-02-23 09:00:35 +1000137
Ben Skeggs6d6538a2011-08-12 09:30:58 +1000138 /* some unknown zcull magic */
Ben Skeggs562af102011-02-23 09:00:35 +1000139 switch (dev_priv->chipset & 0xf0) {
140 case 0x50:
141 case 0x80:
142 case 0x90:
143 nv_wr32(dev, 0x402ca8, 0x00000800);
144 break;
145 case 0xa0:
146 default:
147 nv_wr32(dev, 0x402cc0, 0x00000000);
148 if (dev_priv->chipset == 0xa0 ||
149 dev_priv->chipset == 0xaa ||
150 dev_priv->chipset == 0xac) {
151 nv_wr32(dev, 0x402ca8, 0x00000802);
152 } else {
153 nv_wr32(dev, 0x402cc0, 0x00000000);
154 nv_wr32(dev, 0x402ca8, 0x00000002);
155 }
156
157 break;
158 }
159
160 /* zero out zcull regions */
161 for (i = 0; i < 8; i++) {
162 nv_wr32(dev, 0x402c20 + (i * 8), 0x00000000);
163 nv_wr32(dev, 0x402c24 + (i * 8), 0x00000000);
164 nv_wr32(dev, 0x402c28 + (i * 8), 0x00000000);
165 nv_wr32(dev, 0x402c2c + (i * 8), 0x00000000);
166 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000167
Ben Skeggs6ee73862009-12-11 19:24:15 +1000168 return 0;
169}
170
Ben Skeggs2703c212011-04-01 09:50:18 +1000171static int
Ben Skeggs6c320fe2011-07-20 11:22:33 +1000172nv50_graph_fini(struct drm_device *dev, int engine, bool suspend)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000173{
Ben Skeggs274fec92010-11-03 13:16:18 +1000174 nv_wr32(dev, 0x40013c, 0x00000000);
Ben Skeggs2703c212011-04-01 09:50:18 +1000175 return 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000176}
177
Ben Skeggs2703c212011-04-01 09:50:18 +1000178static int
179nv50_graph_context_new(struct nouveau_channel *chan, int engine)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000180{
181 struct drm_device *dev = chan->dev;
182 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000183 struct nouveau_gpuobj *ramin = chan->ramin;
Ben Skeggs2703c212011-04-01 09:50:18 +1000184 struct nouveau_gpuobj *grctx = NULL;
185 struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000186 int hdr, ret;
187
188 NV_DEBUG(dev, "ch%d\n", chan->id);
189
Ben Skeggs2703c212011-04-01 09:50:18 +1000190 ret = nouveau_gpuobj_new(dev, NULL, pgraph->grctx_size, 0,
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000191 NVOBJ_FLAG_ZERO_ALLOC |
Ben Skeggs2703c212011-04-01 09:50:18 +1000192 NVOBJ_FLAG_ZERO_FREE, &grctx);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000193 if (ret)
194 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000195
Ben Skeggsac94a342010-07-08 15:28:48 +1000196 hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
Ben Skeggsb3beb162010-09-01 15:24:29 +1000197 nv_wo32(ramin, hdr + 0x00, 0x00190002);
Ben Skeggs2703c212011-04-01 09:50:18 +1000198 nv_wo32(ramin, hdr + 0x04, grctx->vinst + grctx->size - 1);
199 nv_wo32(ramin, hdr + 0x08, grctx->vinst);
Ben Skeggsb3beb162010-09-01 15:24:29 +1000200 nv_wo32(ramin, hdr + 0x0c, 0);
201 nv_wo32(ramin, hdr + 0x10, 0);
202 nv_wo32(ramin, hdr + 0x14, 0x00010000);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000203
Ben Skeggsd58086d2012-04-20 11:54:33 +1000204 nv50_grctx_fill(dev, grctx);
Ben Skeggs2703c212011-04-01 09:50:18 +1000205 nv_wo32(grctx, 0x00000, chan->ramin->vinst >> 12);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000206
Ben Skeggsf56cb862010-07-08 11:29:10 +1000207 dev_priv->engine.instmem.flush(dev);
Ben Skeggs2703c212011-04-01 09:50:18 +1000208
209 atomic_inc(&chan->vm->engref[NVOBJ_ENGINE_GR]);
210 chan->engctx[NVOBJ_ENGINE_GR] = grctx;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000211 return 0;
212}
213
Ben Skeggs2703c212011-04-01 09:50:18 +1000214static void
215nv50_graph_context_del(struct nouveau_channel *chan, int engine)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000216{
Ben Skeggs2703c212011-04-01 09:50:18 +1000217 struct nouveau_gpuobj *grctx = chan->engctx[engine];
Ben Skeggs6ee73862009-12-11 19:24:15 +1000218 struct drm_device *dev = chan->dev;
219 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsac94a342010-07-08 15:28:48 +1000220 int i, hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
Francisco Jerez3945e472010-10-18 03:53:39 +0200221
Ben Skeggs6ee73862009-12-11 19:24:15 +1000222 for (i = hdr; i < hdr + 24; i += 4)
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000223 nv_wo32(chan->ramin, i, 0);
Ben Skeggsf56cb862010-07-08 11:29:10 +1000224 dev_priv->engine.instmem.flush(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000225
Ben Skeggs2703c212011-04-01 09:50:18 +1000226 atomic_dec(&chan->vm->engref[engine]);
Ben Skeggs5511d492012-05-01 16:46:28 +1000227 nouveau_gpuobj_ref(NULL, &grctx);
Ben Skeggs2703c212011-04-01 09:50:18 +1000228 chan->engctx[engine] = NULL;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000229}
230
231static int
Ben Skeggs2703c212011-04-01 09:50:18 +1000232nv50_graph_object_new(struct nouveau_channel *chan, int engine,
233 u32 handle, u16 class)
Ben Skeggs4ea52f82011-03-31 13:44:16 +1000234{
235 struct drm_device *dev = chan->dev;
236 struct drm_nouveau_private *dev_priv = dev->dev_private;
237 struct nouveau_gpuobj *obj = NULL;
238 int ret;
239
240 ret = nouveau_gpuobj_new(dev, chan, 16, 16, NVOBJ_FLAG_ZERO_FREE, &obj);
241 if (ret)
242 return ret;
243 obj->engine = 1;
244 obj->class = class;
245
246 nv_wo32(obj, 0x00, class);
247 nv_wo32(obj, 0x04, 0x00000000);
248 nv_wo32(obj, 0x08, 0x00000000);
249 nv_wo32(obj, 0x0c, 0x00000000);
250 dev_priv->engine.instmem.flush(dev);
251
252 ret = nouveau_ramht_insert(chan, handle, obj);
253 nouveau_gpuobj_ref(NULL, &obj);
254 return ret;
255}
256
Ben Skeggs274fec92010-11-03 13:16:18 +1000257static void
Ben Skeggs6ee73862009-12-11 19:24:15 +1000258nv50_graph_context_switch(struct drm_device *dev)
259{
260 uint32_t inst;
261
262 nv50_graph_unload_context(dev);
263
264 inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_NEXT);
265 inst &= NV50_PGRAPH_CTXCTL_NEXT_INSTANCE;
266 nv50_graph_do_load_context(dev, inst);
267
268 nv_wr32(dev, NV40_PGRAPH_INTR_EN, nv_rd32(dev,
269 NV40_PGRAPH_INTR_EN) | NV_PGRAPH_INTR_CONTEXT_SWITCH);
270}
271
Ben Skeggs2703c212011-04-01 09:50:18 +1000272static void
273nv50_graph_tlb_flush(struct drm_device *dev, int engine)
Ben Skeggs56ac7472010-10-22 10:26:24 +1000274{
Ben Skeggsa11c3192010-08-27 10:00:25 +1000275 nv50_vm_flush_engine(dev, 0);
Ben Skeggs56ac7472010-10-22 10:26:24 +1000276}
277
Ben Skeggs2703c212011-04-01 09:50:18 +1000278static void
279nv84_graph_tlb_flush(struct drm_device *dev, int engine)
Ben Skeggs56ac7472010-10-22 10:26:24 +1000280{
281 struct drm_nouveau_private *dev_priv = dev->dev_private;
282 struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer;
283 bool idle, timeout = false;
284 unsigned long flags;
285 u64 start;
286 u32 tmp;
287
288 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
289 nv_mask(dev, 0x400500, 0x00000001, 0x00000000);
290
291 start = ptimer->read(dev);
292 do {
293 idle = true;
294
295 for (tmp = nv_rd32(dev, 0x400380); tmp && idle; tmp >>= 3) {
296 if ((tmp & 7) == 1)
297 idle = false;
298 }
299
300 for (tmp = nv_rd32(dev, 0x400384); tmp && idle; tmp >>= 3) {
301 if ((tmp & 7) == 1)
302 idle = false;
303 }
304
305 for (tmp = nv_rd32(dev, 0x400388); tmp && idle; tmp >>= 3) {
306 if ((tmp & 7) == 1)
307 idle = false;
308 }
309 } while (!idle && !(timeout = ptimer->read(dev) - start > 2000000000));
310
311 if (timeout) {
312 NV_ERROR(dev, "PGRAPH TLB flush idle timeout fail: "
313 "0x%08x 0x%08x 0x%08x 0x%08x\n",
314 nv_rd32(dev, 0x400700), nv_rd32(dev, 0x400380),
315 nv_rd32(dev, 0x400384), nv_rd32(dev, 0x400388));
316 }
317
Ben Skeggsa11c3192010-08-27 10:00:25 +1000318 nv50_vm_flush_engine(dev, 0);
Ben Skeggs56ac7472010-10-22 10:26:24 +1000319
320 nv_mask(dev, 0x400500, 0x00000001, 0x00000001);
321 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
322}
Ben Skeggs274fec92010-11-03 13:16:18 +1000323
Emil Velikovf9ec8f62011-03-19 23:31:53 +0000324static struct nouveau_enum nv50_mp_exec_error_names[] = {
Ben Skeggsbb9b18a2011-03-08 08:39:43 +1000325 { 3, "STACK_UNDERFLOW", NULL },
326 { 4, "QUADON_ACTIVE", NULL },
327 { 8, "TIMEOUT", NULL },
328 { 0x10, "INVALID_OPCODE", NULL },
329 { 0x40, "BREAKPOINT", NULL },
Ben Skeggs274fec92010-11-03 13:16:18 +1000330 {}
331};
332
333static struct nouveau_bitfield nv50_graph_trap_m2mf[] = {
334 { 0x00000001, "NOTIFY" },
335 { 0x00000002, "IN" },
336 { 0x00000004, "OUT" },
337 {}
338};
339
340static struct nouveau_bitfield nv50_graph_trap_vfetch[] = {
341 { 0x00000001, "FAULT" },
342 {}
343};
344
345static struct nouveau_bitfield nv50_graph_trap_strmout[] = {
346 { 0x00000001, "FAULT" },
347 {}
348};
349
350static struct nouveau_bitfield nv50_graph_trap_ccache[] = {
351 { 0x00000001, "FAULT" },
352 {}
353};
354
355/* There must be a *lot* of these. Will take some time to gather them up. */
Ben Skeggs6effe392010-12-30 11:48:03 +1000356struct nouveau_enum nv50_data_error_names[] = {
Ben Skeggsbb9b18a2011-03-08 08:39:43 +1000357 { 0x00000003, "INVALID_QUERY_OR_TEXTURE", NULL },
358 { 0x00000004, "INVALID_VALUE", NULL },
359 { 0x00000005, "INVALID_ENUM", NULL },
360 { 0x00000008, "INVALID_OBJECT", NULL },
361 { 0x00000009, "READ_ONLY_OBJECT", NULL },
362 { 0x0000000a, "SUPERVISOR_OBJECT", NULL },
363 { 0x0000000b, "INVALID_ADDRESS_ALIGNMENT", NULL },
364 { 0x0000000c, "INVALID_BITFIELD", NULL },
365 { 0x0000000d, "BEGIN_END_ACTIVE", NULL },
366 { 0x0000000e, "SEMANTIC_COLOR_BACK_OVER_LIMIT", NULL },
367 { 0x0000000f, "VIEWPORT_ID_NEEDS_GP", NULL },
368 { 0x00000010, "RT_DOUBLE_BIND", NULL },
369 { 0x00000011, "RT_TYPES_MISMATCH", NULL },
370 { 0x00000012, "RT_LINEAR_WITH_ZETA", NULL },
371 { 0x00000015, "FP_TOO_FEW_REGS", NULL },
372 { 0x00000016, "ZETA_FORMAT_CSAA_MISMATCH", NULL },
373 { 0x00000017, "RT_LINEAR_WITH_MSAA", NULL },
374 { 0x00000018, "FP_INTERPOLANT_START_OVER_LIMIT", NULL },
375 { 0x00000019, "SEMANTIC_LAYER_OVER_LIMIT", NULL },
376 { 0x0000001a, "RT_INVALID_ALIGNMENT", NULL },
377 { 0x0000001b, "SAMPLER_OVER_LIMIT", NULL },
378 { 0x0000001c, "TEXTURE_OVER_LIMIT", NULL },
379 { 0x0000001e, "GP_TOO_MANY_OUTPUTS", NULL },
380 { 0x0000001f, "RT_BPP128_WITH_MS8", NULL },
381 { 0x00000021, "Z_OUT_OF_BOUNDS", NULL },
382 { 0x00000023, "XY_OUT_OF_BOUNDS", NULL },
383 { 0x00000027, "CP_MORE_PARAMS_THAN_SHARED", NULL },
384 { 0x00000028, "CP_NO_REG_SPACE_STRIPED", NULL },
385 { 0x00000029, "CP_NO_REG_SPACE_PACKED", NULL },
386 { 0x0000002a, "CP_NOT_ENOUGH_WARPS", NULL },
387 { 0x0000002b, "CP_BLOCK_SIZE_MISMATCH", NULL },
388 { 0x0000002c, "CP_NOT_ENOUGH_LOCAL_WARPS", NULL },
389 { 0x0000002d, "CP_NOT_ENOUGH_STACK_WARPS", NULL },
390 { 0x0000002e, "CP_NO_BLOCKDIM_LATCH", NULL },
391 { 0x00000031, "ENG2D_FORMAT_MISMATCH", NULL },
392 { 0x0000003f, "PRIMITIVE_ID_NEEDS_GP", NULL },
393 { 0x00000044, "SEMANTIC_VIEWPORT_OVER_LIMIT", NULL },
394 { 0x00000045, "SEMANTIC_COLOR_FRONT_OVER_LIMIT", NULL },
395 { 0x00000046, "LAYER_ID_NEEDS_GP", NULL },
396 { 0x00000047, "SEMANTIC_CLIP_OVER_LIMIT", NULL },
397 { 0x00000048, "SEMANTIC_PTSZ_OVER_LIMIT", NULL },
Ben Skeggs274fec92010-11-03 13:16:18 +1000398 {}
399};
400
401static struct nouveau_bitfield nv50_graph_intr[] = {
402 { 0x00000001, "NOTIFY" },
403 { 0x00000002, "COMPUTE_QUERY" },
404 { 0x00000010, "ILLEGAL_MTHD" },
405 { 0x00000020, "ILLEGAL_CLASS" },
406 { 0x00000040, "DOUBLE_NOTIFY" },
407 { 0x00001000, "CONTEXT_SWITCH" },
408 { 0x00010000, "BUFFER_NOTIFY" },
409 { 0x00100000, "DATA_ERROR" },
410 { 0x00200000, "TRAP" },
411 { 0x01000000, "SINGLE_STEP" },
412 {}
413};
414
415static void
416nv50_pgraph_mp_trap(struct drm_device *dev, int tpid, int display)
417{
418 struct drm_nouveau_private *dev_priv = dev->dev_private;
419 uint32_t units = nv_rd32(dev, 0x1540);
420 uint32_t addr, mp10, status, pc, oplow, ophigh;
421 int i;
422 int mps = 0;
423 for (i = 0; i < 4; i++) {
424 if (!(units & 1 << (i+24)))
425 continue;
426 if (dev_priv->chipset < 0xa0)
427 addr = 0x408200 + (tpid << 12) + (i << 7);
428 else
429 addr = 0x408100 + (tpid << 11) + (i << 7);
430 mp10 = nv_rd32(dev, addr + 0x10);
431 status = nv_rd32(dev, addr + 0x14);
432 if (!status)
433 continue;
434 if (display) {
435 nv_rd32(dev, addr + 0x20);
436 pc = nv_rd32(dev, addr + 0x24);
437 oplow = nv_rd32(dev, addr + 0x70);
Emil Velikov0b89a072011-03-19 23:31:54 +0000438 ophigh = nv_rd32(dev, addr + 0x74);
Ben Skeggs274fec92010-11-03 13:16:18 +1000439 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - "
440 "TP %d MP %d: ", tpid, i);
441 nouveau_enum_print(nv50_mp_exec_error_names, status);
442 printk(" at %06x warp %d, opcode %08x %08x\n",
443 pc&0xffffff, pc >> 24,
444 oplow, ophigh);
445 }
446 nv_wr32(dev, addr + 0x10, mp10);
447 nv_wr32(dev, addr + 0x14, 0);
448 mps++;
449 }
450 if (!mps && display)
451 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - TP %d: "
452 "No MPs claiming errors?\n", tpid);
453}
454
455static void
456nv50_pgraph_tp_trap(struct drm_device *dev, int type, uint32_t ustatus_old,
457 uint32_t ustatus_new, int display, const char *name)
458{
459 struct drm_nouveau_private *dev_priv = dev->dev_private;
460 int tps = 0;
461 uint32_t units = nv_rd32(dev, 0x1540);
462 int i, r;
463 uint32_t ustatus_addr, ustatus;
464 for (i = 0; i < 16; i++) {
465 if (!(units & (1 << i)))
466 continue;
467 if (dev_priv->chipset < 0xa0)
468 ustatus_addr = ustatus_old + (i << 12);
469 else
470 ustatus_addr = ustatus_new + (i << 11);
471 ustatus = nv_rd32(dev, ustatus_addr) & 0x7fffffff;
472 if (!ustatus)
473 continue;
474 tps++;
475 switch (type) {
476 case 6: /* texture error... unknown for now */
Ben Skeggs274fec92010-11-03 13:16:18 +1000477 if (display) {
478 NV_ERROR(dev, "magic set %d:\n", i);
479 for (r = ustatus_addr + 4; r <= ustatus_addr + 0x10; r += 4)
480 NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r,
481 nv_rd32(dev, r));
482 }
483 break;
484 case 7: /* MP error */
Maxim Levitskyc983e6f2011-10-09 22:58:32 +0200485 if (ustatus & 0x04030000) {
Ben Skeggs274fec92010-11-03 13:16:18 +1000486 nv50_pgraph_mp_trap(dev, i, display);
Maxim Levitskyc983e6f2011-10-09 22:58:32 +0200487 ustatus &= ~0x04030000;
Ben Skeggs274fec92010-11-03 13:16:18 +1000488 }
489 break;
490 case 8: /* TPDMA error */
491 {
492 uint32_t e0c = nv_rd32(dev, ustatus_addr + 4);
493 uint32_t e10 = nv_rd32(dev, ustatus_addr + 8);
494 uint32_t e14 = nv_rd32(dev, ustatus_addr + 0xc);
495 uint32_t e18 = nv_rd32(dev, ustatus_addr + 0x10);
496 uint32_t e1c = nv_rd32(dev, ustatus_addr + 0x14);
497 uint32_t e20 = nv_rd32(dev, ustatus_addr + 0x18);
498 uint32_t e24 = nv_rd32(dev, ustatus_addr + 0x1c);
Ben Skeggs274fec92010-11-03 13:16:18 +1000499 /* 2d engine destination */
500 if (ustatus & 0x00000010) {
501 if (display) {
502 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - Unknown fault at address %02x%08x\n",
503 i, e14, e10);
504 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
505 i, e0c, e18, e1c, e20, e24);
506 }
507 ustatus &= ~0x00000010;
508 }
509 /* Render target */
510 if (ustatus & 0x00000040) {
511 if (display) {
512 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - Unknown fault at address %02x%08x\n",
513 i, e14, e10);
514 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
515 i, e0c, e18, e1c, e20, e24);
516 }
517 ustatus &= ~0x00000040;
518 }
519 /* CUDA memory: l[], g[] or stack. */
520 if (ustatus & 0x00000080) {
521 if (display) {
522 if (e18 & 0x80000000) {
523 /* g[] read fault? */
524 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global read fault at address %02x%08x\n",
525 i, e14, e10 | ((e18 >> 24) & 0x1f));
526 e18 &= ~0x1f000000;
527 } else if (e18 & 0xc) {
528 /* g[] write fault? */
529 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global write fault at address %02x%08x\n",
530 i, e14, e10 | ((e18 >> 7) & 0x1f));
531 e18 &= ~0x00000f80;
532 } else {
533 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Unknown CUDA fault at address %02x%08x\n",
534 i, e14, e10);
535 }
536 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
537 i, e0c, e18, e1c, e20, e24);
538 }
539 ustatus &= ~0x00000080;
540 }
541 }
542 break;
543 }
544 if (ustatus) {
545 if (display)
546 NV_INFO(dev, "%s - TP%d: Unhandled ustatus 0x%08x\n", name, i, ustatus);
547 }
548 nv_wr32(dev, ustatus_addr, 0xc0000000);
549 }
550
551 if (!tps && display)
552 NV_INFO(dev, "%s - No TPs claiming errors?\n", name);
553}
554
555static int
556nv50_pgraph_trap_handler(struct drm_device *dev, u32 display, u64 inst, u32 chid)
557{
558 u32 status = nv_rd32(dev, 0x400108);
559 u32 ustatus;
560
561 if (!status && display) {
562 NV_INFO(dev, "PGRAPH - TRAP: no units reporting traps?\n");
563 return 1;
564 }
565
566 /* DISPATCH: Relays commands to other units and handles NOTIFY,
567 * COND, QUERY. If you get a trap from it, the command is still stuck
568 * in DISPATCH and you need to do something about it. */
569 if (status & 0x001) {
570 ustatus = nv_rd32(dev, 0x400804) & 0x7fffffff;
571 if (!ustatus && display) {
572 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - no ustatus?\n");
573 }
574
575 nv_wr32(dev, 0x400500, 0x00000000);
576
577 /* Known to be triggered by screwed up NOTIFY and COND... */
578 if (ustatus & 0x00000001) {
579 u32 addr = nv_rd32(dev, 0x400808);
580 u32 subc = (addr & 0x00070000) >> 16;
581 u32 mthd = (addr & 0x00001ffc);
582 u32 datal = nv_rd32(dev, 0x40080c);
583 u32 datah = nv_rd32(dev, 0x400810);
584 u32 class = nv_rd32(dev, 0x400814);
585 u32 r848 = nv_rd32(dev, 0x400848);
586
587 NV_INFO(dev, "PGRAPH - TRAP DISPATCH_FAULT\n");
588 if (display && (addr & 0x80000000)) {
589 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
590 "subc %d class 0x%04x mthd 0x%04x "
591 "data 0x%08x%08x "
592 "400808 0x%08x 400848 0x%08x\n",
593 chid, inst, subc, class, mthd, datah,
594 datal, addr, r848);
595 } else
596 if (display) {
597 NV_INFO(dev, "PGRAPH - no stuck command?\n");
598 }
599
600 nv_wr32(dev, 0x400808, 0);
601 nv_wr32(dev, 0x4008e8, nv_rd32(dev, 0x4008e8) & 3);
602 nv_wr32(dev, 0x400848, 0);
603 ustatus &= ~0x00000001;
604 }
605
606 if (ustatus & 0x00000002) {
607 u32 addr = nv_rd32(dev, 0x40084c);
608 u32 subc = (addr & 0x00070000) >> 16;
609 u32 mthd = (addr & 0x00001ffc);
610 u32 data = nv_rd32(dev, 0x40085c);
611 u32 class = nv_rd32(dev, 0x400814);
612
613 NV_INFO(dev, "PGRAPH - TRAP DISPATCH_QUERY\n");
614 if (display && (addr & 0x80000000)) {
615 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
616 "subc %d class 0x%04x mthd 0x%04x "
617 "data 0x%08x 40084c 0x%08x\n",
618 chid, inst, subc, class, mthd,
619 data, addr);
620 } else
621 if (display) {
622 NV_INFO(dev, "PGRAPH - no stuck command?\n");
623 }
624
625 nv_wr32(dev, 0x40084c, 0);
626 ustatus &= ~0x00000002;
627 }
628
629 if (ustatus && display) {
630 NV_INFO(dev, "PGRAPH - TRAP_DISPATCH (unknown "
631 "0x%08x)\n", ustatus);
632 }
633
634 nv_wr32(dev, 0x400804, 0xc0000000);
635 nv_wr32(dev, 0x400108, 0x001);
636 status &= ~0x001;
637 if (!status)
638 return 0;
639 }
640
641 /* M2MF: Memory to memory copy engine. */
642 if (status & 0x002) {
643 u32 ustatus = nv_rd32(dev, 0x406800) & 0x7fffffff;
644 if (display) {
645 NV_INFO(dev, "PGRAPH - TRAP_M2MF");
646 nouveau_bitfield_print(nv50_graph_trap_m2mf, ustatus);
647 printk("\n");
648 NV_INFO(dev, "PGRAPH - TRAP_M2MF %08x %08x %08x %08x\n",
649 nv_rd32(dev, 0x406804), nv_rd32(dev, 0x406808),
650 nv_rd32(dev, 0x40680c), nv_rd32(dev, 0x406810));
651
652 }
653
654 /* No sane way found yet -- just reset the bugger. */
655 nv_wr32(dev, 0x400040, 2);
656 nv_wr32(dev, 0x400040, 0);
657 nv_wr32(dev, 0x406800, 0xc0000000);
658 nv_wr32(dev, 0x400108, 0x002);
659 status &= ~0x002;
660 }
661
662 /* VFETCH: Fetches data from vertex buffers. */
663 if (status & 0x004) {
664 u32 ustatus = nv_rd32(dev, 0x400c04) & 0x7fffffff;
665 if (display) {
666 NV_INFO(dev, "PGRAPH - TRAP_VFETCH");
667 nouveau_bitfield_print(nv50_graph_trap_vfetch, ustatus);
668 printk("\n");
669 NV_INFO(dev, "PGRAPH - TRAP_VFETCH %08x %08x %08x %08x\n",
670 nv_rd32(dev, 0x400c00), nv_rd32(dev, 0x400c08),
671 nv_rd32(dev, 0x400c0c), nv_rd32(dev, 0x400c10));
672 }
673
674 nv_wr32(dev, 0x400c04, 0xc0000000);
675 nv_wr32(dev, 0x400108, 0x004);
676 status &= ~0x004;
677 }
678
679 /* STRMOUT: DirectX streamout / OpenGL transform feedback. */
680 if (status & 0x008) {
681 ustatus = nv_rd32(dev, 0x401800) & 0x7fffffff;
682 if (display) {
683 NV_INFO(dev, "PGRAPH - TRAP_STRMOUT");
684 nouveau_bitfield_print(nv50_graph_trap_strmout, ustatus);
685 printk("\n");
686 NV_INFO(dev, "PGRAPH - TRAP_STRMOUT %08x %08x %08x %08x\n",
687 nv_rd32(dev, 0x401804), nv_rd32(dev, 0x401808),
688 nv_rd32(dev, 0x40180c), nv_rd32(dev, 0x401810));
689
690 }
691
692 /* No sane way found yet -- just reset the bugger. */
693 nv_wr32(dev, 0x400040, 0x80);
694 nv_wr32(dev, 0x400040, 0);
695 nv_wr32(dev, 0x401800, 0xc0000000);
696 nv_wr32(dev, 0x400108, 0x008);
697 status &= ~0x008;
698 }
699
700 /* CCACHE: Handles code and c[] caches and fills them. */
701 if (status & 0x010) {
702 ustatus = nv_rd32(dev, 0x405018) & 0x7fffffff;
703 if (display) {
704 NV_INFO(dev, "PGRAPH - TRAP_CCACHE");
705 nouveau_bitfield_print(nv50_graph_trap_ccache, ustatus);
706 printk("\n");
707 NV_INFO(dev, "PGRAPH - TRAP_CCACHE %08x %08x %08x %08x"
708 " %08x %08x %08x\n",
Marcin Slusarz4dcf9052011-02-13 20:46:41 +0100709 nv_rd32(dev, 0x405000), nv_rd32(dev, 0x405004),
710 nv_rd32(dev, 0x405008), nv_rd32(dev, 0x40500c),
711 nv_rd32(dev, 0x405010), nv_rd32(dev, 0x405014),
712 nv_rd32(dev, 0x40501c));
Ben Skeggs274fec92010-11-03 13:16:18 +1000713
714 }
715
716 nv_wr32(dev, 0x405018, 0xc0000000);
717 nv_wr32(dev, 0x400108, 0x010);
718 status &= ~0x010;
719 }
720
721 /* Unknown, not seen yet... 0x402000 is the only trap status reg
722 * remaining, so try to handle it anyway. Perhaps related to that
723 * unknown DMA slot on tesla? */
724 if (status & 0x20) {
725 ustatus = nv_rd32(dev, 0x402000) & 0x7fffffff;
726 if (display)
727 NV_INFO(dev, "PGRAPH - TRAP_UNKC04 0x%08x\n", ustatus);
728 nv_wr32(dev, 0x402000, 0xc0000000);
729 /* no status modifiction on purpose */
730 }
731
732 /* TEXTURE: CUDA texturing units */
733 if (status & 0x040) {
734 nv50_pgraph_tp_trap(dev, 6, 0x408900, 0x408600, display,
735 "PGRAPH - TRAP_TEXTURE");
736 nv_wr32(dev, 0x400108, 0x040);
737 status &= ~0x040;
738 }
739
740 /* MP: CUDA execution engines. */
741 if (status & 0x080) {
742 nv50_pgraph_tp_trap(dev, 7, 0x408314, 0x40831c, display,
743 "PGRAPH - TRAP_MP");
744 nv_wr32(dev, 0x400108, 0x080);
745 status &= ~0x080;
746 }
747
748 /* TPDMA: Handles TP-initiated uncached memory accesses:
749 * l[], g[], stack, 2d surfaces, render targets. */
750 if (status & 0x100) {
751 nv50_pgraph_tp_trap(dev, 8, 0x408e08, 0x408708, display,
752 "PGRAPH - TRAP_TPDMA");
753 nv_wr32(dev, 0x400108, 0x100);
754 status &= ~0x100;
755 }
756
757 if (status) {
758 if (display)
759 NV_INFO(dev, "PGRAPH - TRAP: unknown 0x%08x\n", status);
760 nv_wr32(dev, 0x400108, status);
761 }
762
763 return 1;
764}
765
Ben Skeggs7ff54412011-03-18 10:25:59 +1000766int
Ben Skeggs274fec92010-11-03 13:16:18 +1000767nv50_graph_isr_chid(struct drm_device *dev, u64 inst)
768{
769 struct drm_nouveau_private *dev_priv = dev->dev_private;
770 struct nouveau_channel *chan;
771 unsigned long flags;
772 int i;
773
774 spin_lock_irqsave(&dev_priv->channels.lock, flags);
775 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
776 chan = dev_priv->channels.ptr[i];
777 if (!chan || !chan->ramin)
778 continue;
779
780 if (inst == chan->ramin->vinst)
781 break;
782 }
783 spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
784 return i;
785}
786
787static void
788nv50_graph_isr(struct drm_device *dev)
789{
790 u32 stat;
791
792 while ((stat = nv_rd32(dev, 0x400100))) {
793 u64 inst = (u64)(nv_rd32(dev, 0x40032c) & 0x0fffffff) << 12;
794 u32 chid = nv50_graph_isr_chid(dev, inst);
795 u32 addr = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR);
796 u32 subc = (addr & 0x00070000) >> 16;
797 u32 mthd = (addr & 0x00001ffc);
798 u32 data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA);
799 u32 class = nv_rd32(dev, 0x400814);
800 u32 show = stat;
801
802 if (stat & 0x00000010) {
803 if (!nouveau_gpuobj_mthd_call2(dev, chid, class,
804 mthd, data))
805 show &= ~0x00000010;
806 }
807
808 if (stat & 0x00001000) {
809 nv_wr32(dev, 0x400500, 0x00000000);
810 nv_wr32(dev, 0x400100, 0x00001000);
811 nv_mask(dev, 0x40013c, 0x00001000, 0x00000000);
812 nv50_graph_context_switch(dev);
813 stat &= ~0x00001000;
814 show &= ~0x00001000;
815 }
816
817 show = (show && nouveau_ratelimit()) ? show : 0;
818
819 if (show & 0x00100000) {
820 u32 ecode = nv_rd32(dev, 0x400110);
821 NV_INFO(dev, "PGRAPH - DATA_ERROR ");
822 nouveau_enum_print(nv50_data_error_names, ecode);
823 printk("\n");
824 }
825
826 if (stat & 0x00200000) {
827 if (!nv50_pgraph_trap_handler(dev, show, inst, chid))
828 show &= ~0x00200000;
829 }
830
831 nv_wr32(dev, 0x400100, stat);
832 nv_wr32(dev, 0x400500, 0x00010001);
833
834 if (show) {
835 NV_INFO(dev, "PGRAPH -");
836 nouveau_bitfield_print(nv50_graph_intr, show);
837 printk("\n");
838 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) subc %d "
839 "class 0x%04x mthd 0x%04x data 0x%08x\n",
840 chid, inst, subc, class, mthd, data);
Ben Skeggs6fdb3832011-03-08 09:57:17 +1000841 nv50_fb_vm_trap(dev, 1);
Ben Skeggs274fec92010-11-03 13:16:18 +1000842 }
843 }
844
845 if (nv_rd32(dev, 0x400824) & (1 << 31))
846 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) & ~(1 << 31));
847}
Ben Skeggs2703c212011-04-01 09:50:18 +1000848
849static void
850nv50_graph_destroy(struct drm_device *dev, int engine)
851{
852 struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
853
854 NVOBJ_ENGINE_DEL(dev, GR);
855
856 nouveau_irq_unregister(dev, 12);
857 kfree(pgraph);
858}
859
860int
861nv50_graph_create(struct drm_device *dev)
862{
863 struct drm_nouveau_private *dev_priv = dev->dev_private;
864 struct nv50_graph_engine *pgraph;
Ben Skeggs2703c212011-04-01 09:50:18 +1000865 int ret;
866
867 pgraph = kzalloc(sizeof(*pgraph),GFP_KERNEL);
868 if (!pgraph)
869 return -ENOMEM;
870
Ben Skeggsd58086d2012-04-20 11:54:33 +1000871 ret = nv50_grctx_init(dev, pgraph->ctxprog, ARRAY_SIZE(pgraph->ctxprog),
872 &pgraph->ctxprog_size,
873 &pgraph->grctx_size);
Ben Skeggs2703c212011-04-01 09:50:18 +1000874 if (ret) {
875 NV_ERROR(dev, "PGRAPH: ctxprog build failed\n");
Ben Skeggs2703c212011-04-01 09:50:18 +1000876 kfree(pgraph);
877 return 0;
878 }
879
Ben Skeggs2703c212011-04-01 09:50:18 +1000880 pgraph->base.destroy = nv50_graph_destroy;
881 pgraph->base.init = nv50_graph_init;
882 pgraph->base.fini = nv50_graph_fini;
883 pgraph->base.context_new = nv50_graph_context_new;
884 pgraph->base.context_del = nv50_graph_context_del;
885 pgraph->base.object_new = nv50_graph_object_new;
886 if (dev_priv->chipset == 0x50 || dev_priv->chipset == 0xac)
887 pgraph->base.tlb_flush = nv50_graph_tlb_flush;
888 else
889 pgraph->base.tlb_flush = nv84_graph_tlb_flush;
890
891 nouveau_irq_register(dev, 12, nv50_graph_isr);
892
Ben Skeggs2703c212011-04-01 09:50:18 +1000893 NVOBJ_ENGINE_ADD(dev, GR, &pgraph->base);
894 NVOBJ_CLASS(dev, 0x0030, GR); /* null */
895 NVOBJ_CLASS(dev, 0x5039, GR); /* m2mf */
896 NVOBJ_CLASS(dev, 0x502d, GR); /* 2d */
897
898 /* tesla */
899 if (dev_priv->chipset == 0x50)
900 NVOBJ_CLASS(dev, 0x5097, GR); /* tesla (nv50) */
901 else
902 if (dev_priv->chipset < 0xa0)
903 NVOBJ_CLASS(dev, 0x8297, GR); /* tesla (nv8x/nv9x) */
904 else {
905 switch (dev_priv->chipset) {
906 case 0xa0:
907 case 0xaa:
908 case 0xac:
909 NVOBJ_CLASS(dev, 0x8397, GR);
910 break;
911 case 0xa3:
912 case 0xa5:
913 case 0xa8:
914 NVOBJ_CLASS(dev, 0x8597, GR);
915 break;
916 case 0xaf:
917 NVOBJ_CLASS(dev, 0x8697, GR);
918 break;
919 }
920 }
921
922 /* compute */
923 NVOBJ_CLASS(dev, 0x50c0, GR);
924 if (dev_priv->chipset > 0xa0 &&
925 dev_priv->chipset != 0xaa &&
926 dev_priv->chipset != 0xac)
927 NVOBJ_CLASS(dev, 0x85c0, GR);
928
929 return 0;
930}