blob: 289c0dd6c53db10d8a27a4bacdf28d47d85b8a38 [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"
Marcin Kościelnickid5f3c902010-02-25 00:54:02 +000031#include "nouveau_grctx.h"
Francisco Jerez332b2422010-10-20 23:35:40 +020032#include "nouveau_dma.h"
Ben Skeggsa11c3192010-08-27 10:00:25 +100033#include "nouveau_vm.h"
Francisco Jerez332b2422010-10-20 23:35:40 +020034#include "nv50_evo.h"
Ben Skeggs6ee73862009-12-11 19:24:15 +100035
Ben Skeggs274fec92010-11-03 13:16:18 +100036static int nv50_graph_register(struct drm_device *);
37static void nv50_graph_isr(struct drm_device *);
Ben Skeggsb8c157d2010-10-20 10:39:35 +100038
Ben Skeggs6ee73862009-12-11 19:24:15 +100039static void
40nv50_graph_init_reset(struct drm_device *dev)
41{
42 uint32_t pmc_e = NV_PMC_ENABLE_PGRAPH | (1 << 21);
43
44 NV_DEBUG(dev, "\n");
45
46 nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) & ~pmc_e);
47 nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) | pmc_e);
48}
49
50static void
51nv50_graph_init_intr(struct drm_device *dev)
52{
53 NV_DEBUG(dev, "\n");
54
Ben Skeggs274fec92010-11-03 13:16:18 +100055 nouveau_irq_register(dev, 12, nv50_graph_isr);
Ben Skeggs6ee73862009-12-11 19:24:15 +100056 nv_wr32(dev, NV03_PGRAPH_INTR, 0xffffffff);
57 nv_wr32(dev, 0x400138, 0xffffffff);
58 nv_wr32(dev, NV40_PGRAPH_INTR_EN, 0xffffffff);
59}
60
61static void
62nv50_graph_init_regs__nv(struct drm_device *dev)
63{
Marcin Kościelnicki304424e2010-03-01 00:18:39 +000064 struct drm_nouveau_private *dev_priv = dev->dev_private;
65 uint32_t units = nv_rd32(dev, 0x1540);
66 int i;
67
Ben Skeggs6ee73862009-12-11 19:24:15 +100068 NV_DEBUG(dev, "\n");
69
70 nv_wr32(dev, 0x400804, 0xc0000000);
71 nv_wr32(dev, 0x406800, 0xc0000000);
72 nv_wr32(dev, 0x400c04, 0xc0000000);
Marcin Kościelnicki716abaa2010-01-12 18:21:56 +000073 nv_wr32(dev, 0x401800, 0xc0000000);
Ben Skeggs6ee73862009-12-11 19:24:15 +100074 nv_wr32(dev, 0x405018, 0xc0000000);
75 nv_wr32(dev, 0x402000, 0xc0000000);
76
Marcin Kościelnicki304424e2010-03-01 00:18:39 +000077 for (i = 0; i < 16; i++) {
78 if (units & 1 << i) {
79 if (dev_priv->chipset < 0xa0) {
80 nv_wr32(dev, 0x408900 + (i << 12), 0xc0000000);
81 nv_wr32(dev, 0x408e08 + (i << 12), 0xc0000000);
82 nv_wr32(dev, 0x408314 + (i << 12), 0xc0000000);
83 } else {
84 nv_wr32(dev, 0x408600 + (i << 11), 0xc0000000);
85 nv_wr32(dev, 0x408708 + (i << 11), 0xc0000000);
86 nv_wr32(dev, 0x40831c + (i << 11), 0xc0000000);
87 }
88 }
89 }
90
Ben Skeggs6ee73862009-12-11 19:24:15 +100091 nv_wr32(dev, 0x400108, 0xffffffff);
92
93 nv_wr32(dev, 0x400824, 0x00004000);
94 nv_wr32(dev, 0x400500, 0x00010001);
95}
96
97static void
98nv50_graph_init_regs(struct drm_device *dev)
99{
100 NV_DEBUG(dev, "\n");
101
102 nv_wr32(dev, NV04_PGRAPH_DEBUG_3,
103 (1 << 2) /* HW_CONTEXT_SWITCH_ENABLED */);
104 nv_wr32(dev, 0x402ca8, 0x800);
105}
106
107static int
108nv50_graph_init_ctxctl(struct drm_device *dev)
109{
Ben Skeggs054b93e2009-12-15 22:02:47 +1000110 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsec91db22010-07-08 11:53:19 +1000111 struct nouveau_grctx ctx = {};
112 uint32_t *cp;
113 int i;
Ben Skeggs054b93e2009-12-15 22:02:47 +1000114
Ben Skeggs6ee73862009-12-11 19:24:15 +1000115 NV_DEBUG(dev, "\n");
116
Ben Skeggsec91db22010-07-08 11:53:19 +1000117 cp = kmalloc(512 * 4, GFP_KERNEL);
118 if (!cp) {
119 NV_ERROR(dev, "failed to allocate ctxprog\n");
120 dev_priv->engine.graph.accel_blocked = true;
121 return 0;
Marcin Kościelnickid5f3c902010-02-25 00:54:02 +0000122 }
Marcin Kościelnickid5f3c902010-02-25 00:54:02 +0000123
Ben Skeggsec91db22010-07-08 11:53:19 +1000124 ctx.dev = dev;
125 ctx.mode = NOUVEAU_GRCTX_PROG;
126 ctx.data = cp;
127 ctx.ctxprog_max = 512;
128 if (!nv50_grctx_init(&ctx)) {
129 dev_priv->engine.graph.grctx_size = ctx.ctxvals_pos * 4;
130
131 nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0);
132 for (i = 0; i < ctx.ctxprog_len; i++)
133 nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_DATA, cp[i]);
134 } else {
135 dev_priv->engine.graph.accel_blocked = true;
Marcin Kościelnickid5f3c902010-02-25 00:54:02 +0000136 }
Ben Skeggsec91db22010-07-08 11:53:19 +1000137 kfree(cp);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000138
139 nv_wr32(dev, 0x400320, 4);
140 nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, 0);
141 nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, 0);
142 return 0;
143}
144
145int
146nv50_graph_init(struct drm_device *dev)
147{
148 int ret;
149
150 NV_DEBUG(dev, "\n");
151
152 nv50_graph_init_reset(dev);
153 nv50_graph_init_regs__nv(dev);
154 nv50_graph_init_regs(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000155
156 ret = nv50_graph_init_ctxctl(dev);
157 if (ret)
158 return ret;
159
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000160 ret = nv50_graph_register(dev);
161 if (ret)
162 return ret;
163 nv50_graph_init_intr(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000164 return 0;
165}
166
167void
168nv50_graph_takedown(struct drm_device *dev)
169{
170 NV_DEBUG(dev, "\n");
Ben Skeggs274fec92010-11-03 13:16:18 +1000171 nv_wr32(dev, 0x40013c, 0x00000000);
172 nouveau_irq_unregister(dev, 12);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000173}
174
175void
176nv50_graph_fifo_access(struct drm_device *dev, bool enabled)
177{
178 const uint32_t mask = 0x00010001;
179
180 if (enabled)
181 nv_wr32(dev, 0x400500, nv_rd32(dev, 0x400500) | mask);
182 else
183 nv_wr32(dev, 0x400500, nv_rd32(dev, 0x400500) & ~mask);
184}
185
186struct nouveau_channel *
187nv50_graph_channel(struct drm_device *dev)
188{
189 struct drm_nouveau_private *dev_priv = dev->dev_private;
190 uint32_t inst;
191 int i;
192
Maarten Maathuisa51a3bf2010-02-01 18:32:09 +0100193 /* Be sure we're not in the middle of a context switch or bad things
194 * will happen, such as unloading the wrong pgraph context.
195 */
Francisco Jerez4b5c1522010-09-07 17:34:44 +0200196 if (!nv_wait(dev, 0x400300, 0x00000001, 0x00000000))
Maarten Maathuisa51a3bf2010-02-01 18:32:09 +0100197 NV_ERROR(dev, "Ctxprog is still running\n");
198
Ben Skeggs6ee73862009-12-11 19:24:15 +1000199 inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_CUR);
200 if (!(inst & NV50_PGRAPH_CTXCTL_CUR_LOADED))
201 return NULL;
202 inst = (inst & NV50_PGRAPH_CTXCTL_CUR_INSTANCE) << 12;
203
204 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
Ben Skeggscff5c132010-10-06 16:16:59 +1000205 struct nouveau_channel *chan = dev_priv->channels.ptr[i];
Ben Skeggs6ee73862009-12-11 19:24:15 +1000206
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000207 if (chan && chan->ramin && chan->ramin->vinst == inst)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000208 return chan;
209 }
210
211 return NULL;
212}
213
214int
215nv50_graph_create_context(struct nouveau_channel *chan)
216{
217 struct drm_device *dev = chan->dev;
218 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000219 struct nouveau_gpuobj *ramin = chan->ramin;
Marcin Kościelnickid5f3c902010-02-25 00:54:02 +0000220 struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
Ben Skeggsec91db22010-07-08 11:53:19 +1000221 struct nouveau_grctx ctx = {};
Ben Skeggs6ee73862009-12-11 19:24:15 +1000222 int hdr, ret;
223
224 NV_DEBUG(dev, "ch%d\n", chan->id);
225
Ben Skeggs3052be22010-10-20 11:46:38 +1000226 ret = nouveau_gpuobj_new(dev, chan, pgraph->grctx_size, 0,
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000227 NVOBJ_FLAG_ZERO_ALLOC |
228 NVOBJ_FLAG_ZERO_FREE, &chan->ramin_grctx);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000229 if (ret)
230 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000231
Ben Skeggsac94a342010-07-08 15:28:48 +1000232 hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
Ben Skeggsb3beb162010-09-01 15:24:29 +1000233 nv_wo32(ramin, hdr + 0x00, 0x00190002);
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000234 nv_wo32(ramin, hdr + 0x04, chan->ramin_grctx->vinst +
Ben Skeggsb3beb162010-09-01 15:24:29 +1000235 pgraph->grctx_size - 1);
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000236 nv_wo32(ramin, hdr + 0x08, chan->ramin_grctx->vinst);
Ben Skeggsb3beb162010-09-01 15:24:29 +1000237 nv_wo32(ramin, hdr + 0x0c, 0);
238 nv_wo32(ramin, hdr + 0x10, 0);
239 nv_wo32(ramin, hdr + 0x14, 0x00010000);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000240
Ben Skeggsec91db22010-07-08 11:53:19 +1000241 ctx.dev = chan->dev;
242 ctx.mode = NOUVEAU_GRCTX_VALS;
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000243 ctx.data = chan->ramin_grctx;
Ben Skeggsec91db22010-07-08 11:53:19 +1000244 nv50_grctx_init(&ctx);
245
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000246 nv_wo32(chan->ramin_grctx, 0x00000, chan->ramin->vinst >> 12);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000247
Ben Skeggsf56cb862010-07-08 11:29:10 +1000248 dev_priv->engine.instmem.flush(dev);
Ben Skeggs4c1361422010-11-15 11:54:21 +1000249 atomic_inc(&chan->vm->pgraph_refs);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000250 return 0;
251}
252
253void
254nv50_graph_destroy_context(struct nouveau_channel *chan)
255{
256 struct drm_device *dev = chan->dev;
257 struct drm_nouveau_private *dev_priv = dev->dev_private;
Francisco Jerez3945e472010-10-18 03:53:39 +0200258 struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
Francisco Jerez34311c72011-01-24 01:47:42 +0100259 struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
Ben Skeggsac94a342010-07-08 15:28:48 +1000260 int i, hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
Francisco Jerez3945e472010-10-18 03:53:39 +0200261 unsigned long flags;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000262
263 NV_DEBUG(dev, "ch%d\n", chan->id);
264
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000265 if (!chan->ramin)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000266 return;
267
Francisco Jerez3945e472010-10-18 03:53:39 +0200268 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
Francisco Jerez34311c72011-01-24 01:47:42 +0100269 pfifo->reassign(dev, false);
Francisco Jerez3945e472010-10-18 03:53:39 +0200270 pgraph->fifo_access(dev, false);
271
272 if (pgraph->channel(dev) == chan)
273 pgraph->unload_context(dev);
274
Ben Skeggs6ee73862009-12-11 19:24:15 +1000275 for (i = hdr; i < hdr + 24; i += 4)
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000276 nv_wo32(chan->ramin, i, 0);
Ben Skeggsf56cb862010-07-08 11:29:10 +1000277 dev_priv->engine.instmem.flush(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000278
Francisco Jerez3945e472010-10-18 03:53:39 +0200279 pgraph->fifo_access(dev, true);
Francisco Jerez34311c72011-01-24 01:47:42 +0100280 pfifo->reassign(dev, true);
Francisco Jerez3945e472010-10-18 03:53:39 +0200281 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
282
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000283 nouveau_gpuobj_ref(NULL, &chan->ramin_grctx);
Ben Skeggs4c1361422010-11-15 11:54:21 +1000284
285 atomic_dec(&chan->vm->pgraph_refs);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000286}
287
288static int
289nv50_graph_do_load_context(struct drm_device *dev, uint32_t inst)
290{
291 uint32_t fifo = nv_rd32(dev, 0x400500);
292
293 nv_wr32(dev, 0x400500, fifo & ~1);
294 nv_wr32(dev, 0x400784, inst);
295 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) | 0x40);
296 nv_wr32(dev, 0x400320, nv_rd32(dev, 0x400320) | 0x11);
297 nv_wr32(dev, 0x400040, 0xffffffff);
298 (void)nv_rd32(dev, 0x400040);
299 nv_wr32(dev, 0x400040, 0x00000000);
300 nv_wr32(dev, 0x400304, nv_rd32(dev, 0x400304) | 1);
301
302 if (nouveau_wait_for_idle(dev))
303 nv_wr32(dev, 0x40032c, inst | (1<<31));
304 nv_wr32(dev, 0x400500, fifo);
305
306 return 0;
307}
308
309int
310nv50_graph_load_context(struct nouveau_channel *chan)
311{
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000312 uint32_t inst = chan->ramin->vinst >> 12;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000313
314 NV_DEBUG(chan->dev, "ch%d\n", chan->id);
315 return nv50_graph_do_load_context(chan->dev, inst);
316}
317
318int
319nv50_graph_unload_context(struct drm_device *dev)
320{
Maarten Maathuisa51a3bf2010-02-01 18:32:09 +0100321 uint32_t inst;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000322
323 inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_CUR);
324 if (!(inst & NV50_PGRAPH_CTXCTL_CUR_LOADED))
325 return 0;
326 inst &= NV50_PGRAPH_CTXCTL_CUR_INSTANCE;
327
Maarten Maathuis0a90dc512010-01-11 21:18:53 +0100328 nouveau_wait_for_idle(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000329 nv_wr32(dev, 0x400784, inst);
330 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) | 0x20);
331 nv_wr32(dev, 0x400304, nv_rd32(dev, 0x400304) | 0x01);
332 nouveau_wait_for_idle(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000333
334 nv_wr32(dev, NV50_PGRAPH_CTXCTL_CUR, inst);
335 return 0;
336}
337
Ben Skeggs274fec92010-11-03 13:16:18 +1000338static void
Ben Skeggs6ee73862009-12-11 19:24:15 +1000339nv50_graph_context_switch(struct drm_device *dev)
340{
341 uint32_t inst;
342
343 nv50_graph_unload_context(dev);
344
345 inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_NEXT);
346 inst &= NV50_PGRAPH_CTXCTL_NEXT_INSTANCE;
347 nv50_graph_do_load_context(dev, inst);
348
349 nv_wr32(dev, NV40_PGRAPH_INTR_EN, nv_rd32(dev,
350 NV40_PGRAPH_INTR_EN) | NV_PGRAPH_INTR_CONTEXT_SWITCH);
351}
352
353static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000354nv50_graph_nvsw_dma_vblsem(struct nouveau_channel *chan,
355 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000356{
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000357 struct nouveau_gpuobj *gpuobj;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000358
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000359 gpuobj = nouveau_ramht_find(chan, data);
360 if (!gpuobj)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000361 return -ENOENT;
362
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000363 if (nouveau_notifier_offset(gpuobj, NULL))
Ben Skeggs6ee73862009-12-11 19:24:15 +1000364 return -EINVAL;
365
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000366 chan->nvsw.vblsem = gpuobj;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000367 chan->nvsw.vblsem_offset = ~0;
368 return 0;
369}
370
371static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000372nv50_graph_nvsw_vblsem_offset(struct nouveau_channel *chan,
373 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000374{
375 if (nouveau_notifier_offset(chan->nvsw.vblsem, &data))
376 return -ERANGE;
377
378 chan->nvsw.vblsem_offset = data >> 2;
379 return 0;
380}
381
382static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000383nv50_graph_nvsw_vblsem_release_val(struct nouveau_channel *chan,
384 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000385{
386 chan->nvsw.vblsem_rval = data;
387 return 0;
388}
389
390static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000391nv50_graph_nvsw_vblsem_release(struct nouveau_channel *chan,
392 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000393{
394 struct drm_device *dev = chan->dev;
395 struct drm_nouveau_private *dev_priv = dev->dev_private;
396
397 if (!chan->nvsw.vblsem || chan->nvsw.vblsem_offset == ~0 || data > 1)
398 return -EINVAL;
399
Francisco Jerez042206c2010-10-21 18:19:29 +0200400 drm_vblank_get(dev, data);
Francisco Jerez1f6d2de2010-10-24 14:15:58 +0200401
402 chan->nvsw.vblsem_head = data;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000403 list_add(&chan->nvsw.vbl_wait, &dev_priv->vbl_waiting);
Francisco Jerez1f6d2de2010-10-24 14:15:58 +0200404
Ben Skeggs6ee73862009-12-11 19:24:15 +1000405 return 0;
406}
407
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000408static int
Francisco Jerez332b2422010-10-20 23:35:40 +0200409nv50_graph_nvsw_mthd_page_flip(struct nouveau_channel *chan,
410 u32 class, u32 mthd, u32 data)
411{
Ben Skeggsd7117e02011-02-07 14:27:04 +1000412 nouveau_finish_page_flip(chan, NULL);
Francisco Jerez332b2422010-10-20 23:35:40 +0200413 return 0;
414}
415
416static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000417nv50_graph_register(struct drm_device *dev)
418{
419 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000420
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000421 if (dev_priv->engine.graph.registered)
422 return 0;
423
424 NVOBJ_CLASS(dev, 0x506e, SW); /* nvsw */
425 NVOBJ_MTHD (dev, 0x506e, 0x018c, nv50_graph_nvsw_dma_vblsem);
426 NVOBJ_MTHD (dev, 0x506e, 0x0400, nv50_graph_nvsw_vblsem_offset);
427 NVOBJ_MTHD (dev, 0x506e, 0x0404, nv50_graph_nvsw_vblsem_release_val);
428 NVOBJ_MTHD (dev, 0x506e, 0x0408, nv50_graph_nvsw_vblsem_release);
Francisco Jerez332b2422010-10-20 23:35:40 +0200429 NVOBJ_MTHD (dev, 0x506e, 0x0500, nv50_graph_nvsw_mthd_page_flip);
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000430
431 NVOBJ_CLASS(dev, 0x0030, GR); /* null */
432 NVOBJ_CLASS(dev, 0x5039, GR); /* m2mf */
433 NVOBJ_CLASS(dev, 0x502d, GR); /* 2d */
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000434
435 /* tesla */
436 if (dev_priv->chipset == 0x50)
437 NVOBJ_CLASS(dev, 0x5097, GR); /* tesla (nv50) */
438 else
439 if (dev_priv->chipset < 0xa0)
440 NVOBJ_CLASS(dev, 0x8297, GR); /* tesla (nv8x/nv9x) */
441 else {
442 switch (dev_priv->chipset) {
443 case 0xa0:
444 case 0xaa:
445 case 0xac:
446 NVOBJ_CLASS(dev, 0x8397, GR);
447 break;
448 case 0xa3:
449 case 0xa5:
450 case 0xa8:
451 NVOBJ_CLASS(dev, 0x8597, GR);
452 break;
453 case 0xaf:
454 NVOBJ_CLASS(dev, 0x8697, GR);
455 break;
456 }
457 }
458
Ben Skeggsaa2c2e82010-11-04 13:40:15 +1000459 /* compute */
Ben Skeggsa169f092010-11-05 09:40:00 +1000460 NVOBJ_CLASS(dev, 0x50c0, GR);
461 if (dev_priv->chipset > 0xa0 &&
462 dev_priv->chipset != 0xaa &&
463 dev_priv->chipset != 0xac)
Ben Skeggsaa2c2e82010-11-04 13:40:15 +1000464 NVOBJ_CLASS(dev, 0x85c0, GR);
465
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000466 dev_priv->engine.graph.registered = true;
467 return 0;
468}
Ben Skeggs56ac7472010-10-22 10:26:24 +1000469
470void
471nv50_graph_tlb_flush(struct drm_device *dev)
472{
Ben Skeggsa11c3192010-08-27 10:00:25 +1000473 nv50_vm_flush_engine(dev, 0);
Ben Skeggs56ac7472010-10-22 10:26:24 +1000474}
475
476void
477nv86_graph_tlb_flush(struct drm_device *dev)
478{
479 struct drm_nouveau_private *dev_priv = dev->dev_private;
480 struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer;
481 bool idle, timeout = false;
482 unsigned long flags;
483 u64 start;
484 u32 tmp;
485
486 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
487 nv_mask(dev, 0x400500, 0x00000001, 0x00000000);
488
489 start = ptimer->read(dev);
490 do {
491 idle = true;
492
493 for (tmp = nv_rd32(dev, 0x400380); tmp && idle; tmp >>= 3) {
494 if ((tmp & 7) == 1)
495 idle = false;
496 }
497
498 for (tmp = nv_rd32(dev, 0x400384); tmp && idle; tmp >>= 3) {
499 if ((tmp & 7) == 1)
500 idle = false;
501 }
502
503 for (tmp = nv_rd32(dev, 0x400388); tmp && idle; tmp >>= 3) {
504 if ((tmp & 7) == 1)
505 idle = false;
506 }
507 } while (!idle && !(timeout = ptimer->read(dev) - start > 2000000000));
508
509 if (timeout) {
510 NV_ERROR(dev, "PGRAPH TLB flush idle timeout fail: "
511 "0x%08x 0x%08x 0x%08x 0x%08x\n",
512 nv_rd32(dev, 0x400700), nv_rd32(dev, 0x400380),
513 nv_rd32(dev, 0x400384), nv_rd32(dev, 0x400388));
514 }
515
Ben Skeggsa11c3192010-08-27 10:00:25 +1000516 nv50_vm_flush_engine(dev, 0);
Ben Skeggs56ac7472010-10-22 10:26:24 +1000517
518 nv_mask(dev, 0x400500, 0x00000001, 0x00000001);
519 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
520}
Ben Skeggs274fec92010-11-03 13:16:18 +1000521
522static struct nouveau_enum nv50_mp_exec_error_names[] =
523{
524 { 3, "STACK_UNDERFLOW" },
525 { 4, "QUADON_ACTIVE" },
526 { 8, "TIMEOUT" },
527 { 0x10, "INVALID_OPCODE" },
528 { 0x40, "BREAKPOINT" },
529 {}
530};
531
532static struct nouveau_bitfield nv50_graph_trap_m2mf[] = {
533 { 0x00000001, "NOTIFY" },
534 { 0x00000002, "IN" },
535 { 0x00000004, "OUT" },
536 {}
537};
538
539static struct nouveau_bitfield nv50_graph_trap_vfetch[] = {
540 { 0x00000001, "FAULT" },
541 {}
542};
543
544static struct nouveau_bitfield nv50_graph_trap_strmout[] = {
545 { 0x00000001, "FAULT" },
546 {}
547};
548
549static struct nouveau_bitfield nv50_graph_trap_ccache[] = {
550 { 0x00000001, "FAULT" },
551 {}
552};
553
554/* There must be a *lot* of these. Will take some time to gather them up. */
Ben Skeggs6effe392010-12-30 11:48:03 +1000555struct nouveau_enum nv50_data_error_names[] = {
556 { 0x00000003, "INVALID_QUERY_OR_TEXTURE" },
557 { 0x00000004, "INVALID_VALUE" },
558 { 0x00000005, "INVALID_ENUM" },
559 { 0x00000008, "INVALID_OBJECT" },
560 { 0x00000009, "READ_ONLY_OBJECT" },
561 { 0x0000000a, "SUPERVISOR_OBJECT" },
562 { 0x0000000b, "INVALID_ADDRESS_ALIGNMENT" },
563 { 0x0000000c, "INVALID_BITFIELD" },
564 { 0x0000000d, "BEGIN_END_ACTIVE" },
565 { 0x0000000e, "SEMANTIC_COLOR_BACK_OVER_LIMIT" },
566 { 0x0000000f, "VIEWPORT_ID_NEEDS_GP" },
567 { 0x00000010, "RT_DOUBLE_BIND" },
568 { 0x00000011, "RT_TYPES_MISMATCH" },
569 { 0x00000012, "RT_LINEAR_WITH_ZETA" },
570 { 0x00000015, "FP_TOO_FEW_REGS" },
571 { 0x00000016, "ZETA_FORMAT_CSAA_MISMATCH" },
572 { 0x00000017, "RT_LINEAR_WITH_MSAA" },
573 { 0x00000018, "FP_INTERPOLANT_START_OVER_LIMIT" },
574 { 0x00000019, "SEMANTIC_LAYER_OVER_LIMIT" },
575 { 0x0000001a, "RT_INVALID_ALIGNMENT" },
576 { 0x0000001b, "SAMPLER_OVER_LIMIT" },
577 { 0x0000001c, "TEXTURE_OVER_LIMIT" },
578 { 0x0000001e, "GP_TOO_MANY_OUTPUTS" },
579 { 0x0000001f, "RT_BPP128_WITH_MS8" },
580 { 0x00000021, "Z_OUT_OF_BOUNDS" },
581 { 0x00000023, "XY_OUT_OF_BOUNDS" },
582 { 0x00000027, "CP_MORE_PARAMS_THAN_SHARED" },
583 { 0x00000028, "CP_NO_REG_SPACE_STRIPED" },
584 { 0x00000029, "CP_NO_REG_SPACE_PACKED" },
585 { 0x0000002a, "CP_NOT_ENOUGH_WARPS" },
586 { 0x0000002b, "CP_BLOCK_SIZE_MISMATCH" },
587 { 0x0000002c, "CP_NOT_ENOUGH_LOCAL_WARPS" },
588 { 0x0000002d, "CP_NOT_ENOUGH_STACK_WARPS" },
589 { 0x0000002e, "CP_NO_BLOCKDIM_LATCH" },
590 { 0x00000031, "ENG2D_FORMAT_MISMATCH" },
591 { 0x0000003f, "PRIMITIVE_ID_NEEDS_GP" },
592 { 0x00000044, "SEMANTIC_VIEWPORT_OVER_LIMIT" },
593 { 0x00000045, "SEMANTIC_COLOR_FRONT_OVER_LIMIT" },
594 { 0x00000046, "LAYER_ID_NEEDS_GP" },
595 { 0x00000047, "SEMANTIC_CLIP_OVER_LIMIT" },
596 { 0x00000048, "SEMANTIC_PTSZ_OVER_LIMIT" },
Ben Skeggs274fec92010-11-03 13:16:18 +1000597 {}
598};
599
600static struct nouveau_bitfield nv50_graph_intr[] = {
601 { 0x00000001, "NOTIFY" },
602 { 0x00000002, "COMPUTE_QUERY" },
603 { 0x00000010, "ILLEGAL_MTHD" },
604 { 0x00000020, "ILLEGAL_CLASS" },
605 { 0x00000040, "DOUBLE_NOTIFY" },
606 { 0x00001000, "CONTEXT_SWITCH" },
607 { 0x00010000, "BUFFER_NOTIFY" },
608 { 0x00100000, "DATA_ERROR" },
609 { 0x00200000, "TRAP" },
610 { 0x01000000, "SINGLE_STEP" },
611 {}
612};
613
614static void
615nv50_pgraph_mp_trap(struct drm_device *dev, int tpid, int display)
616{
617 struct drm_nouveau_private *dev_priv = dev->dev_private;
618 uint32_t units = nv_rd32(dev, 0x1540);
619 uint32_t addr, mp10, status, pc, oplow, ophigh;
620 int i;
621 int mps = 0;
622 for (i = 0; i < 4; i++) {
623 if (!(units & 1 << (i+24)))
624 continue;
625 if (dev_priv->chipset < 0xa0)
626 addr = 0x408200 + (tpid << 12) + (i << 7);
627 else
628 addr = 0x408100 + (tpid << 11) + (i << 7);
629 mp10 = nv_rd32(dev, addr + 0x10);
630 status = nv_rd32(dev, addr + 0x14);
631 if (!status)
632 continue;
633 if (display) {
634 nv_rd32(dev, addr + 0x20);
635 pc = nv_rd32(dev, addr + 0x24);
636 oplow = nv_rd32(dev, addr + 0x70);
637 ophigh= nv_rd32(dev, addr + 0x74);
638 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - "
639 "TP %d MP %d: ", tpid, i);
640 nouveau_enum_print(nv50_mp_exec_error_names, status);
641 printk(" at %06x warp %d, opcode %08x %08x\n",
642 pc&0xffffff, pc >> 24,
643 oplow, ophigh);
644 }
645 nv_wr32(dev, addr + 0x10, mp10);
646 nv_wr32(dev, addr + 0x14, 0);
647 mps++;
648 }
649 if (!mps && display)
650 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - TP %d: "
651 "No MPs claiming errors?\n", tpid);
652}
653
654static void
655nv50_pgraph_tp_trap(struct drm_device *dev, int type, uint32_t ustatus_old,
656 uint32_t ustatus_new, int display, const char *name)
657{
658 struct drm_nouveau_private *dev_priv = dev->dev_private;
659 int tps = 0;
660 uint32_t units = nv_rd32(dev, 0x1540);
661 int i, r;
662 uint32_t ustatus_addr, ustatus;
663 for (i = 0; i < 16; i++) {
664 if (!(units & (1 << i)))
665 continue;
666 if (dev_priv->chipset < 0xa0)
667 ustatus_addr = ustatus_old + (i << 12);
668 else
669 ustatus_addr = ustatus_new + (i << 11);
670 ustatus = nv_rd32(dev, ustatus_addr) & 0x7fffffff;
671 if (!ustatus)
672 continue;
673 tps++;
674 switch (type) {
675 case 6: /* texture error... unknown for now */
676 nv50_fb_vm_trap(dev, display, name);
677 if (display) {
678 NV_ERROR(dev, "magic set %d:\n", i);
679 for (r = ustatus_addr + 4; r <= ustatus_addr + 0x10; r += 4)
680 NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r,
681 nv_rd32(dev, r));
682 }
683 break;
684 case 7: /* MP error */
685 if (ustatus & 0x00010000) {
686 nv50_pgraph_mp_trap(dev, i, display);
687 ustatus &= ~0x00010000;
688 }
689 break;
690 case 8: /* TPDMA error */
691 {
692 uint32_t e0c = nv_rd32(dev, ustatus_addr + 4);
693 uint32_t e10 = nv_rd32(dev, ustatus_addr + 8);
694 uint32_t e14 = nv_rd32(dev, ustatus_addr + 0xc);
695 uint32_t e18 = nv_rd32(dev, ustatus_addr + 0x10);
696 uint32_t e1c = nv_rd32(dev, ustatus_addr + 0x14);
697 uint32_t e20 = nv_rd32(dev, ustatus_addr + 0x18);
698 uint32_t e24 = nv_rd32(dev, ustatus_addr + 0x1c);
699 nv50_fb_vm_trap(dev, display, name);
700 /* 2d engine destination */
701 if (ustatus & 0x00000010) {
702 if (display) {
703 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - Unknown fault at address %02x%08x\n",
704 i, e14, e10);
705 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
706 i, e0c, e18, e1c, e20, e24);
707 }
708 ustatus &= ~0x00000010;
709 }
710 /* Render target */
711 if (ustatus & 0x00000040) {
712 if (display) {
713 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - Unknown fault at address %02x%08x\n",
714 i, e14, e10);
715 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
716 i, e0c, e18, e1c, e20, e24);
717 }
718 ustatus &= ~0x00000040;
719 }
720 /* CUDA memory: l[], g[] or stack. */
721 if (ustatus & 0x00000080) {
722 if (display) {
723 if (e18 & 0x80000000) {
724 /* g[] read fault? */
725 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global read fault at address %02x%08x\n",
726 i, e14, e10 | ((e18 >> 24) & 0x1f));
727 e18 &= ~0x1f000000;
728 } else if (e18 & 0xc) {
729 /* g[] write fault? */
730 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global write fault at address %02x%08x\n",
731 i, e14, e10 | ((e18 >> 7) & 0x1f));
732 e18 &= ~0x00000f80;
733 } else {
734 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Unknown CUDA fault at address %02x%08x\n",
735 i, e14, e10);
736 }
737 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
738 i, e0c, e18, e1c, e20, e24);
739 }
740 ustatus &= ~0x00000080;
741 }
742 }
743 break;
744 }
745 if (ustatus) {
746 if (display)
747 NV_INFO(dev, "%s - TP%d: Unhandled ustatus 0x%08x\n", name, i, ustatus);
748 }
749 nv_wr32(dev, ustatus_addr, 0xc0000000);
750 }
751
752 if (!tps && display)
753 NV_INFO(dev, "%s - No TPs claiming errors?\n", name);
754}
755
756static int
757nv50_pgraph_trap_handler(struct drm_device *dev, u32 display, u64 inst, u32 chid)
758{
759 u32 status = nv_rd32(dev, 0x400108);
760 u32 ustatus;
761
762 if (!status && display) {
763 NV_INFO(dev, "PGRAPH - TRAP: no units reporting traps?\n");
764 return 1;
765 }
766
767 /* DISPATCH: Relays commands to other units and handles NOTIFY,
768 * COND, QUERY. If you get a trap from it, the command is still stuck
769 * in DISPATCH and you need to do something about it. */
770 if (status & 0x001) {
771 ustatus = nv_rd32(dev, 0x400804) & 0x7fffffff;
772 if (!ustatus && display) {
773 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - no ustatus?\n");
774 }
775
776 nv_wr32(dev, 0x400500, 0x00000000);
777
778 /* Known to be triggered by screwed up NOTIFY and COND... */
779 if (ustatus & 0x00000001) {
780 u32 addr = nv_rd32(dev, 0x400808);
781 u32 subc = (addr & 0x00070000) >> 16;
782 u32 mthd = (addr & 0x00001ffc);
783 u32 datal = nv_rd32(dev, 0x40080c);
784 u32 datah = nv_rd32(dev, 0x400810);
785 u32 class = nv_rd32(dev, 0x400814);
786 u32 r848 = nv_rd32(dev, 0x400848);
787
788 NV_INFO(dev, "PGRAPH - TRAP DISPATCH_FAULT\n");
789 if (display && (addr & 0x80000000)) {
790 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
791 "subc %d class 0x%04x mthd 0x%04x "
792 "data 0x%08x%08x "
793 "400808 0x%08x 400848 0x%08x\n",
794 chid, inst, subc, class, mthd, datah,
795 datal, addr, r848);
796 } else
797 if (display) {
798 NV_INFO(dev, "PGRAPH - no stuck command?\n");
799 }
800
801 nv_wr32(dev, 0x400808, 0);
802 nv_wr32(dev, 0x4008e8, nv_rd32(dev, 0x4008e8) & 3);
803 nv_wr32(dev, 0x400848, 0);
804 ustatus &= ~0x00000001;
805 }
806
807 if (ustatus & 0x00000002) {
808 u32 addr = nv_rd32(dev, 0x40084c);
809 u32 subc = (addr & 0x00070000) >> 16;
810 u32 mthd = (addr & 0x00001ffc);
811 u32 data = nv_rd32(dev, 0x40085c);
812 u32 class = nv_rd32(dev, 0x400814);
813
814 NV_INFO(dev, "PGRAPH - TRAP DISPATCH_QUERY\n");
815 if (display && (addr & 0x80000000)) {
816 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
817 "subc %d class 0x%04x mthd 0x%04x "
818 "data 0x%08x 40084c 0x%08x\n",
819 chid, inst, subc, class, mthd,
820 data, addr);
821 } else
822 if (display) {
823 NV_INFO(dev, "PGRAPH - no stuck command?\n");
824 }
825
826 nv_wr32(dev, 0x40084c, 0);
827 ustatus &= ~0x00000002;
828 }
829
830 if (ustatus && display) {
831 NV_INFO(dev, "PGRAPH - TRAP_DISPATCH (unknown "
832 "0x%08x)\n", ustatus);
833 }
834
835 nv_wr32(dev, 0x400804, 0xc0000000);
836 nv_wr32(dev, 0x400108, 0x001);
837 status &= ~0x001;
838 if (!status)
839 return 0;
840 }
841
842 /* M2MF: Memory to memory copy engine. */
843 if (status & 0x002) {
844 u32 ustatus = nv_rd32(dev, 0x406800) & 0x7fffffff;
845 if (display) {
846 NV_INFO(dev, "PGRAPH - TRAP_M2MF");
847 nouveau_bitfield_print(nv50_graph_trap_m2mf, ustatus);
848 printk("\n");
849 NV_INFO(dev, "PGRAPH - TRAP_M2MF %08x %08x %08x %08x\n",
850 nv_rd32(dev, 0x406804), nv_rd32(dev, 0x406808),
851 nv_rd32(dev, 0x40680c), nv_rd32(dev, 0x406810));
852
853 }
854
855 /* No sane way found yet -- just reset the bugger. */
856 nv_wr32(dev, 0x400040, 2);
857 nv_wr32(dev, 0x400040, 0);
858 nv_wr32(dev, 0x406800, 0xc0000000);
859 nv_wr32(dev, 0x400108, 0x002);
860 status &= ~0x002;
861 }
862
863 /* VFETCH: Fetches data from vertex buffers. */
864 if (status & 0x004) {
865 u32 ustatus = nv_rd32(dev, 0x400c04) & 0x7fffffff;
866 if (display) {
867 NV_INFO(dev, "PGRAPH - TRAP_VFETCH");
868 nouveau_bitfield_print(nv50_graph_trap_vfetch, ustatus);
869 printk("\n");
870 NV_INFO(dev, "PGRAPH - TRAP_VFETCH %08x %08x %08x %08x\n",
871 nv_rd32(dev, 0x400c00), nv_rd32(dev, 0x400c08),
872 nv_rd32(dev, 0x400c0c), nv_rd32(dev, 0x400c10));
873 }
874
875 nv_wr32(dev, 0x400c04, 0xc0000000);
876 nv_wr32(dev, 0x400108, 0x004);
877 status &= ~0x004;
878 }
879
880 /* STRMOUT: DirectX streamout / OpenGL transform feedback. */
881 if (status & 0x008) {
882 ustatus = nv_rd32(dev, 0x401800) & 0x7fffffff;
883 if (display) {
884 NV_INFO(dev, "PGRAPH - TRAP_STRMOUT");
885 nouveau_bitfield_print(nv50_graph_trap_strmout, ustatus);
886 printk("\n");
887 NV_INFO(dev, "PGRAPH - TRAP_STRMOUT %08x %08x %08x %08x\n",
888 nv_rd32(dev, 0x401804), nv_rd32(dev, 0x401808),
889 nv_rd32(dev, 0x40180c), nv_rd32(dev, 0x401810));
890
891 }
892
893 /* No sane way found yet -- just reset the bugger. */
894 nv_wr32(dev, 0x400040, 0x80);
895 nv_wr32(dev, 0x400040, 0);
896 nv_wr32(dev, 0x401800, 0xc0000000);
897 nv_wr32(dev, 0x400108, 0x008);
898 status &= ~0x008;
899 }
900
901 /* CCACHE: Handles code and c[] caches and fills them. */
902 if (status & 0x010) {
903 ustatus = nv_rd32(dev, 0x405018) & 0x7fffffff;
904 if (display) {
905 NV_INFO(dev, "PGRAPH - TRAP_CCACHE");
906 nouveau_bitfield_print(nv50_graph_trap_ccache, ustatus);
907 printk("\n");
908 NV_INFO(dev, "PGRAPH - TRAP_CCACHE %08x %08x %08x %08x"
909 " %08x %08x %08x\n",
Marcin Slusarz4dcf9052011-02-13 20:46:41 +0100910 nv_rd32(dev, 0x405000), nv_rd32(dev, 0x405004),
911 nv_rd32(dev, 0x405008), nv_rd32(dev, 0x40500c),
912 nv_rd32(dev, 0x405010), nv_rd32(dev, 0x405014),
913 nv_rd32(dev, 0x40501c));
Ben Skeggs274fec92010-11-03 13:16:18 +1000914
915 }
916
917 nv_wr32(dev, 0x405018, 0xc0000000);
918 nv_wr32(dev, 0x400108, 0x010);
919 status &= ~0x010;
920 }
921
922 /* Unknown, not seen yet... 0x402000 is the only trap status reg
923 * remaining, so try to handle it anyway. Perhaps related to that
924 * unknown DMA slot on tesla? */
925 if (status & 0x20) {
926 ustatus = nv_rd32(dev, 0x402000) & 0x7fffffff;
927 if (display)
928 NV_INFO(dev, "PGRAPH - TRAP_UNKC04 0x%08x\n", ustatus);
929 nv_wr32(dev, 0x402000, 0xc0000000);
930 /* no status modifiction on purpose */
931 }
932
933 /* TEXTURE: CUDA texturing units */
934 if (status & 0x040) {
935 nv50_pgraph_tp_trap(dev, 6, 0x408900, 0x408600, display,
936 "PGRAPH - TRAP_TEXTURE");
937 nv_wr32(dev, 0x400108, 0x040);
938 status &= ~0x040;
939 }
940
941 /* MP: CUDA execution engines. */
942 if (status & 0x080) {
943 nv50_pgraph_tp_trap(dev, 7, 0x408314, 0x40831c, display,
944 "PGRAPH - TRAP_MP");
945 nv_wr32(dev, 0x400108, 0x080);
946 status &= ~0x080;
947 }
948
949 /* TPDMA: Handles TP-initiated uncached memory accesses:
950 * l[], g[], stack, 2d surfaces, render targets. */
951 if (status & 0x100) {
952 nv50_pgraph_tp_trap(dev, 8, 0x408e08, 0x408708, display,
953 "PGRAPH - TRAP_TPDMA");
954 nv_wr32(dev, 0x400108, 0x100);
955 status &= ~0x100;
956 }
957
958 if (status) {
959 if (display)
960 NV_INFO(dev, "PGRAPH - TRAP: unknown 0x%08x\n", status);
961 nv_wr32(dev, 0x400108, status);
962 }
963
964 return 1;
965}
966
967static int
968nv50_graph_isr_chid(struct drm_device *dev, u64 inst)
969{
970 struct drm_nouveau_private *dev_priv = dev->dev_private;
971 struct nouveau_channel *chan;
972 unsigned long flags;
973 int i;
974
975 spin_lock_irqsave(&dev_priv->channels.lock, flags);
976 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
977 chan = dev_priv->channels.ptr[i];
978 if (!chan || !chan->ramin)
979 continue;
980
981 if (inst == chan->ramin->vinst)
982 break;
983 }
984 spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
985 return i;
986}
987
988static void
989nv50_graph_isr(struct drm_device *dev)
990{
991 u32 stat;
992
993 while ((stat = nv_rd32(dev, 0x400100))) {
994 u64 inst = (u64)(nv_rd32(dev, 0x40032c) & 0x0fffffff) << 12;
995 u32 chid = nv50_graph_isr_chid(dev, inst);
996 u32 addr = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR);
997 u32 subc = (addr & 0x00070000) >> 16;
998 u32 mthd = (addr & 0x00001ffc);
999 u32 data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA);
1000 u32 class = nv_rd32(dev, 0x400814);
1001 u32 show = stat;
1002
1003 if (stat & 0x00000010) {
1004 if (!nouveau_gpuobj_mthd_call2(dev, chid, class,
1005 mthd, data))
1006 show &= ~0x00000010;
1007 }
1008
1009 if (stat & 0x00001000) {
1010 nv_wr32(dev, 0x400500, 0x00000000);
1011 nv_wr32(dev, 0x400100, 0x00001000);
1012 nv_mask(dev, 0x40013c, 0x00001000, 0x00000000);
1013 nv50_graph_context_switch(dev);
1014 stat &= ~0x00001000;
1015 show &= ~0x00001000;
1016 }
1017
1018 show = (show && nouveau_ratelimit()) ? show : 0;
1019
1020 if (show & 0x00100000) {
1021 u32 ecode = nv_rd32(dev, 0x400110);
1022 NV_INFO(dev, "PGRAPH - DATA_ERROR ");
1023 nouveau_enum_print(nv50_data_error_names, ecode);
1024 printk("\n");
1025 }
1026
1027 if (stat & 0x00200000) {
1028 if (!nv50_pgraph_trap_handler(dev, show, inst, chid))
1029 show &= ~0x00200000;
1030 }
1031
1032 nv_wr32(dev, 0x400100, stat);
1033 nv_wr32(dev, 0x400500, 0x00010001);
1034
1035 if (show) {
1036 NV_INFO(dev, "PGRAPH -");
1037 nouveau_bitfield_print(nv50_graph_intr, show);
1038 printk("\n");
1039 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) subc %d "
1040 "class 0x%04x mthd 0x%04x data 0x%08x\n",
1041 chid, inst, subc, class, mthd, data);
1042 }
1043 }
1044
1045 if (nv_rd32(dev, 0x400824) & (1 << 31))
1046 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) & ~(1 << 31));
1047}