blob: 2698d80c8eb211f310e4ffddb209679cfc523260 [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
42static void
43nv50_graph_fifo_access(struct drm_device *dev, bool enabled)
44{
45 const uint32_t mask = 0x00010001;
46
47 if (enabled)
48 nv_wr32(dev, 0x400500, nv_rd32(dev, 0x400500) | mask);
49 else
50 nv_wr32(dev, 0x400500, nv_rd32(dev, 0x400500) & ~mask);
51}
52
53static struct nouveau_channel *
54nv50_graph_channel(struct drm_device *dev)
55{
56 struct drm_nouveau_private *dev_priv = dev->dev_private;
57 uint32_t inst;
58 int i;
59
60 /* Be sure we're not in the middle of a context switch or bad things
61 * will happen, such as unloading the wrong pgraph context.
62 */
63 if (!nv_wait(dev, 0x400300, 0x00000001, 0x00000000))
64 NV_ERROR(dev, "Ctxprog is still running\n");
65
66 inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_CUR);
67 if (!(inst & NV50_PGRAPH_CTXCTL_CUR_LOADED))
68 return NULL;
69 inst = (inst & NV50_PGRAPH_CTXCTL_CUR_INSTANCE) << 12;
70
71 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
72 struct nouveau_channel *chan = dev_priv->channels.ptr[i];
73
74 if (chan && chan->ramin && chan->ramin->vinst == inst)
75 return chan;
76 }
77
78 return NULL;
79}
80
81static int
82nv50_graph_do_load_context(struct drm_device *dev, uint32_t inst)
83{
84 uint32_t fifo = nv_rd32(dev, 0x400500);
85
86 nv_wr32(dev, 0x400500, fifo & ~1);
87 nv_wr32(dev, 0x400784, inst);
88 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) | 0x40);
89 nv_wr32(dev, 0x400320, nv_rd32(dev, 0x400320) | 0x11);
90 nv_wr32(dev, 0x400040, 0xffffffff);
91 (void)nv_rd32(dev, 0x400040);
92 nv_wr32(dev, 0x400040, 0x00000000);
93 nv_wr32(dev, 0x400304, nv_rd32(dev, 0x400304) | 1);
94
95 if (nouveau_wait_for_idle(dev))
96 nv_wr32(dev, 0x40032c, inst | (1<<31));
97 nv_wr32(dev, 0x400500, fifo);
98
99 return 0;
100}
101
102static int
103nv50_graph_unload_context(struct drm_device *dev)
104{
105 uint32_t inst;
106
107 inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_CUR);
108 if (!(inst & NV50_PGRAPH_CTXCTL_CUR_LOADED))
109 return 0;
110 inst &= NV50_PGRAPH_CTXCTL_CUR_INSTANCE;
111
112 nouveau_wait_for_idle(dev);
113 nv_wr32(dev, 0x400784, inst);
114 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) | 0x20);
115 nv_wr32(dev, 0x400304, nv_rd32(dev, 0x400304) | 0x01);
116 nouveau_wait_for_idle(dev);
117
118 nv_wr32(dev, NV50_PGRAPH_CTXCTL_CUR, inst);
119 return 0;
120}
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000121
Ben Skeggs6d6538a2011-08-12 09:30:58 +1000122static int
123nv50_graph_init(struct drm_device *dev, int engine)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000124{
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000125 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggs6d6538a2011-08-12 09:30:58 +1000126 struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
127 u32 units = nv_rd32(dev, 0x001540);
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000128 int i;
129
Ben Skeggs6ee73862009-12-11 19:24:15 +1000130 NV_DEBUG(dev, "\n");
131
Ben Skeggs6d6538a2011-08-12 09:30:58 +1000132 /* master reset */
Ben Skeggsdce411c2011-09-29 13:15:17 +1000133 nv_mask(dev, 0x000200, 0x00201000, 0x00000000);
134 nv_mask(dev, 0x000200, 0x00201000, 0x00201000);
Ben Skeggs6d6538a2011-08-12 09:30:58 +1000135 nv_wr32(dev, 0x40008c, 0x00000004); /* HW_CTX_SWITCH_ENABLED */
136
137 /* reset/enable traps and interrupts */
Ben Skeggs6ee73862009-12-11 19:24:15 +1000138 nv_wr32(dev, 0x400804, 0xc0000000);
139 nv_wr32(dev, 0x406800, 0xc0000000);
140 nv_wr32(dev, 0x400c04, 0xc0000000);
Marcin Kościelnicki716abaa2010-01-12 18:21:56 +0000141 nv_wr32(dev, 0x401800, 0xc0000000);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000142 nv_wr32(dev, 0x405018, 0xc0000000);
143 nv_wr32(dev, 0x402000, 0xc0000000);
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000144 for (i = 0; i < 16; i++) {
Ben Skeggs6d6538a2011-08-12 09:30:58 +1000145 if (!(units & (1 << i)))
146 continue;
147
148 if (dev_priv->chipset < 0xa0) {
149 nv_wr32(dev, 0x408900 + (i << 12), 0xc0000000);
150 nv_wr32(dev, 0x408e08 + (i << 12), 0xc0000000);
151 nv_wr32(dev, 0x408314 + (i << 12), 0xc0000000);
152 } else {
153 nv_wr32(dev, 0x408600 + (i << 11), 0xc0000000);
154 nv_wr32(dev, 0x408708 + (i << 11), 0xc0000000);
155 nv_wr32(dev, 0x40831c + (i << 11), 0xc0000000);
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000156 }
157 }
158
Ben Skeggs6ee73862009-12-11 19:24:15 +1000159 nv_wr32(dev, 0x400108, 0xffffffff);
Ben Skeggs6d6538a2011-08-12 09:30:58 +1000160 nv_wr32(dev, 0x400138, 0xffffffff);
161 nv_wr32(dev, 0x400100, 0xffffffff);
162 nv_wr32(dev, 0x40013c, 0xffffffff);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000163 nv_wr32(dev, 0x400500, 0x00010001);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000164
Ben Skeggs6d6538a2011-08-12 09:30:58 +1000165 /* upload context program, initialise ctxctl defaults */
166 nv_wr32(dev, 0x400324, 0x00000000);
167 for (i = 0; i < pgraph->ctxprog_size; i++)
168 nv_wr32(dev, 0x400328, pgraph->ctxprog[i]);
169 nv_wr32(dev, 0x400824, 0x00000000);
170 nv_wr32(dev, 0x400828, 0x00000000);
171 nv_wr32(dev, 0x40082c, 0x00000000);
172 nv_wr32(dev, 0x400830, 0x00000000);
173 nv_wr32(dev, 0x400724, 0x00000000);
174 nv_wr32(dev, 0x40032c, 0x00000000);
175 nv_wr32(dev, 0x400320, 4); /* CTXCTL_CMD = NEWCTXDMA */
Ben Skeggs562af102011-02-23 09:00:35 +1000176
Ben Skeggs6d6538a2011-08-12 09:30:58 +1000177 /* some unknown zcull magic */
Ben Skeggs562af102011-02-23 09:00:35 +1000178 switch (dev_priv->chipset & 0xf0) {
179 case 0x50:
180 case 0x80:
181 case 0x90:
182 nv_wr32(dev, 0x402ca8, 0x00000800);
183 break;
184 case 0xa0:
185 default:
186 nv_wr32(dev, 0x402cc0, 0x00000000);
187 if (dev_priv->chipset == 0xa0 ||
188 dev_priv->chipset == 0xaa ||
189 dev_priv->chipset == 0xac) {
190 nv_wr32(dev, 0x402ca8, 0x00000802);
191 } else {
192 nv_wr32(dev, 0x402cc0, 0x00000000);
193 nv_wr32(dev, 0x402ca8, 0x00000002);
194 }
195
196 break;
197 }
198
199 /* zero out zcull regions */
200 for (i = 0; i < 8; i++) {
201 nv_wr32(dev, 0x402c20 + (i * 8), 0x00000000);
202 nv_wr32(dev, 0x402c24 + (i * 8), 0x00000000);
203 nv_wr32(dev, 0x402c28 + (i * 8), 0x00000000);
204 nv_wr32(dev, 0x402c2c + (i * 8), 0x00000000);
205 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000206
Ben Skeggs6ee73862009-12-11 19:24:15 +1000207 return 0;
208}
209
Ben Skeggs2703c212011-04-01 09:50:18 +1000210static int
Ben Skeggs6c320fe2011-07-20 11:22:33 +1000211nv50_graph_fini(struct drm_device *dev, int engine, bool suspend)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000212{
Ben Skeggs9962cc62011-07-20 11:44:52 +1000213 nv_mask(dev, 0x400500, 0x00010001, 0x00000000);
214 if (!nv_wait(dev, 0x400700, ~0, 0) && suspend) {
215 nv_mask(dev, 0x400500, 0x00010001, 0x00010001);
216 return -EBUSY;
217 }
Ben Skeggs2703c212011-04-01 09:50:18 +1000218 nv50_graph_unload_context(dev);
Ben Skeggs274fec92010-11-03 13:16:18 +1000219 nv_wr32(dev, 0x40013c, 0x00000000);
Ben Skeggs2703c212011-04-01 09:50:18 +1000220 return 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000221}
222
Ben Skeggs2703c212011-04-01 09:50:18 +1000223static int
224nv50_graph_context_new(struct nouveau_channel *chan, int engine)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000225{
226 struct drm_device *dev = chan->dev;
227 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000228 struct nouveau_gpuobj *ramin = chan->ramin;
Ben Skeggs2703c212011-04-01 09:50:18 +1000229 struct nouveau_gpuobj *grctx = NULL;
230 struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000231 int hdr, ret;
232
233 NV_DEBUG(dev, "ch%d\n", chan->id);
234
Ben Skeggs2703c212011-04-01 09:50:18 +1000235 ret = nouveau_gpuobj_new(dev, NULL, pgraph->grctx_size, 0,
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000236 NVOBJ_FLAG_ZERO_ALLOC |
Ben Skeggs2703c212011-04-01 09:50:18 +1000237 NVOBJ_FLAG_ZERO_FREE, &grctx);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000238 if (ret)
239 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000240
Ben Skeggsac94a342010-07-08 15:28:48 +1000241 hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
Ben Skeggsb3beb162010-09-01 15:24:29 +1000242 nv_wo32(ramin, hdr + 0x00, 0x00190002);
Ben Skeggs2703c212011-04-01 09:50:18 +1000243 nv_wo32(ramin, hdr + 0x04, grctx->vinst + grctx->size - 1);
244 nv_wo32(ramin, hdr + 0x08, grctx->vinst);
Ben Skeggsb3beb162010-09-01 15:24:29 +1000245 nv_wo32(ramin, hdr + 0x0c, 0);
246 nv_wo32(ramin, hdr + 0x10, 0);
247 nv_wo32(ramin, hdr + 0x14, 0x00010000);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000248
Ben Skeggsd58086d2012-04-20 11:54:33 +1000249 nv50_grctx_fill(dev, grctx);
Ben Skeggs2703c212011-04-01 09:50:18 +1000250 nv_wo32(grctx, 0x00000, chan->ramin->vinst >> 12);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000251
Ben Skeggsf56cb862010-07-08 11:29:10 +1000252 dev_priv->engine.instmem.flush(dev);
Ben Skeggs2703c212011-04-01 09:50:18 +1000253
254 atomic_inc(&chan->vm->engref[NVOBJ_ENGINE_GR]);
255 chan->engctx[NVOBJ_ENGINE_GR] = grctx;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000256 return 0;
257}
258
Ben Skeggs2703c212011-04-01 09:50:18 +1000259static void
260nv50_graph_context_del(struct nouveau_channel *chan, int engine)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000261{
Ben Skeggs2703c212011-04-01 09:50:18 +1000262 struct nouveau_gpuobj *grctx = chan->engctx[engine];
Ben Skeggs6ee73862009-12-11 19:24:15 +1000263 struct drm_device *dev = chan->dev;
264 struct drm_nouveau_private *dev_priv = dev->dev_private;
Francisco Jerez34311c72011-01-24 01:47:42 +0100265 struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
Ben Skeggsac94a342010-07-08 15:28:48 +1000266 int i, hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
Francisco Jerez3945e472010-10-18 03:53:39 +0200267 unsigned long flags;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000268
269 NV_DEBUG(dev, "ch%d\n", chan->id);
270
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000271 if (!chan->ramin)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000272 return;
273
Francisco Jerez3945e472010-10-18 03:53:39 +0200274 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
Francisco Jerez34311c72011-01-24 01:47:42 +0100275 pfifo->reassign(dev, false);
Ben Skeggs2703c212011-04-01 09:50:18 +1000276 nv50_graph_fifo_access(dev, false);
Francisco Jerez3945e472010-10-18 03:53:39 +0200277
Ben Skeggs2703c212011-04-01 09:50:18 +1000278 if (nv50_graph_channel(dev) == chan)
279 nv50_graph_unload_context(dev);
Francisco Jerez3945e472010-10-18 03:53:39 +0200280
Ben Skeggs6ee73862009-12-11 19:24:15 +1000281 for (i = hdr; i < hdr + 24; i += 4)
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000282 nv_wo32(chan->ramin, i, 0);
Ben Skeggsf56cb862010-07-08 11:29:10 +1000283 dev_priv->engine.instmem.flush(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000284
Ben Skeggs2703c212011-04-01 09:50:18 +1000285 nv50_graph_fifo_access(dev, true);
Francisco Jerez34311c72011-01-24 01:47:42 +0100286 pfifo->reassign(dev, true);
Francisco Jerez3945e472010-10-18 03:53:39 +0200287 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
288
Ben Skeggs2703c212011-04-01 09:50:18 +1000289 nouveau_gpuobj_ref(NULL, &grctx);
Ben Skeggs4c1361422010-11-15 11:54:21 +1000290
Ben Skeggs2703c212011-04-01 09:50:18 +1000291 atomic_dec(&chan->vm->engref[engine]);
292 chan->engctx[engine] = NULL;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000293}
294
295static int
Ben Skeggs2703c212011-04-01 09:50:18 +1000296nv50_graph_object_new(struct nouveau_channel *chan, int engine,
297 u32 handle, u16 class)
Ben Skeggs4ea52f82011-03-31 13:44:16 +1000298{
299 struct drm_device *dev = chan->dev;
300 struct drm_nouveau_private *dev_priv = dev->dev_private;
301 struct nouveau_gpuobj *obj = NULL;
302 int ret;
303
304 ret = nouveau_gpuobj_new(dev, chan, 16, 16, NVOBJ_FLAG_ZERO_FREE, &obj);
305 if (ret)
306 return ret;
307 obj->engine = 1;
308 obj->class = class;
309
310 nv_wo32(obj, 0x00, class);
311 nv_wo32(obj, 0x04, 0x00000000);
312 nv_wo32(obj, 0x08, 0x00000000);
313 nv_wo32(obj, 0x0c, 0x00000000);
314 dev_priv->engine.instmem.flush(dev);
315
316 ret = nouveau_ramht_insert(chan, handle, obj);
317 nouveau_gpuobj_ref(NULL, &obj);
318 return ret;
319}
320
Ben Skeggs274fec92010-11-03 13:16:18 +1000321static void
Ben Skeggs6ee73862009-12-11 19:24:15 +1000322nv50_graph_context_switch(struct drm_device *dev)
323{
324 uint32_t inst;
325
326 nv50_graph_unload_context(dev);
327
328 inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_NEXT);
329 inst &= NV50_PGRAPH_CTXCTL_NEXT_INSTANCE;
330 nv50_graph_do_load_context(dev, inst);
331
332 nv_wr32(dev, NV40_PGRAPH_INTR_EN, nv_rd32(dev,
333 NV40_PGRAPH_INTR_EN) | NV_PGRAPH_INTR_CONTEXT_SWITCH);
334}
335
336static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000337nv50_graph_nvsw_dma_vblsem(struct nouveau_channel *chan,
338 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000339{
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000340 struct nouveau_gpuobj *gpuobj;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000341
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000342 gpuobj = nouveau_ramht_find(chan, data);
343 if (!gpuobj)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000344 return -ENOENT;
345
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000346 if (nouveau_notifier_offset(gpuobj, NULL))
Ben Skeggs6ee73862009-12-11 19:24:15 +1000347 return -EINVAL;
348
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000349 chan->nvsw.vblsem = gpuobj;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000350 chan->nvsw.vblsem_offset = ~0;
351 return 0;
352}
353
354static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000355nv50_graph_nvsw_vblsem_offset(struct nouveau_channel *chan,
356 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000357{
358 if (nouveau_notifier_offset(chan->nvsw.vblsem, &data))
359 return -ERANGE;
360
361 chan->nvsw.vblsem_offset = data >> 2;
362 return 0;
363}
364
365static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000366nv50_graph_nvsw_vblsem_release_val(struct nouveau_channel *chan,
367 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000368{
369 chan->nvsw.vblsem_rval = data;
370 return 0;
371}
372
373static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000374nv50_graph_nvsw_vblsem_release(struct nouveau_channel *chan,
375 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000376{
377 struct drm_device *dev = chan->dev;
378 struct drm_nouveau_private *dev_priv = dev->dev_private;
379
380 if (!chan->nvsw.vblsem || chan->nvsw.vblsem_offset == ~0 || data > 1)
381 return -EINVAL;
382
Francisco Jerez042206c2010-10-21 18:19:29 +0200383 drm_vblank_get(dev, data);
Francisco Jerez1f6d2de2010-10-24 14:15:58 +0200384
385 chan->nvsw.vblsem_head = data;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000386 list_add(&chan->nvsw.vbl_wait, &dev_priv->vbl_waiting);
Francisco Jerez1f6d2de2010-10-24 14:15:58 +0200387
Ben Skeggs6ee73862009-12-11 19:24:15 +1000388 return 0;
389}
390
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000391static int
Francisco Jerez332b2422010-10-20 23:35:40 +0200392nv50_graph_nvsw_mthd_page_flip(struct nouveau_channel *chan,
393 u32 class, u32 mthd, u32 data)
394{
Ben Skeggsd7117e02011-02-07 14:27:04 +1000395 nouveau_finish_page_flip(chan, NULL);
Francisco Jerez332b2422010-10-20 23:35:40 +0200396 return 0;
397}
398
Ben Skeggs6ee73862009-12-11 19:24:15 +1000399
Ben Skeggs2703c212011-04-01 09:50:18 +1000400static void
401nv50_graph_tlb_flush(struct drm_device *dev, int engine)
Ben Skeggs56ac7472010-10-22 10:26:24 +1000402{
Ben Skeggsa11c3192010-08-27 10:00:25 +1000403 nv50_vm_flush_engine(dev, 0);
Ben Skeggs56ac7472010-10-22 10:26:24 +1000404}
405
Ben Skeggs2703c212011-04-01 09:50:18 +1000406static void
407nv84_graph_tlb_flush(struct drm_device *dev, int engine)
Ben Skeggs56ac7472010-10-22 10:26:24 +1000408{
409 struct drm_nouveau_private *dev_priv = dev->dev_private;
410 struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer;
411 bool idle, timeout = false;
412 unsigned long flags;
413 u64 start;
414 u32 tmp;
415
416 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
417 nv_mask(dev, 0x400500, 0x00000001, 0x00000000);
418
419 start = ptimer->read(dev);
420 do {
421 idle = true;
422
423 for (tmp = nv_rd32(dev, 0x400380); tmp && idle; tmp >>= 3) {
424 if ((tmp & 7) == 1)
425 idle = false;
426 }
427
428 for (tmp = nv_rd32(dev, 0x400384); tmp && idle; tmp >>= 3) {
429 if ((tmp & 7) == 1)
430 idle = false;
431 }
432
433 for (tmp = nv_rd32(dev, 0x400388); tmp && idle; tmp >>= 3) {
434 if ((tmp & 7) == 1)
435 idle = false;
436 }
437 } while (!idle && !(timeout = ptimer->read(dev) - start > 2000000000));
438
439 if (timeout) {
440 NV_ERROR(dev, "PGRAPH TLB flush idle timeout fail: "
441 "0x%08x 0x%08x 0x%08x 0x%08x\n",
442 nv_rd32(dev, 0x400700), nv_rd32(dev, 0x400380),
443 nv_rd32(dev, 0x400384), nv_rd32(dev, 0x400388));
444 }
445
Ben Skeggsa11c3192010-08-27 10:00:25 +1000446 nv50_vm_flush_engine(dev, 0);
Ben Skeggs56ac7472010-10-22 10:26:24 +1000447
448 nv_mask(dev, 0x400500, 0x00000001, 0x00000001);
449 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
450}
Ben Skeggs274fec92010-11-03 13:16:18 +1000451
Emil Velikovf9ec8f62011-03-19 23:31:53 +0000452static struct nouveau_enum nv50_mp_exec_error_names[] = {
Ben Skeggsbb9b18a2011-03-08 08:39:43 +1000453 { 3, "STACK_UNDERFLOW", NULL },
454 { 4, "QUADON_ACTIVE", NULL },
455 { 8, "TIMEOUT", NULL },
456 { 0x10, "INVALID_OPCODE", NULL },
457 { 0x40, "BREAKPOINT", NULL },
Ben Skeggs274fec92010-11-03 13:16:18 +1000458 {}
459};
460
461static struct nouveau_bitfield nv50_graph_trap_m2mf[] = {
462 { 0x00000001, "NOTIFY" },
463 { 0x00000002, "IN" },
464 { 0x00000004, "OUT" },
465 {}
466};
467
468static struct nouveau_bitfield nv50_graph_trap_vfetch[] = {
469 { 0x00000001, "FAULT" },
470 {}
471};
472
473static struct nouveau_bitfield nv50_graph_trap_strmout[] = {
474 { 0x00000001, "FAULT" },
475 {}
476};
477
478static struct nouveau_bitfield nv50_graph_trap_ccache[] = {
479 { 0x00000001, "FAULT" },
480 {}
481};
482
483/* There must be a *lot* of these. Will take some time to gather them up. */
Ben Skeggs6effe392010-12-30 11:48:03 +1000484struct nouveau_enum nv50_data_error_names[] = {
Ben Skeggsbb9b18a2011-03-08 08:39:43 +1000485 { 0x00000003, "INVALID_QUERY_OR_TEXTURE", NULL },
486 { 0x00000004, "INVALID_VALUE", NULL },
487 { 0x00000005, "INVALID_ENUM", NULL },
488 { 0x00000008, "INVALID_OBJECT", NULL },
489 { 0x00000009, "READ_ONLY_OBJECT", NULL },
490 { 0x0000000a, "SUPERVISOR_OBJECT", NULL },
491 { 0x0000000b, "INVALID_ADDRESS_ALIGNMENT", NULL },
492 { 0x0000000c, "INVALID_BITFIELD", NULL },
493 { 0x0000000d, "BEGIN_END_ACTIVE", NULL },
494 { 0x0000000e, "SEMANTIC_COLOR_BACK_OVER_LIMIT", NULL },
495 { 0x0000000f, "VIEWPORT_ID_NEEDS_GP", NULL },
496 { 0x00000010, "RT_DOUBLE_BIND", NULL },
497 { 0x00000011, "RT_TYPES_MISMATCH", NULL },
498 { 0x00000012, "RT_LINEAR_WITH_ZETA", NULL },
499 { 0x00000015, "FP_TOO_FEW_REGS", NULL },
500 { 0x00000016, "ZETA_FORMAT_CSAA_MISMATCH", NULL },
501 { 0x00000017, "RT_LINEAR_WITH_MSAA", NULL },
502 { 0x00000018, "FP_INTERPOLANT_START_OVER_LIMIT", NULL },
503 { 0x00000019, "SEMANTIC_LAYER_OVER_LIMIT", NULL },
504 { 0x0000001a, "RT_INVALID_ALIGNMENT", NULL },
505 { 0x0000001b, "SAMPLER_OVER_LIMIT", NULL },
506 { 0x0000001c, "TEXTURE_OVER_LIMIT", NULL },
507 { 0x0000001e, "GP_TOO_MANY_OUTPUTS", NULL },
508 { 0x0000001f, "RT_BPP128_WITH_MS8", NULL },
509 { 0x00000021, "Z_OUT_OF_BOUNDS", NULL },
510 { 0x00000023, "XY_OUT_OF_BOUNDS", NULL },
511 { 0x00000027, "CP_MORE_PARAMS_THAN_SHARED", NULL },
512 { 0x00000028, "CP_NO_REG_SPACE_STRIPED", NULL },
513 { 0x00000029, "CP_NO_REG_SPACE_PACKED", NULL },
514 { 0x0000002a, "CP_NOT_ENOUGH_WARPS", NULL },
515 { 0x0000002b, "CP_BLOCK_SIZE_MISMATCH", NULL },
516 { 0x0000002c, "CP_NOT_ENOUGH_LOCAL_WARPS", NULL },
517 { 0x0000002d, "CP_NOT_ENOUGH_STACK_WARPS", NULL },
518 { 0x0000002e, "CP_NO_BLOCKDIM_LATCH", NULL },
519 { 0x00000031, "ENG2D_FORMAT_MISMATCH", NULL },
520 { 0x0000003f, "PRIMITIVE_ID_NEEDS_GP", NULL },
521 { 0x00000044, "SEMANTIC_VIEWPORT_OVER_LIMIT", NULL },
522 { 0x00000045, "SEMANTIC_COLOR_FRONT_OVER_LIMIT", NULL },
523 { 0x00000046, "LAYER_ID_NEEDS_GP", NULL },
524 { 0x00000047, "SEMANTIC_CLIP_OVER_LIMIT", NULL },
525 { 0x00000048, "SEMANTIC_PTSZ_OVER_LIMIT", NULL },
Ben Skeggs274fec92010-11-03 13:16:18 +1000526 {}
527};
528
529static struct nouveau_bitfield nv50_graph_intr[] = {
530 { 0x00000001, "NOTIFY" },
531 { 0x00000002, "COMPUTE_QUERY" },
532 { 0x00000010, "ILLEGAL_MTHD" },
533 { 0x00000020, "ILLEGAL_CLASS" },
534 { 0x00000040, "DOUBLE_NOTIFY" },
535 { 0x00001000, "CONTEXT_SWITCH" },
536 { 0x00010000, "BUFFER_NOTIFY" },
537 { 0x00100000, "DATA_ERROR" },
538 { 0x00200000, "TRAP" },
539 { 0x01000000, "SINGLE_STEP" },
540 {}
541};
542
543static void
544nv50_pgraph_mp_trap(struct drm_device *dev, int tpid, int display)
545{
546 struct drm_nouveau_private *dev_priv = dev->dev_private;
547 uint32_t units = nv_rd32(dev, 0x1540);
548 uint32_t addr, mp10, status, pc, oplow, ophigh;
549 int i;
550 int mps = 0;
551 for (i = 0; i < 4; i++) {
552 if (!(units & 1 << (i+24)))
553 continue;
554 if (dev_priv->chipset < 0xa0)
555 addr = 0x408200 + (tpid << 12) + (i << 7);
556 else
557 addr = 0x408100 + (tpid << 11) + (i << 7);
558 mp10 = nv_rd32(dev, addr + 0x10);
559 status = nv_rd32(dev, addr + 0x14);
560 if (!status)
561 continue;
562 if (display) {
563 nv_rd32(dev, addr + 0x20);
564 pc = nv_rd32(dev, addr + 0x24);
565 oplow = nv_rd32(dev, addr + 0x70);
Emil Velikov0b89a072011-03-19 23:31:54 +0000566 ophigh = nv_rd32(dev, addr + 0x74);
Ben Skeggs274fec92010-11-03 13:16:18 +1000567 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - "
568 "TP %d MP %d: ", tpid, i);
569 nouveau_enum_print(nv50_mp_exec_error_names, status);
570 printk(" at %06x warp %d, opcode %08x %08x\n",
571 pc&0xffffff, pc >> 24,
572 oplow, ophigh);
573 }
574 nv_wr32(dev, addr + 0x10, mp10);
575 nv_wr32(dev, addr + 0x14, 0);
576 mps++;
577 }
578 if (!mps && display)
579 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - TP %d: "
580 "No MPs claiming errors?\n", tpid);
581}
582
583static void
584nv50_pgraph_tp_trap(struct drm_device *dev, int type, uint32_t ustatus_old,
585 uint32_t ustatus_new, int display, const char *name)
586{
587 struct drm_nouveau_private *dev_priv = dev->dev_private;
588 int tps = 0;
589 uint32_t units = nv_rd32(dev, 0x1540);
590 int i, r;
591 uint32_t ustatus_addr, ustatus;
592 for (i = 0; i < 16; i++) {
593 if (!(units & (1 << i)))
594 continue;
595 if (dev_priv->chipset < 0xa0)
596 ustatus_addr = ustatus_old + (i << 12);
597 else
598 ustatus_addr = ustatus_new + (i << 11);
599 ustatus = nv_rd32(dev, ustatus_addr) & 0x7fffffff;
600 if (!ustatus)
601 continue;
602 tps++;
603 switch (type) {
604 case 6: /* texture error... unknown for now */
Ben Skeggs274fec92010-11-03 13:16:18 +1000605 if (display) {
606 NV_ERROR(dev, "magic set %d:\n", i);
607 for (r = ustatus_addr + 4; r <= ustatus_addr + 0x10; r += 4)
608 NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r,
609 nv_rd32(dev, r));
610 }
611 break;
612 case 7: /* MP error */
Maxim Levitskyc983e6f2011-10-09 22:58:32 +0200613 if (ustatus & 0x04030000) {
Ben Skeggs274fec92010-11-03 13:16:18 +1000614 nv50_pgraph_mp_trap(dev, i, display);
Maxim Levitskyc983e6f2011-10-09 22:58:32 +0200615 ustatus &= ~0x04030000;
Ben Skeggs274fec92010-11-03 13:16:18 +1000616 }
617 break;
618 case 8: /* TPDMA error */
619 {
620 uint32_t e0c = nv_rd32(dev, ustatus_addr + 4);
621 uint32_t e10 = nv_rd32(dev, ustatus_addr + 8);
622 uint32_t e14 = nv_rd32(dev, ustatus_addr + 0xc);
623 uint32_t e18 = nv_rd32(dev, ustatus_addr + 0x10);
624 uint32_t e1c = nv_rd32(dev, ustatus_addr + 0x14);
625 uint32_t e20 = nv_rd32(dev, ustatus_addr + 0x18);
626 uint32_t e24 = nv_rd32(dev, ustatus_addr + 0x1c);
Ben Skeggs274fec92010-11-03 13:16:18 +1000627 /* 2d engine destination */
628 if (ustatus & 0x00000010) {
629 if (display) {
630 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - Unknown fault at address %02x%08x\n",
631 i, e14, e10);
632 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
633 i, e0c, e18, e1c, e20, e24);
634 }
635 ustatus &= ~0x00000010;
636 }
637 /* Render target */
638 if (ustatus & 0x00000040) {
639 if (display) {
640 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - Unknown fault at address %02x%08x\n",
641 i, e14, e10);
642 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
643 i, e0c, e18, e1c, e20, e24);
644 }
645 ustatus &= ~0x00000040;
646 }
647 /* CUDA memory: l[], g[] or stack. */
648 if (ustatus & 0x00000080) {
649 if (display) {
650 if (e18 & 0x80000000) {
651 /* g[] read fault? */
652 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global read fault at address %02x%08x\n",
653 i, e14, e10 | ((e18 >> 24) & 0x1f));
654 e18 &= ~0x1f000000;
655 } else if (e18 & 0xc) {
656 /* g[] write fault? */
657 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global write fault at address %02x%08x\n",
658 i, e14, e10 | ((e18 >> 7) & 0x1f));
659 e18 &= ~0x00000f80;
660 } else {
661 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Unknown CUDA fault at address %02x%08x\n",
662 i, e14, e10);
663 }
664 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
665 i, e0c, e18, e1c, e20, e24);
666 }
667 ustatus &= ~0x00000080;
668 }
669 }
670 break;
671 }
672 if (ustatus) {
673 if (display)
674 NV_INFO(dev, "%s - TP%d: Unhandled ustatus 0x%08x\n", name, i, ustatus);
675 }
676 nv_wr32(dev, ustatus_addr, 0xc0000000);
677 }
678
679 if (!tps && display)
680 NV_INFO(dev, "%s - No TPs claiming errors?\n", name);
681}
682
683static int
684nv50_pgraph_trap_handler(struct drm_device *dev, u32 display, u64 inst, u32 chid)
685{
686 u32 status = nv_rd32(dev, 0x400108);
687 u32 ustatus;
688
689 if (!status && display) {
690 NV_INFO(dev, "PGRAPH - TRAP: no units reporting traps?\n");
691 return 1;
692 }
693
694 /* DISPATCH: Relays commands to other units and handles NOTIFY,
695 * COND, QUERY. If you get a trap from it, the command is still stuck
696 * in DISPATCH and you need to do something about it. */
697 if (status & 0x001) {
698 ustatus = nv_rd32(dev, 0x400804) & 0x7fffffff;
699 if (!ustatus && display) {
700 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - no ustatus?\n");
701 }
702
703 nv_wr32(dev, 0x400500, 0x00000000);
704
705 /* Known to be triggered by screwed up NOTIFY and COND... */
706 if (ustatus & 0x00000001) {
707 u32 addr = nv_rd32(dev, 0x400808);
708 u32 subc = (addr & 0x00070000) >> 16;
709 u32 mthd = (addr & 0x00001ffc);
710 u32 datal = nv_rd32(dev, 0x40080c);
711 u32 datah = nv_rd32(dev, 0x400810);
712 u32 class = nv_rd32(dev, 0x400814);
713 u32 r848 = nv_rd32(dev, 0x400848);
714
715 NV_INFO(dev, "PGRAPH - TRAP DISPATCH_FAULT\n");
716 if (display && (addr & 0x80000000)) {
717 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
718 "subc %d class 0x%04x mthd 0x%04x "
719 "data 0x%08x%08x "
720 "400808 0x%08x 400848 0x%08x\n",
721 chid, inst, subc, class, mthd, datah,
722 datal, addr, r848);
723 } else
724 if (display) {
725 NV_INFO(dev, "PGRAPH - no stuck command?\n");
726 }
727
728 nv_wr32(dev, 0x400808, 0);
729 nv_wr32(dev, 0x4008e8, nv_rd32(dev, 0x4008e8) & 3);
730 nv_wr32(dev, 0x400848, 0);
731 ustatus &= ~0x00000001;
732 }
733
734 if (ustatus & 0x00000002) {
735 u32 addr = nv_rd32(dev, 0x40084c);
736 u32 subc = (addr & 0x00070000) >> 16;
737 u32 mthd = (addr & 0x00001ffc);
738 u32 data = nv_rd32(dev, 0x40085c);
739 u32 class = nv_rd32(dev, 0x400814);
740
741 NV_INFO(dev, "PGRAPH - TRAP DISPATCH_QUERY\n");
742 if (display && (addr & 0x80000000)) {
743 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
744 "subc %d class 0x%04x mthd 0x%04x "
745 "data 0x%08x 40084c 0x%08x\n",
746 chid, inst, subc, class, mthd,
747 data, addr);
748 } else
749 if (display) {
750 NV_INFO(dev, "PGRAPH - no stuck command?\n");
751 }
752
753 nv_wr32(dev, 0x40084c, 0);
754 ustatus &= ~0x00000002;
755 }
756
757 if (ustatus && display) {
758 NV_INFO(dev, "PGRAPH - TRAP_DISPATCH (unknown "
759 "0x%08x)\n", ustatus);
760 }
761
762 nv_wr32(dev, 0x400804, 0xc0000000);
763 nv_wr32(dev, 0x400108, 0x001);
764 status &= ~0x001;
765 if (!status)
766 return 0;
767 }
768
769 /* M2MF: Memory to memory copy engine. */
770 if (status & 0x002) {
771 u32 ustatus = nv_rd32(dev, 0x406800) & 0x7fffffff;
772 if (display) {
773 NV_INFO(dev, "PGRAPH - TRAP_M2MF");
774 nouveau_bitfield_print(nv50_graph_trap_m2mf, ustatus);
775 printk("\n");
776 NV_INFO(dev, "PGRAPH - TRAP_M2MF %08x %08x %08x %08x\n",
777 nv_rd32(dev, 0x406804), nv_rd32(dev, 0x406808),
778 nv_rd32(dev, 0x40680c), nv_rd32(dev, 0x406810));
779
780 }
781
782 /* No sane way found yet -- just reset the bugger. */
783 nv_wr32(dev, 0x400040, 2);
784 nv_wr32(dev, 0x400040, 0);
785 nv_wr32(dev, 0x406800, 0xc0000000);
786 nv_wr32(dev, 0x400108, 0x002);
787 status &= ~0x002;
788 }
789
790 /* VFETCH: Fetches data from vertex buffers. */
791 if (status & 0x004) {
792 u32 ustatus = nv_rd32(dev, 0x400c04) & 0x7fffffff;
793 if (display) {
794 NV_INFO(dev, "PGRAPH - TRAP_VFETCH");
795 nouveau_bitfield_print(nv50_graph_trap_vfetch, ustatus);
796 printk("\n");
797 NV_INFO(dev, "PGRAPH - TRAP_VFETCH %08x %08x %08x %08x\n",
798 nv_rd32(dev, 0x400c00), nv_rd32(dev, 0x400c08),
799 nv_rd32(dev, 0x400c0c), nv_rd32(dev, 0x400c10));
800 }
801
802 nv_wr32(dev, 0x400c04, 0xc0000000);
803 nv_wr32(dev, 0x400108, 0x004);
804 status &= ~0x004;
805 }
806
807 /* STRMOUT: DirectX streamout / OpenGL transform feedback. */
808 if (status & 0x008) {
809 ustatus = nv_rd32(dev, 0x401800) & 0x7fffffff;
810 if (display) {
811 NV_INFO(dev, "PGRAPH - TRAP_STRMOUT");
812 nouveau_bitfield_print(nv50_graph_trap_strmout, ustatus);
813 printk("\n");
814 NV_INFO(dev, "PGRAPH - TRAP_STRMOUT %08x %08x %08x %08x\n",
815 nv_rd32(dev, 0x401804), nv_rd32(dev, 0x401808),
816 nv_rd32(dev, 0x40180c), nv_rd32(dev, 0x401810));
817
818 }
819
820 /* No sane way found yet -- just reset the bugger. */
821 nv_wr32(dev, 0x400040, 0x80);
822 nv_wr32(dev, 0x400040, 0);
823 nv_wr32(dev, 0x401800, 0xc0000000);
824 nv_wr32(dev, 0x400108, 0x008);
825 status &= ~0x008;
826 }
827
828 /* CCACHE: Handles code and c[] caches and fills them. */
829 if (status & 0x010) {
830 ustatus = nv_rd32(dev, 0x405018) & 0x7fffffff;
831 if (display) {
832 NV_INFO(dev, "PGRAPH - TRAP_CCACHE");
833 nouveau_bitfield_print(nv50_graph_trap_ccache, ustatus);
834 printk("\n");
835 NV_INFO(dev, "PGRAPH - TRAP_CCACHE %08x %08x %08x %08x"
836 " %08x %08x %08x\n",
Marcin Slusarz4dcf9052011-02-13 20:46:41 +0100837 nv_rd32(dev, 0x405000), nv_rd32(dev, 0x405004),
838 nv_rd32(dev, 0x405008), nv_rd32(dev, 0x40500c),
839 nv_rd32(dev, 0x405010), nv_rd32(dev, 0x405014),
840 nv_rd32(dev, 0x40501c));
Ben Skeggs274fec92010-11-03 13:16:18 +1000841
842 }
843
844 nv_wr32(dev, 0x405018, 0xc0000000);
845 nv_wr32(dev, 0x400108, 0x010);
846 status &= ~0x010;
847 }
848
849 /* Unknown, not seen yet... 0x402000 is the only trap status reg
850 * remaining, so try to handle it anyway. Perhaps related to that
851 * unknown DMA slot on tesla? */
852 if (status & 0x20) {
853 ustatus = nv_rd32(dev, 0x402000) & 0x7fffffff;
854 if (display)
855 NV_INFO(dev, "PGRAPH - TRAP_UNKC04 0x%08x\n", ustatus);
856 nv_wr32(dev, 0x402000, 0xc0000000);
857 /* no status modifiction on purpose */
858 }
859
860 /* TEXTURE: CUDA texturing units */
861 if (status & 0x040) {
862 nv50_pgraph_tp_trap(dev, 6, 0x408900, 0x408600, display,
863 "PGRAPH - TRAP_TEXTURE");
864 nv_wr32(dev, 0x400108, 0x040);
865 status &= ~0x040;
866 }
867
868 /* MP: CUDA execution engines. */
869 if (status & 0x080) {
870 nv50_pgraph_tp_trap(dev, 7, 0x408314, 0x40831c, display,
871 "PGRAPH - TRAP_MP");
872 nv_wr32(dev, 0x400108, 0x080);
873 status &= ~0x080;
874 }
875
876 /* TPDMA: Handles TP-initiated uncached memory accesses:
877 * l[], g[], stack, 2d surfaces, render targets. */
878 if (status & 0x100) {
879 nv50_pgraph_tp_trap(dev, 8, 0x408e08, 0x408708, display,
880 "PGRAPH - TRAP_TPDMA");
881 nv_wr32(dev, 0x400108, 0x100);
882 status &= ~0x100;
883 }
884
885 if (status) {
886 if (display)
887 NV_INFO(dev, "PGRAPH - TRAP: unknown 0x%08x\n", status);
888 nv_wr32(dev, 0x400108, status);
889 }
890
891 return 1;
892}
893
Ben Skeggs7ff54412011-03-18 10:25:59 +1000894int
Ben Skeggs274fec92010-11-03 13:16:18 +1000895nv50_graph_isr_chid(struct drm_device *dev, u64 inst)
896{
897 struct drm_nouveau_private *dev_priv = dev->dev_private;
898 struct nouveau_channel *chan;
899 unsigned long flags;
900 int i;
901
902 spin_lock_irqsave(&dev_priv->channels.lock, flags);
903 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
904 chan = dev_priv->channels.ptr[i];
905 if (!chan || !chan->ramin)
906 continue;
907
908 if (inst == chan->ramin->vinst)
909 break;
910 }
911 spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
912 return i;
913}
914
915static void
916nv50_graph_isr(struct drm_device *dev)
917{
918 u32 stat;
919
920 while ((stat = nv_rd32(dev, 0x400100))) {
921 u64 inst = (u64)(nv_rd32(dev, 0x40032c) & 0x0fffffff) << 12;
922 u32 chid = nv50_graph_isr_chid(dev, inst);
923 u32 addr = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR);
924 u32 subc = (addr & 0x00070000) >> 16;
925 u32 mthd = (addr & 0x00001ffc);
926 u32 data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA);
927 u32 class = nv_rd32(dev, 0x400814);
928 u32 show = stat;
929
930 if (stat & 0x00000010) {
931 if (!nouveau_gpuobj_mthd_call2(dev, chid, class,
932 mthd, data))
933 show &= ~0x00000010;
934 }
935
936 if (stat & 0x00001000) {
937 nv_wr32(dev, 0x400500, 0x00000000);
938 nv_wr32(dev, 0x400100, 0x00001000);
939 nv_mask(dev, 0x40013c, 0x00001000, 0x00000000);
940 nv50_graph_context_switch(dev);
941 stat &= ~0x00001000;
942 show &= ~0x00001000;
943 }
944
945 show = (show && nouveau_ratelimit()) ? show : 0;
946
947 if (show & 0x00100000) {
948 u32 ecode = nv_rd32(dev, 0x400110);
949 NV_INFO(dev, "PGRAPH - DATA_ERROR ");
950 nouveau_enum_print(nv50_data_error_names, ecode);
951 printk("\n");
952 }
953
954 if (stat & 0x00200000) {
955 if (!nv50_pgraph_trap_handler(dev, show, inst, chid))
956 show &= ~0x00200000;
957 }
958
959 nv_wr32(dev, 0x400100, stat);
960 nv_wr32(dev, 0x400500, 0x00010001);
961
962 if (show) {
963 NV_INFO(dev, "PGRAPH -");
964 nouveau_bitfield_print(nv50_graph_intr, show);
965 printk("\n");
966 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) subc %d "
967 "class 0x%04x mthd 0x%04x data 0x%08x\n",
968 chid, inst, subc, class, mthd, data);
Ben Skeggs6fdb3832011-03-08 09:57:17 +1000969 nv50_fb_vm_trap(dev, 1);
Ben Skeggs274fec92010-11-03 13:16:18 +1000970 }
971 }
972
973 if (nv_rd32(dev, 0x400824) & (1 << 31))
974 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) & ~(1 << 31));
975}
Ben Skeggs2703c212011-04-01 09:50:18 +1000976
977static void
978nv50_graph_destroy(struct drm_device *dev, int engine)
979{
980 struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
981
982 NVOBJ_ENGINE_DEL(dev, GR);
983
984 nouveau_irq_unregister(dev, 12);
985 kfree(pgraph);
986}
987
988int
989nv50_graph_create(struct drm_device *dev)
990{
991 struct drm_nouveau_private *dev_priv = dev->dev_private;
992 struct nv50_graph_engine *pgraph;
Ben Skeggs2703c212011-04-01 09:50:18 +1000993 int ret;
994
995 pgraph = kzalloc(sizeof(*pgraph),GFP_KERNEL);
996 if (!pgraph)
997 return -ENOMEM;
998
Ben Skeggsd58086d2012-04-20 11:54:33 +1000999 ret = nv50_grctx_init(dev, pgraph->ctxprog, ARRAY_SIZE(pgraph->ctxprog),
1000 &pgraph->ctxprog_size,
1001 &pgraph->grctx_size);
Ben Skeggs2703c212011-04-01 09:50:18 +10001002 if (ret) {
1003 NV_ERROR(dev, "PGRAPH: ctxprog build failed\n");
Ben Skeggs2703c212011-04-01 09:50:18 +10001004 kfree(pgraph);
1005 return 0;
1006 }
1007
Ben Skeggs2703c212011-04-01 09:50:18 +10001008 pgraph->base.destroy = nv50_graph_destroy;
1009 pgraph->base.init = nv50_graph_init;
1010 pgraph->base.fini = nv50_graph_fini;
1011 pgraph->base.context_new = nv50_graph_context_new;
1012 pgraph->base.context_del = nv50_graph_context_del;
1013 pgraph->base.object_new = nv50_graph_object_new;
1014 if (dev_priv->chipset == 0x50 || dev_priv->chipset == 0xac)
1015 pgraph->base.tlb_flush = nv50_graph_tlb_flush;
1016 else
1017 pgraph->base.tlb_flush = nv84_graph_tlb_flush;
1018
1019 nouveau_irq_register(dev, 12, nv50_graph_isr);
1020
1021 /* NVSW really doesn't live here... */
1022 NVOBJ_CLASS(dev, 0x506e, SW); /* nvsw */
1023 NVOBJ_MTHD (dev, 0x506e, 0x018c, nv50_graph_nvsw_dma_vblsem);
1024 NVOBJ_MTHD (dev, 0x506e, 0x0400, nv50_graph_nvsw_vblsem_offset);
1025 NVOBJ_MTHD (dev, 0x506e, 0x0404, nv50_graph_nvsw_vblsem_release_val);
1026 NVOBJ_MTHD (dev, 0x506e, 0x0408, nv50_graph_nvsw_vblsem_release);
1027 NVOBJ_MTHD (dev, 0x506e, 0x0500, nv50_graph_nvsw_mthd_page_flip);
1028
1029 NVOBJ_ENGINE_ADD(dev, GR, &pgraph->base);
1030 NVOBJ_CLASS(dev, 0x0030, GR); /* null */
1031 NVOBJ_CLASS(dev, 0x5039, GR); /* m2mf */
1032 NVOBJ_CLASS(dev, 0x502d, GR); /* 2d */
1033
1034 /* tesla */
1035 if (dev_priv->chipset == 0x50)
1036 NVOBJ_CLASS(dev, 0x5097, GR); /* tesla (nv50) */
1037 else
1038 if (dev_priv->chipset < 0xa0)
1039 NVOBJ_CLASS(dev, 0x8297, GR); /* tesla (nv8x/nv9x) */
1040 else {
1041 switch (dev_priv->chipset) {
1042 case 0xa0:
1043 case 0xaa:
1044 case 0xac:
1045 NVOBJ_CLASS(dev, 0x8397, GR);
1046 break;
1047 case 0xa3:
1048 case 0xa5:
1049 case 0xa8:
1050 NVOBJ_CLASS(dev, 0x8597, GR);
1051 break;
1052 case 0xaf:
1053 NVOBJ_CLASS(dev, 0x8697, GR);
1054 break;
1055 }
1056 }
1057
1058 /* compute */
1059 NVOBJ_CLASS(dev, 0x50c0, GR);
1060 if (dev_priv->chipset > 0xa0 &&
1061 dev_priv->chipset != 0xaa &&
1062 dev_priv->chipset != 0xac)
1063 NVOBJ_CLASS(dev, 0x85c0, GR);
1064
1065 return 0;
1066}