blob: bffa486ec7ce00de48c0ff5029e5a19049a561df [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"
Ben Skeggs4ea52f82011-03-31 13:44:16 +100034#include "nouveau_ramht.h"
Francisco Jerez332b2422010-10-20 23:35:40 +020035#include "nv50_evo.h"
Ben Skeggs6ee73862009-12-11 19:24:15 +100036
Ben Skeggs2703c212011-04-01 09:50:18 +100037struct nv50_graph_engine {
38 struct nouveau_exec_engine base;
39 u32 ctxprog[512];
40 u32 ctxprog_size;
41 u32 grctx_size;
42};
43
44static void
45nv50_graph_fifo_access(struct drm_device *dev, bool enabled)
46{
47 const uint32_t mask = 0x00010001;
48
49 if (enabled)
50 nv_wr32(dev, 0x400500, nv_rd32(dev, 0x400500) | mask);
51 else
52 nv_wr32(dev, 0x400500, nv_rd32(dev, 0x400500) & ~mask);
53}
54
55static struct nouveau_channel *
56nv50_graph_channel(struct drm_device *dev)
57{
58 struct drm_nouveau_private *dev_priv = dev->dev_private;
59 uint32_t inst;
60 int i;
61
62 /* Be sure we're not in the middle of a context switch or bad things
63 * will happen, such as unloading the wrong pgraph context.
64 */
65 if (!nv_wait(dev, 0x400300, 0x00000001, 0x00000000))
66 NV_ERROR(dev, "Ctxprog is still running\n");
67
68 inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_CUR);
69 if (!(inst & NV50_PGRAPH_CTXCTL_CUR_LOADED))
70 return NULL;
71 inst = (inst & NV50_PGRAPH_CTXCTL_CUR_INSTANCE) << 12;
72
73 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
74 struct nouveau_channel *chan = dev_priv->channels.ptr[i];
75
76 if (chan && chan->ramin && chan->ramin->vinst == inst)
77 return chan;
78 }
79
80 return NULL;
81}
82
83static int
84nv50_graph_do_load_context(struct drm_device *dev, uint32_t inst)
85{
86 uint32_t fifo = nv_rd32(dev, 0x400500);
87
88 nv_wr32(dev, 0x400500, fifo & ~1);
89 nv_wr32(dev, 0x400784, inst);
90 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) | 0x40);
91 nv_wr32(dev, 0x400320, nv_rd32(dev, 0x400320) | 0x11);
92 nv_wr32(dev, 0x400040, 0xffffffff);
93 (void)nv_rd32(dev, 0x400040);
94 nv_wr32(dev, 0x400040, 0x00000000);
95 nv_wr32(dev, 0x400304, nv_rd32(dev, 0x400304) | 1);
96
97 if (nouveau_wait_for_idle(dev))
98 nv_wr32(dev, 0x40032c, inst | (1<<31));
99 nv_wr32(dev, 0x400500, fifo);
100
101 return 0;
102}
103
104static int
105nv50_graph_unload_context(struct drm_device *dev)
106{
107 uint32_t inst;
108
109 inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_CUR);
110 if (!(inst & NV50_PGRAPH_CTXCTL_CUR_LOADED))
111 return 0;
112 inst &= NV50_PGRAPH_CTXCTL_CUR_INSTANCE;
113
114 nouveau_wait_for_idle(dev);
115 nv_wr32(dev, 0x400784, inst);
116 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) | 0x20);
117 nv_wr32(dev, 0x400304, nv_rd32(dev, 0x400304) | 0x01);
118 nouveau_wait_for_idle(dev);
119
120 nv_wr32(dev, NV50_PGRAPH_CTXCTL_CUR, inst);
121 return 0;
122}
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000123
Ben Skeggs6ee73862009-12-11 19:24:15 +1000124static void
125nv50_graph_init_reset(struct drm_device *dev)
126{
127 uint32_t pmc_e = NV_PMC_ENABLE_PGRAPH | (1 << 21);
128
129 NV_DEBUG(dev, "\n");
130
131 nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) & ~pmc_e);
132 nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) | pmc_e);
133}
134
135static void
136nv50_graph_init_intr(struct drm_device *dev)
137{
138 NV_DEBUG(dev, "\n");
139
140 nv_wr32(dev, NV03_PGRAPH_INTR, 0xffffffff);
141 nv_wr32(dev, 0x400138, 0xffffffff);
142 nv_wr32(dev, NV40_PGRAPH_INTR_EN, 0xffffffff);
143}
144
145static void
146nv50_graph_init_regs__nv(struct drm_device *dev)
147{
Marcin Koƛcielnicki304424e2010-03-01 00:18:39 +0000148 struct drm_nouveau_private *dev_priv = dev->dev_private;
149 uint32_t units = nv_rd32(dev, 0x1540);
150 int i;
151
Ben Skeggs6ee73862009-12-11 19:24:15 +1000152 NV_DEBUG(dev, "\n");
153
154 nv_wr32(dev, 0x400804, 0xc0000000);
155 nv_wr32(dev, 0x406800, 0xc0000000);
156 nv_wr32(dev, 0x400c04, 0xc0000000);
Marcin Koƛcielnicki716abaa2010-01-12 18:21:56 +0000157 nv_wr32(dev, 0x401800, 0xc0000000);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000158 nv_wr32(dev, 0x405018, 0xc0000000);
159 nv_wr32(dev, 0x402000, 0xc0000000);
160
Marcin Koƛcielnicki304424e2010-03-01 00:18:39 +0000161 for (i = 0; i < 16; i++) {
162 if (units & 1 << i) {
163 if (dev_priv->chipset < 0xa0) {
164 nv_wr32(dev, 0x408900 + (i << 12), 0xc0000000);
165 nv_wr32(dev, 0x408e08 + (i << 12), 0xc0000000);
166 nv_wr32(dev, 0x408314 + (i << 12), 0xc0000000);
167 } else {
168 nv_wr32(dev, 0x408600 + (i << 11), 0xc0000000);
169 nv_wr32(dev, 0x408708 + (i << 11), 0xc0000000);
170 nv_wr32(dev, 0x40831c + (i << 11), 0xc0000000);
171 }
172 }
173 }
174
Ben Skeggs6ee73862009-12-11 19:24:15 +1000175 nv_wr32(dev, 0x400108, 0xffffffff);
176
177 nv_wr32(dev, 0x400824, 0x00004000);
178 nv_wr32(dev, 0x400500, 0x00010001);
179}
180
181static void
Ben Skeggs562af102011-02-23 09:00:35 +1000182nv50_graph_init_zcull(struct drm_device *dev)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000183{
Ben Skeggs562af102011-02-23 09:00:35 +1000184 struct drm_nouveau_private *dev_priv = dev->dev_private;
185 int i;
186
Ben Skeggs6ee73862009-12-11 19:24:15 +1000187 NV_DEBUG(dev, "\n");
188
Ben Skeggs562af102011-02-23 09:00:35 +1000189 switch (dev_priv->chipset & 0xf0) {
190 case 0x50:
191 case 0x80:
192 case 0x90:
193 nv_wr32(dev, 0x402ca8, 0x00000800);
194 break;
195 case 0xa0:
196 default:
197 nv_wr32(dev, 0x402cc0, 0x00000000);
198 if (dev_priv->chipset == 0xa0 ||
199 dev_priv->chipset == 0xaa ||
200 dev_priv->chipset == 0xac) {
201 nv_wr32(dev, 0x402ca8, 0x00000802);
202 } else {
203 nv_wr32(dev, 0x402cc0, 0x00000000);
204 nv_wr32(dev, 0x402ca8, 0x00000002);
205 }
206
207 break;
208 }
209
210 /* zero out zcull regions */
211 for (i = 0; i < 8; i++) {
212 nv_wr32(dev, 0x402c20 + (i * 8), 0x00000000);
213 nv_wr32(dev, 0x402c24 + (i * 8), 0x00000000);
214 nv_wr32(dev, 0x402c28 + (i * 8), 0x00000000);
215 nv_wr32(dev, 0x402c2c + (i * 8), 0x00000000);
216 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000217}
218
219static int
220nv50_graph_init_ctxctl(struct drm_device *dev)
221{
Ben Skeggs2703c212011-04-01 09:50:18 +1000222 struct nv50_graph_engine *pgraph = nv_engine(dev, NVOBJ_ENGINE_GR);
Ben Skeggsec91db22010-07-08 11:53:19 +1000223 int i;
Ben Skeggs054b93e2009-12-15 22:02:47 +1000224
Ben Skeggs6ee73862009-12-11 19:24:15 +1000225 NV_DEBUG(dev, "\n");
226
Ben Skeggs2703c212011-04-01 09:50:18 +1000227 nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0);
228 for (i = 0; i < pgraph->ctxprog_size; i++)
229 nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_DATA, pgraph->ctxprog[i]);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000230
Ben Skeggs562af102011-02-23 09:00:35 +1000231 nv_wr32(dev, 0x40008c, 0x00000004); /* HW_CTX_SWITCH_ENABLED */
Ben Skeggs6ee73862009-12-11 19:24:15 +1000232 nv_wr32(dev, 0x400320, 4);
233 nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, 0);
234 nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, 0);
235 return 0;
236}
237
Ben Skeggs2703c212011-04-01 09:50:18 +1000238static int
239nv50_graph_init(struct drm_device *dev, int engine)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000240{
241 int ret;
242
243 NV_DEBUG(dev, "\n");
244
245 nv50_graph_init_reset(dev);
246 nv50_graph_init_regs__nv(dev);
Ben Skeggs562af102011-02-23 09:00:35 +1000247 nv50_graph_init_zcull(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000248
249 ret = nv50_graph_init_ctxctl(dev);
250 if (ret)
251 return ret;
252
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000253 nv50_graph_init_intr(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000254 return 0;
255}
256
Ben Skeggs2703c212011-04-01 09:50:18 +1000257static int
258nv50_graph_fini(struct drm_device *dev, int engine)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000259{
260 NV_DEBUG(dev, "\n");
Ben Skeggs2703c212011-04-01 09:50:18 +1000261 nv50_graph_unload_context(dev);
Ben Skeggs274fec92010-11-03 13:16:18 +1000262 nv_wr32(dev, 0x40013c, 0x00000000);
Ben Skeggs2703c212011-04-01 09:50:18 +1000263 return 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000264}
265
Ben Skeggs2703c212011-04-01 09:50:18 +1000266static int
267nv50_graph_context_new(struct nouveau_channel *chan, int engine)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000268{
269 struct drm_device *dev = chan->dev;
270 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000271 struct nouveau_gpuobj *ramin = chan->ramin;
Ben Skeggs2703c212011-04-01 09:50:18 +1000272 struct nouveau_gpuobj *grctx = NULL;
273 struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
Ben Skeggsec91db22010-07-08 11:53:19 +1000274 struct nouveau_grctx ctx = {};
Ben Skeggs6ee73862009-12-11 19:24:15 +1000275 int hdr, ret;
276
277 NV_DEBUG(dev, "ch%d\n", chan->id);
278
Ben Skeggs2703c212011-04-01 09:50:18 +1000279 ret = nouveau_gpuobj_new(dev, NULL, pgraph->grctx_size, 0,
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000280 NVOBJ_FLAG_ZERO_ALLOC |
Ben Skeggs2703c212011-04-01 09:50:18 +1000281 NVOBJ_FLAG_ZERO_FREE, &grctx);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000282 if (ret)
283 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000284
Ben Skeggsac94a342010-07-08 15:28:48 +1000285 hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
Ben Skeggsb3beb162010-09-01 15:24:29 +1000286 nv_wo32(ramin, hdr + 0x00, 0x00190002);
Ben Skeggs2703c212011-04-01 09:50:18 +1000287 nv_wo32(ramin, hdr + 0x04, grctx->vinst + grctx->size - 1);
288 nv_wo32(ramin, hdr + 0x08, grctx->vinst);
Ben Skeggsb3beb162010-09-01 15:24:29 +1000289 nv_wo32(ramin, hdr + 0x0c, 0);
290 nv_wo32(ramin, hdr + 0x10, 0);
291 nv_wo32(ramin, hdr + 0x14, 0x00010000);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000292
Ben Skeggsec91db22010-07-08 11:53:19 +1000293 ctx.dev = chan->dev;
294 ctx.mode = NOUVEAU_GRCTX_VALS;
Ben Skeggs2703c212011-04-01 09:50:18 +1000295 ctx.data = grctx;
Ben Skeggsec91db22010-07-08 11:53:19 +1000296 nv50_grctx_init(&ctx);
297
Ben Skeggs2703c212011-04-01 09:50:18 +1000298 nv_wo32(grctx, 0x00000, chan->ramin->vinst >> 12);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000299
Ben Skeggsf56cb862010-07-08 11:29:10 +1000300 dev_priv->engine.instmem.flush(dev);
Ben Skeggs2703c212011-04-01 09:50:18 +1000301
302 atomic_inc(&chan->vm->engref[NVOBJ_ENGINE_GR]);
303 chan->engctx[NVOBJ_ENGINE_GR] = grctx;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000304 return 0;
305}
306
Ben Skeggs2703c212011-04-01 09:50:18 +1000307static void
308nv50_graph_context_del(struct nouveau_channel *chan, int engine)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000309{
Ben Skeggs2703c212011-04-01 09:50:18 +1000310 struct nouveau_gpuobj *grctx = chan->engctx[engine];
Ben Skeggs6ee73862009-12-11 19:24:15 +1000311 struct drm_device *dev = chan->dev;
312 struct drm_nouveau_private *dev_priv = dev->dev_private;
Francisco Jerez34311c72011-01-24 01:47:42 +0100313 struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
Ben Skeggsac94a342010-07-08 15:28:48 +1000314 int i, hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
Francisco Jerez3945e472010-10-18 03:53:39 +0200315 unsigned long flags;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000316
317 NV_DEBUG(dev, "ch%d\n", chan->id);
318
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000319 if (!chan->ramin)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000320 return;
321
Francisco Jerez3945e472010-10-18 03:53:39 +0200322 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
Francisco Jerez34311c72011-01-24 01:47:42 +0100323 pfifo->reassign(dev, false);
Ben Skeggs2703c212011-04-01 09:50:18 +1000324 nv50_graph_fifo_access(dev, false);
Francisco Jerez3945e472010-10-18 03:53:39 +0200325
Ben Skeggs2703c212011-04-01 09:50:18 +1000326 if (nv50_graph_channel(dev) == chan)
327 nv50_graph_unload_context(dev);
Francisco Jerez3945e472010-10-18 03:53:39 +0200328
Ben Skeggs6ee73862009-12-11 19:24:15 +1000329 for (i = hdr; i < hdr + 24; i += 4)
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000330 nv_wo32(chan->ramin, i, 0);
Ben Skeggsf56cb862010-07-08 11:29:10 +1000331 dev_priv->engine.instmem.flush(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000332
Ben Skeggs2703c212011-04-01 09:50:18 +1000333 nv50_graph_fifo_access(dev, true);
Francisco Jerez34311c72011-01-24 01:47:42 +0100334 pfifo->reassign(dev, true);
Francisco Jerez3945e472010-10-18 03:53:39 +0200335 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
336
Ben Skeggs2703c212011-04-01 09:50:18 +1000337 nouveau_gpuobj_ref(NULL, &grctx);
Ben Skeggs4c1361422010-11-15 11:54:21 +1000338
Ben Skeggs2703c212011-04-01 09:50:18 +1000339 atomic_dec(&chan->vm->engref[engine]);
340 chan->engctx[engine] = NULL;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000341}
342
343static int
Ben Skeggs2703c212011-04-01 09:50:18 +1000344nv50_graph_object_new(struct nouveau_channel *chan, int engine,
345 u32 handle, u16 class)
Ben Skeggs4ea52f82011-03-31 13:44:16 +1000346{
347 struct drm_device *dev = chan->dev;
348 struct drm_nouveau_private *dev_priv = dev->dev_private;
349 struct nouveau_gpuobj *obj = NULL;
350 int ret;
351
352 ret = nouveau_gpuobj_new(dev, chan, 16, 16, NVOBJ_FLAG_ZERO_FREE, &obj);
353 if (ret)
354 return ret;
355 obj->engine = 1;
356 obj->class = class;
357
358 nv_wo32(obj, 0x00, class);
359 nv_wo32(obj, 0x04, 0x00000000);
360 nv_wo32(obj, 0x08, 0x00000000);
361 nv_wo32(obj, 0x0c, 0x00000000);
362 dev_priv->engine.instmem.flush(dev);
363
364 ret = nouveau_ramht_insert(chan, handle, obj);
365 nouveau_gpuobj_ref(NULL, &obj);
366 return ret;
367}
368
Ben Skeggs274fec92010-11-03 13:16:18 +1000369static void
Ben Skeggs6ee73862009-12-11 19:24:15 +1000370nv50_graph_context_switch(struct drm_device *dev)
371{
372 uint32_t inst;
373
374 nv50_graph_unload_context(dev);
375
376 inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_NEXT);
377 inst &= NV50_PGRAPH_CTXCTL_NEXT_INSTANCE;
378 nv50_graph_do_load_context(dev, inst);
379
380 nv_wr32(dev, NV40_PGRAPH_INTR_EN, nv_rd32(dev,
381 NV40_PGRAPH_INTR_EN) | NV_PGRAPH_INTR_CONTEXT_SWITCH);
382}
383
384static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000385nv50_graph_nvsw_dma_vblsem(struct nouveau_channel *chan,
386 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000387{
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000388 struct nouveau_gpuobj *gpuobj;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000389
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000390 gpuobj = nouveau_ramht_find(chan, data);
391 if (!gpuobj)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000392 return -ENOENT;
393
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000394 if (nouveau_notifier_offset(gpuobj, NULL))
Ben Skeggs6ee73862009-12-11 19:24:15 +1000395 return -EINVAL;
396
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000397 chan->nvsw.vblsem = gpuobj;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000398 chan->nvsw.vblsem_offset = ~0;
399 return 0;
400}
401
402static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000403nv50_graph_nvsw_vblsem_offset(struct nouveau_channel *chan,
404 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000405{
406 if (nouveau_notifier_offset(chan->nvsw.vblsem, &data))
407 return -ERANGE;
408
409 chan->nvsw.vblsem_offset = data >> 2;
410 return 0;
411}
412
413static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000414nv50_graph_nvsw_vblsem_release_val(struct nouveau_channel *chan,
415 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000416{
417 chan->nvsw.vblsem_rval = data;
418 return 0;
419}
420
421static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000422nv50_graph_nvsw_vblsem_release(struct nouveau_channel *chan,
423 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000424{
425 struct drm_device *dev = chan->dev;
426 struct drm_nouveau_private *dev_priv = dev->dev_private;
427
428 if (!chan->nvsw.vblsem || chan->nvsw.vblsem_offset == ~0 || data > 1)
429 return -EINVAL;
430
Francisco Jerez042206c2010-10-21 18:19:29 +0200431 drm_vblank_get(dev, data);
Francisco Jerez1f6d2de2010-10-24 14:15:58 +0200432
433 chan->nvsw.vblsem_head = data;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000434 list_add(&chan->nvsw.vbl_wait, &dev_priv->vbl_waiting);
Francisco Jerez1f6d2de2010-10-24 14:15:58 +0200435
Ben Skeggs6ee73862009-12-11 19:24:15 +1000436 return 0;
437}
438
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000439static int
Francisco Jerez332b2422010-10-20 23:35:40 +0200440nv50_graph_nvsw_mthd_page_flip(struct nouveau_channel *chan,
441 u32 class, u32 mthd, u32 data)
442{
Ben Skeggsd7117e02011-02-07 14:27:04 +1000443 nouveau_finish_page_flip(chan, NULL);
Francisco Jerez332b2422010-10-20 23:35:40 +0200444 return 0;
445}
446
Ben Skeggs6ee73862009-12-11 19:24:15 +1000447
Ben Skeggs2703c212011-04-01 09:50:18 +1000448static void
449nv50_graph_tlb_flush(struct drm_device *dev, int engine)
Ben Skeggs56ac7472010-10-22 10:26:24 +1000450{
Ben Skeggsa11c3192010-08-27 10:00:25 +1000451 nv50_vm_flush_engine(dev, 0);
Ben Skeggs56ac7472010-10-22 10:26:24 +1000452}
453
Ben Skeggs2703c212011-04-01 09:50:18 +1000454static void
455nv84_graph_tlb_flush(struct drm_device *dev, int engine)
Ben Skeggs56ac7472010-10-22 10:26:24 +1000456{
457 struct drm_nouveau_private *dev_priv = dev->dev_private;
458 struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer;
459 bool idle, timeout = false;
460 unsigned long flags;
461 u64 start;
462 u32 tmp;
463
464 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
465 nv_mask(dev, 0x400500, 0x00000001, 0x00000000);
466
467 start = ptimer->read(dev);
468 do {
469 idle = true;
470
471 for (tmp = nv_rd32(dev, 0x400380); tmp && idle; tmp >>= 3) {
472 if ((tmp & 7) == 1)
473 idle = false;
474 }
475
476 for (tmp = nv_rd32(dev, 0x400384); tmp && idle; tmp >>= 3) {
477 if ((tmp & 7) == 1)
478 idle = false;
479 }
480
481 for (tmp = nv_rd32(dev, 0x400388); tmp && idle; tmp >>= 3) {
482 if ((tmp & 7) == 1)
483 idle = false;
484 }
485 } while (!idle && !(timeout = ptimer->read(dev) - start > 2000000000));
486
487 if (timeout) {
488 NV_ERROR(dev, "PGRAPH TLB flush idle timeout fail: "
489 "0x%08x 0x%08x 0x%08x 0x%08x\n",
490 nv_rd32(dev, 0x400700), nv_rd32(dev, 0x400380),
491 nv_rd32(dev, 0x400384), nv_rd32(dev, 0x400388));
492 }
493
Ben Skeggsa11c3192010-08-27 10:00:25 +1000494 nv50_vm_flush_engine(dev, 0);
Ben Skeggs56ac7472010-10-22 10:26:24 +1000495
496 nv_mask(dev, 0x400500, 0x00000001, 0x00000001);
497 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
498}
Ben Skeggs274fec92010-11-03 13:16:18 +1000499
Emil Velikovf9ec8f62011-03-19 23:31:53 +0000500static struct nouveau_enum nv50_mp_exec_error_names[] = {
Ben Skeggsbb9b18a2011-03-08 08:39:43 +1000501 { 3, "STACK_UNDERFLOW", NULL },
502 { 4, "QUADON_ACTIVE", NULL },
503 { 8, "TIMEOUT", NULL },
504 { 0x10, "INVALID_OPCODE", NULL },
505 { 0x40, "BREAKPOINT", NULL },
Ben Skeggs274fec92010-11-03 13:16:18 +1000506 {}
507};
508
509static struct nouveau_bitfield nv50_graph_trap_m2mf[] = {
510 { 0x00000001, "NOTIFY" },
511 { 0x00000002, "IN" },
512 { 0x00000004, "OUT" },
513 {}
514};
515
516static struct nouveau_bitfield nv50_graph_trap_vfetch[] = {
517 { 0x00000001, "FAULT" },
518 {}
519};
520
521static struct nouveau_bitfield nv50_graph_trap_strmout[] = {
522 { 0x00000001, "FAULT" },
523 {}
524};
525
526static struct nouveau_bitfield nv50_graph_trap_ccache[] = {
527 { 0x00000001, "FAULT" },
528 {}
529};
530
531/* There must be a *lot* of these. Will take some time to gather them up. */
Ben Skeggs6effe392010-12-30 11:48:03 +1000532struct nouveau_enum nv50_data_error_names[] = {
Ben Skeggsbb9b18a2011-03-08 08:39:43 +1000533 { 0x00000003, "INVALID_QUERY_OR_TEXTURE", NULL },
534 { 0x00000004, "INVALID_VALUE", NULL },
535 { 0x00000005, "INVALID_ENUM", NULL },
536 { 0x00000008, "INVALID_OBJECT", NULL },
537 { 0x00000009, "READ_ONLY_OBJECT", NULL },
538 { 0x0000000a, "SUPERVISOR_OBJECT", NULL },
539 { 0x0000000b, "INVALID_ADDRESS_ALIGNMENT", NULL },
540 { 0x0000000c, "INVALID_BITFIELD", NULL },
541 { 0x0000000d, "BEGIN_END_ACTIVE", NULL },
542 { 0x0000000e, "SEMANTIC_COLOR_BACK_OVER_LIMIT", NULL },
543 { 0x0000000f, "VIEWPORT_ID_NEEDS_GP", NULL },
544 { 0x00000010, "RT_DOUBLE_BIND", NULL },
545 { 0x00000011, "RT_TYPES_MISMATCH", NULL },
546 { 0x00000012, "RT_LINEAR_WITH_ZETA", NULL },
547 { 0x00000015, "FP_TOO_FEW_REGS", NULL },
548 { 0x00000016, "ZETA_FORMAT_CSAA_MISMATCH", NULL },
549 { 0x00000017, "RT_LINEAR_WITH_MSAA", NULL },
550 { 0x00000018, "FP_INTERPOLANT_START_OVER_LIMIT", NULL },
551 { 0x00000019, "SEMANTIC_LAYER_OVER_LIMIT", NULL },
552 { 0x0000001a, "RT_INVALID_ALIGNMENT", NULL },
553 { 0x0000001b, "SAMPLER_OVER_LIMIT", NULL },
554 { 0x0000001c, "TEXTURE_OVER_LIMIT", NULL },
555 { 0x0000001e, "GP_TOO_MANY_OUTPUTS", NULL },
556 { 0x0000001f, "RT_BPP128_WITH_MS8", NULL },
557 { 0x00000021, "Z_OUT_OF_BOUNDS", NULL },
558 { 0x00000023, "XY_OUT_OF_BOUNDS", NULL },
559 { 0x00000027, "CP_MORE_PARAMS_THAN_SHARED", NULL },
560 { 0x00000028, "CP_NO_REG_SPACE_STRIPED", NULL },
561 { 0x00000029, "CP_NO_REG_SPACE_PACKED", NULL },
562 { 0x0000002a, "CP_NOT_ENOUGH_WARPS", NULL },
563 { 0x0000002b, "CP_BLOCK_SIZE_MISMATCH", NULL },
564 { 0x0000002c, "CP_NOT_ENOUGH_LOCAL_WARPS", NULL },
565 { 0x0000002d, "CP_NOT_ENOUGH_STACK_WARPS", NULL },
566 { 0x0000002e, "CP_NO_BLOCKDIM_LATCH", NULL },
567 { 0x00000031, "ENG2D_FORMAT_MISMATCH", NULL },
568 { 0x0000003f, "PRIMITIVE_ID_NEEDS_GP", NULL },
569 { 0x00000044, "SEMANTIC_VIEWPORT_OVER_LIMIT", NULL },
570 { 0x00000045, "SEMANTIC_COLOR_FRONT_OVER_LIMIT", NULL },
571 { 0x00000046, "LAYER_ID_NEEDS_GP", NULL },
572 { 0x00000047, "SEMANTIC_CLIP_OVER_LIMIT", NULL },
573 { 0x00000048, "SEMANTIC_PTSZ_OVER_LIMIT", NULL },
Ben Skeggs274fec92010-11-03 13:16:18 +1000574 {}
575};
576
577static struct nouveau_bitfield nv50_graph_intr[] = {
578 { 0x00000001, "NOTIFY" },
579 { 0x00000002, "COMPUTE_QUERY" },
580 { 0x00000010, "ILLEGAL_MTHD" },
581 { 0x00000020, "ILLEGAL_CLASS" },
582 { 0x00000040, "DOUBLE_NOTIFY" },
583 { 0x00001000, "CONTEXT_SWITCH" },
584 { 0x00010000, "BUFFER_NOTIFY" },
585 { 0x00100000, "DATA_ERROR" },
586 { 0x00200000, "TRAP" },
587 { 0x01000000, "SINGLE_STEP" },
588 {}
589};
590
591static void
592nv50_pgraph_mp_trap(struct drm_device *dev, int tpid, int display)
593{
594 struct drm_nouveau_private *dev_priv = dev->dev_private;
595 uint32_t units = nv_rd32(dev, 0x1540);
596 uint32_t addr, mp10, status, pc, oplow, ophigh;
597 int i;
598 int mps = 0;
599 for (i = 0; i < 4; i++) {
600 if (!(units & 1 << (i+24)))
601 continue;
602 if (dev_priv->chipset < 0xa0)
603 addr = 0x408200 + (tpid << 12) + (i << 7);
604 else
605 addr = 0x408100 + (tpid << 11) + (i << 7);
606 mp10 = nv_rd32(dev, addr + 0x10);
607 status = nv_rd32(dev, addr + 0x14);
608 if (!status)
609 continue;
610 if (display) {
611 nv_rd32(dev, addr + 0x20);
612 pc = nv_rd32(dev, addr + 0x24);
613 oplow = nv_rd32(dev, addr + 0x70);
Emil Velikov0b89a072011-03-19 23:31:54 +0000614 ophigh = nv_rd32(dev, addr + 0x74);
Ben Skeggs274fec92010-11-03 13:16:18 +1000615 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - "
616 "TP %d MP %d: ", tpid, i);
617 nouveau_enum_print(nv50_mp_exec_error_names, status);
618 printk(" at %06x warp %d, opcode %08x %08x\n",
619 pc&0xffffff, pc >> 24,
620 oplow, ophigh);
621 }
622 nv_wr32(dev, addr + 0x10, mp10);
623 nv_wr32(dev, addr + 0x14, 0);
624 mps++;
625 }
626 if (!mps && display)
627 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - TP %d: "
628 "No MPs claiming errors?\n", tpid);
629}
630
631static void
632nv50_pgraph_tp_trap(struct drm_device *dev, int type, uint32_t ustatus_old,
633 uint32_t ustatus_new, int display, const char *name)
634{
635 struct drm_nouveau_private *dev_priv = dev->dev_private;
636 int tps = 0;
637 uint32_t units = nv_rd32(dev, 0x1540);
638 int i, r;
639 uint32_t ustatus_addr, ustatus;
640 for (i = 0; i < 16; i++) {
641 if (!(units & (1 << i)))
642 continue;
643 if (dev_priv->chipset < 0xa0)
644 ustatus_addr = ustatus_old + (i << 12);
645 else
646 ustatus_addr = ustatus_new + (i << 11);
647 ustatus = nv_rd32(dev, ustatus_addr) & 0x7fffffff;
648 if (!ustatus)
649 continue;
650 tps++;
651 switch (type) {
652 case 6: /* texture error... unknown for now */
Ben Skeggs274fec92010-11-03 13:16:18 +1000653 if (display) {
654 NV_ERROR(dev, "magic set %d:\n", i);
655 for (r = ustatus_addr + 4; r <= ustatus_addr + 0x10; r += 4)
656 NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r,
657 nv_rd32(dev, r));
658 }
659 break;
660 case 7: /* MP error */
661 if (ustatus & 0x00010000) {
662 nv50_pgraph_mp_trap(dev, i, display);
663 ustatus &= ~0x00010000;
664 }
665 break;
666 case 8: /* TPDMA error */
667 {
668 uint32_t e0c = nv_rd32(dev, ustatus_addr + 4);
669 uint32_t e10 = nv_rd32(dev, ustatus_addr + 8);
670 uint32_t e14 = nv_rd32(dev, ustatus_addr + 0xc);
671 uint32_t e18 = nv_rd32(dev, ustatus_addr + 0x10);
672 uint32_t e1c = nv_rd32(dev, ustatus_addr + 0x14);
673 uint32_t e20 = nv_rd32(dev, ustatus_addr + 0x18);
674 uint32_t e24 = nv_rd32(dev, ustatus_addr + 0x1c);
Ben Skeggs274fec92010-11-03 13:16:18 +1000675 /* 2d engine destination */
676 if (ustatus & 0x00000010) {
677 if (display) {
678 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - Unknown fault at address %02x%08x\n",
679 i, e14, e10);
680 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
681 i, e0c, e18, e1c, e20, e24);
682 }
683 ustatus &= ~0x00000010;
684 }
685 /* Render target */
686 if (ustatus & 0x00000040) {
687 if (display) {
688 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - Unknown fault at address %02x%08x\n",
689 i, e14, e10);
690 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
691 i, e0c, e18, e1c, e20, e24);
692 }
693 ustatus &= ~0x00000040;
694 }
695 /* CUDA memory: l[], g[] or stack. */
696 if (ustatus & 0x00000080) {
697 if (display) {
698 if (e18 & 0x80000000) {
699 /* g[] read fault? */
700 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global read fault at address %02x%08x\n",
701 i, e14, e10 | ((e18 >> 24) & 0x1f));
702 e18 &= ~0x1f000000;
703 } else if (e18 & 0xc) {
704 /* g[] write fault? */
705 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global write fault at address %02x%08x\n",
706 i, e14, e10 | ((e18 >> 7) & 0x1f));
707 e18 &= ~0x00000f80;
708 } else {
709 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Unknown CUDA fault at address %02x%08x\n",
710 i, e14, e10);
711 }
712 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
713 i, e0c, e18, e1c, e20, e24);
714 }
715 ustatus &= ~0x00000080;
716 }
717 }
718 break;
719 }
720 if (ustatus) {
721 if (display)
722 NV_INFO(dev, "%s - TP%d: Unhandled ustatus 0x%08x\n", name, i, ustatus);
723 }
724 nv_wr32(dev, ustatus_addr, 0xc0000000);
725 }
726
727 if (!tps && display)
728 NV_INFO(dev, "%s - No TPs claiming errors?\n", name);
729}
730
731static int
732nv50_pgraph_trap_handler(struct drm_device *dev, u32 display, u64 inst, u32 chid)
733{
734 u32 status = nv_rd32(dev, 0x400108);
735 u32 ustatus;
736
737 if (!status && display) {
738 NV_INFO(dev, "PGRAPH - TRAP: no units reporting traps?\n");
739 return 1;
740 }
741
742 /* DISPATCH: Relays commands to other units and handles NOTIFY,
743 * COND, QUERY. If you get a trap from it, the command is still stuck
744 * in DISPATCH and you need to do something about it. */
745 if (status & 0x001) {
746 ustatus = nv_rd32(dev, 0x400804) & 0x7fffffff;
747 if (!ustatus && display) {
748 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - no ustatus?\n");
749 }
750
751 nv_wr32(dev, 0x400500, 0x00000000);
752
753 /* Known to be triggered by screwed up NOTIFY and COND... */
754 if (ustatus & 0x00000001) {
755 u32 addr = nv_rd32(dev, 0x400808);
756 u32 subc = (addr & 0x00070000) >> 16;
757 u32 mthd = (addr & 0x00001ffc);
758 u32 datal = nv_rd32(dev, 0x40080c);
759 u32 datah = nv_rd32(dev, 0x400810);
760 u32 class = nv_rd32(dev, 0x400814);
761 u32 r848 = nv_rd32(dev, 0x400848);
762
763 NV_INFO(dev, "PGRAPH - TRAP DISPATCH_FAULT\n");
764 if (display && (addr & 0x80000000)) {
765 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
766 "subc %d class 0x%04x mthd 0x%04x "
767 "data 0x%08x%08x "
768 "400808 0x%08x 400848 0x%08x\n",
769 chid, inst, subc, class, mthd, datah,
770 datal, addr, r848);
771 } else
772 if (display) {
773 NV_INFO(dev, "PGRAPH - no stuck command?\n");
774 }
775
776 nv_wr32(dev, 0x400808, 0);
777 nv_wr32(dev, 0x4008e8, nv_rd32(dev, 0x4008e8) & 3);
778 nv_wr32(dev, 0x400848, 0);
779 ustatus &= ~0x00000001;
780 }
781
782 if (ustatus & 0x00000002) {
783 u32 addr = nv_rd32(dev, 0x40084c);
784 u32 subc = (addr & 0x00070000) >> 16;
785 u32 mthd = (addr & 0x00001ffc);
786 u32 data = nv_rd32(dev, 0x40085c);
787 u32 class = nv_rd32(dev, 0x400814);
788
789 NV_INFO(dev, "PGRAPH - TRAP DISPATCH_QUERY\n");
790 if (display && (addr & 0x80000000)) {
791 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
792 "subc %d class 0x%04x mthd 0x%04x "
793 "data 0x%08x 40084c 0x%08x\n",
794 chid, inst, subc, class, mthd,
795 data, addr);
796 } else
797 if (display) {
798 NV_INFO(dev, "PGRAPH - no stuck command?\n");
799 }
800
801 nv_wr32(dev, 0x40084c, 0);
802 ustatus &= ~0x00000002;
803 }
804
805 if (ustatus && display) {
806 NV_INFO(dev, "PGRAPH - TRAP_DISPATCH (unknown "
807 "0x%08x)\n", ustatus);
808 }
809
810 nv_wr32(dev, 0x400804, 0xc0000000);
811 nv_wr32(dev, 0x400108, 0x001);
812 status &= ~0x001;
813 if (!status)
814 return 0;
815 }
816
817 /* M2MF: Memory to memory copy engine. */
818 if (status & 0x002) {
819 u32 ustatus = nv_rd32(dev, 0x406800) & 0x7fffffff;
820 if (display) {
821 NV_INFO(dev, "PGRAPH - TRAP_M2MF");
822 nouveau_bitfield_print(nv50_graph_trap_m2mf, ustatus);
823 printk("\n");
824 NV_INFO(dev, "PGRAPH - TRAP_M2MF %08x %08x %08x %08x\n",
825 nv_rd32(dev, 0x406804), nv_rd32(dev, 0x406808),
826 nv_rd32(dev, 0x40680c), nv_rd32(dev, 0x406810));
827
828 }
829
830 /* No sane way found yet -- just reset the bugger. */
831 nv_wr32(dev, 0x400040, 2);
832 nv_wr32(dev, 0x400040, 0);
833 nv_wr32(dev, 0x406800, 0xc0000000);
834 nv_wr32(dev, 0x400108, 0x002);
835 status &= ~0x002;
836 }
837
838 /* VFETCH: Fetches data from vertex buffers. */
839 if (status & 0x004) {
840 u32 ustatus = nv_rd32(dev, 0x400c04) & 0x7fffffff;
841 if (display) {
842 NV_INFO(dev, "PGRAPH - TRAP_VFETCH");
843 nouveau_bitfield_print(nv50_graph_trap_vfetch, ustatus);
844 printk("\n");
845 NV_INFO(dev, "PGRAPH - TRAP_VFETCH %08x %08x %08x %08x\n",
846 nv_rd32(dev, 0x400c00), nv_rd32(dev, 0x400c08),
847 nv_rd32(dev, 0x400c0c), nv_rd32(dev, 0x400c10));
848 }
849
850 nv_wr32(dev, 0x400c04, 0xc0000000);
851 nv_wr32(dev, 0x400108, 0x004);
852 status &= ~0x004;
853 }
854
855 /* STRMOUT: DirectX streamout / OpenGL transform feedback. */
856 if (status & 0x008) {
857 ustatus = nv_rd32(dev, 0x401800) & 0x7fffffff;
858 if (display) {
859 NV_INFO(dev, "PGRAPH - TRAP_STRMOUT");
860 nouveau_bitfield_print(nv50_graph_trap_strmout, ustatus);
861 printk("\n");
862 NV_INFO(dev, "PGRAPH - TRAP_STRMOUT %08x %08x %08x %08x\n",
863 nv_rd32(dev, 0x401804), nv_rd32(dev, 0x401808),
864 nv_rd32(dev, 0x40180c), nv_rd32(dev, 0x401810));
865
866 }
867
868 /* No sane way found yet -- just reset the bugger. */
869 nv_wr32(dev, 0x400040, 0x80);
870 nv_wr32(dev, 0x400040, 0);
871 nv_wr32(dev, 0x401800, 0xc0000000);
872 nv_wr32(dev, 0x400108, 0x008);
873 status &= ~0x008;
874 }
875
876 /* CCACHE: Handles code and c[] caches and fills them. */
877 if (status & 0x010) {
878 ustatus = nv_rd32(dev, 0x405018) & 0x7fffffff;
879 if (display) {
880 NV_INFO(dev, "PGRAPH - TRAP_CCACHE");
881 nouveau_bitfield_print(nv50_graph_trap_ccache, ustatus);
882 printk("\n");
883 NV_INFO(dev, "PGRAPH - TRAP_CCACHE %08x %08x %08x %08x"
884 " %08x %08x %08x\n",
Marcin Slusarz4dcf9052011-02-13 20:46:41 +0100885 nv_rd32(dev, 0x405000), nv_rd32(dev, 0x405004),
886 nv_rd32(dev, 0x405008), nv_rd32(dev, 0x40500c),
887 nv_rd32(dev, 0x405010), nv_rd32(dev, 0x405014),
888 nv_rd32(dev, 0x40501c));
Ben Skeggs274fec92010-11-03 13:16:18 +1000889
890 }
891
892 nv_wr32(dev, 0x405018, 0xc0000000);
893 nv_wr32(dev, 0x400108, 0x010);
894 status &= ~0x010;
895 }
896
897 /* Unknown, not seen yet... 0x402000 is the only trap status reg
898 * remaining, so try to handle it anyway. Perhaps related to that
899 * unknown DMA slot on tesla? */
900 if (status & 0x20) {
901 ustatus = nv_rd32(dev, 0x402000) & 0x7fffffff;
902 if (display)
903 NV_INFO(dev, "PGRAPH - TRAP_UNKC04 0x%08x\n", ustatus);
904 nv_wr32(dev, 0x402000, 0xc0000000);
905 /* no status modifiction on purpose */
906 }
907
908 /* TEXTURE: CUDA texturing units */
909 if (status & 0x040) {
910 nv50_pgraph_tp_trap(dev, 6, 0x408900, 0x408600, display,
911 "PGRAPH - TRAP_TEXTURE");
912 nv_wr32(dev, 0x400108, 0x040);
913 status &= ~0x040;
914 }
915
916 /* MP: CUDA execution engines. */
917 if (status & 0x080) {
918 nv50_pgraph_tp_trap(dev, 7, 0x408314, 0x40831c, display,
919 "PGRAPH - TRAP_MP");
920 nv_wr32(dev, 0x400108, 0x080);
921 status &= ~0x080;
922 }
923
924 /* TPDMA: Handles TP-initiated uncached memory accesses:
925 * l[], g[], stack, 2d surfaces, render targets. */
926 if (status & 0x100) {
927 nv50_pgraph_tp_trap(dev, 8, 0x408e08, 0x408708, display,
928 "PGRAPH - TRAP_TPDMA");
929 nv_wr32(dev, 0x400108, 0x100);
930 status &= ~0x100;
931 }
932
933 if (status) {
934 if (display)
935 NV_INFO(dev, "PGRAPH - TRAP: unknown 0x%08x\n", status);
936 nv_wr32(dev, 0x400108, status);
937 }
938
939 return 1;
940}
941
942static int
943nv50_graph_isr_chid(struct drm_device *dev, u64 inst)
944{
945 struct drm_nouveau_private *dev_priv = dev->dev_private;
946 struct nouveau_channel *chan;
947 unsigned long flags;
948 int i;
949
950 spin_lock_irqsave(&dev_priv->channels.lock, flags);
951 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
952 chan = dev_priv->channels.ptr[i];
953 if (!chan || !chan->ramin)
954 continue;
955
956 if (inst == chan->ramin->vinst)
957 break;
958 }
959 spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
960 return i;
961}
962
963static void
964nv50_graph_isr(struct drm_device *dev)
965{
966 u32 stat;
967
968 while ((stat = nv_rd32(dev, 0x400100))) {
969 u64 inst = (u64)(nv_rd32(dev, 0x40032c) & 0x0fffffff) << 12;
970 u32 chid = nv50_graph_isr_chid(dev, inst);
971 u32 addr = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR);
972 u32 subc = (addr & 0x00070000) >> 16;
973 u32 mthd = (addr & 0x00001ffc);
974 u32 data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA);
975 u32 class = nv_rd32(dev, 0x400814);
976 u32 show = stat;
977
978 if (stat & 0x00000010) {
979 if (!nouveau_gpuobj_mthd_call2(dev, chid, class,
980 mthd, data))
981 show &= ~0x00000010;
982 }
983
984 if (stat & 0x00001000) {
985 nv_wr32(dev, 0x400500, 0x00000000);
986 nv_wr32(dev, 0x400100, 0x00001000);
987 nv_mask(dev, 0x40013c, 0x00001000, 0x00000000);
988 nv50_graph_context_switch(dev);
989 stat &= ~0x00001000;
990 show &= ~0x00001000;
991 }
992
993 show = (show && nouveau_ratelimit()) ? show : 0;
994
995 if (show & 0x00100000) {
996 u32 ecode = nv_rd32(dev, 0x400110);
997 NV_INFO(dev, "PGRAPH - DATA_ERROR ");
998 nouveau_enum_print(nv50_data_error_names, ecode);
999 printk("\n");
1000 }
1001
1002 if (stat & 0x00200000) {
1003 if (!nv50_pgraph_trap_handler(dev, show, inst, chid))
1004 show &= ~0x00200000;
1005 }
1006
1007 nv_wr32(dev, 0x400100, stat);
1008 nv_wr32(dev, 0x400500, 0x00010001);
1009
1010 if (show) {
1011 NV_INFO(dev, "PGRAPH -");
1012 nouveau_bitfield_print(nv50_graph_intr, show);
1013 printk("\n");
1014 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) subc %d "
1015 "class 0x%04x mthd 0x%04x data 0x%08x\n",
1016 chid, inst, subc, class, mthd, data);
Ben Skeggs6fdb3832011-03-08 09:57:17 +10001017 nv50_fb_vm_trap(dev, 1);
Ben Skeggs274fec92010-11-03 13:16:18 +10001018 }
1019 }
1020
1021 if (nv_rd32(dev, 0x400824) & (1 << 31))
1022 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) & ~(1 << 31));
1023}
Ben Skeggs2703c212011-04-01 09:50:18 +10001024
1025static void
1026nv50_graph_destroy(struct drm_device *dev, int engine)
1027{
1028 struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
1029
1030 NVOBJ_ENGINE_DEL(dev, GR);
1031
1032 nouveau_irq_unregister(dev, 12);
1033 kfree(pgraph);
1034}
1035
1036int
1037nv50_graph_create(struct drm_device *dev)
1038{
1039 struct drm_nouveau_private *dev_priv = dev->dev_private;
1040 struct nv50_graph_engine *pgraph;
1041 struct nouveau_grctx ctx = {};
1042 int ret;
1043
1044 pgraph = kzalloc(sizeof(*pgraph),GFP_KERNEL);
1045 if (!pgraph)
1046 return -ENOMEM;
1047
1048 ctx.dev = dev;
1049 ctx.mode = NOUVEAU_GRCTX_PROG;
1050 ctx.data = pgraph->ctxprog;
1051 ctx.ctxprog_max = ARRAY_SIZE(pgraph->ctxprog);
1052
1053 ret = nv50_grctx_init(&ctx);
1054 if (ret) {
1055 NV_ERROR(dev, "PGRAPH: ctxprog build failed\n");
1056 dev_priv->engine.graph.accel_blocked = true;
1057 kfree(pgraph);
1058 return 0;
1059 }
1060
1061 pgraph->grctx_size = ctx.ctxvals_pos * 4;
1062 pgraph->ctxprog_size = ctx.ctxprog_len;
1063
1064 pgraph->base.destroy = nv50_graph_destroy;
1065 pgraph->base.init = nv50_graph_init;
1066 pgraph->base.fini = nv50_graph_fini;
1067 pgraph->base.context_new = nv50_graph_context_new;
1068 pgraph->base.context_del = nv50_graph_context_del;
1069 pgraph->base.object_new = nv50_graph_object_new;
1070 if (dev_priv->chipset == 0x50 || dev_priv->chipset == 0xac)
1071 pgraph->base.tlb_flush = nv50_graph_tlb_flush;
1072 else
1073 pgraph->base.tlb_flush = nv84_graph_tlb_flush;
1074
1075 nouveau_irq_register(dev, 12, nv50_graph_isr);
1076
1077 /* NVSW really doesn't live here... */
1078 NVOBJ_CLASS(dev, 0x506e, SW); /* nvsw */
1079 NVOBJ_MTHD (dev, 0x506e, 0x018c, nv50_graph_nvsw_dma_vblsem);
1080 NVOBJ_MTHD (dev, 0x506e, 0x0400, nv50_graph_nvsw_vblsem_offset);
1081 NVOBJ_MTHD (dev, 0x506e, 0x0404, nv50_graph_nvsw_vblsem_release_val);
1082 NVOBJ_MTHD (dev, 0x506e, 0x0408, nv50_graph_nvsw_vblsem_release);
1083 NVOBJ_MTHD (dev, 0x506e, 0x0500, nv50_graph_nvsw_mthd_page_flip);
1084
1085 NVOBJ_ENGINE_ADD(dev, GR, &pgraph->base);
1086 NVOBJ_CLASS(dev, 0x0030, GR); /* null */
1087 NVOBJ_CLASS(dev, 0x5039, GR); /* m2mf */
1088 NVOBJ_CLASS(dev, 0x502d, GR); /* 2d */
1089
1090 /* tesla */
1091 if (dev_priv->chipset == 0x50)
1092 NVOBJ_CLASS(dev, 0x5097, GR); /* tesla (nv50) */
1093 else
1094 if (dev_priv->chipset < 0xa0)
1095 NVOBJ_CLASS(dev, 0x8297, GR); /* tesla (nv8x/nv9x) */
1096 else {
1097 switch (dev_priv->chipset) {
1098 case 0xa0:
1099 case 0xaa:
1100 case 0xac:
1101 NVOBJ_CLASS(dev, 0x8397, GR);
1102 break;
1103 case 0xa3:
1104 case 0xa5:
1105 case 0xa8:
1106 NVOBJ_CLASS(dev, 0x8597, GR);
1107 break;
1108 case 0xaf:
1109 NVOBJ_CLASS(dev, 0x8697, GR);
1110 break;
1111 }
1112 }
1113
1114 /* compute */
1115 NVOBJ_CLASS(dev, 0x50c0, GR);
1116 if (dev_priv->chipset > 0xa0 &&
1117 dev_priv->chipset != 0xaa &&
1118 dev_priv->chipset != 0xac)
1119 NVOBJ_CLASS(dev, 0x85c0, GR);
1120
1121 return 0;
1122}