blob: d27dcf0790de2367336da3e0d4ac8c0c2ab0fa0f [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);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000128 NV_DEBUG(dev, "\n");
129
130 nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) & ~pmc_e);
131 nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) | pmc_e);
132}
133
134static void
135nv50_graph_init_intr(struct drm_device *dev)
136{
137 NV_DEBUG(dev, "\n");
138
139 nv_wr32(dev, NV03_PGRAPH_INTR, 0xffffffff);
140 nv_wr32(dev, 0x400138, 0xffffffff);
141 nv_wr32(dev, NV40_PGRAPH_INTR_EN, 0xffffffff);
142}
143
144static void
145nv50_graph_init_regs__nv(struct drm_device *dev)
146{
Marcin Koƛcielnicki304424e2010-03-01 00:18:39 +0000147 struct drm_nouveau_private *dev_priv = dev->dev_private;
148 uint32_t units = nv_rd32(dev, 0x1540);
149 int i;
150
Ben Skeggs6ee73862009-12-11 19:24:15 +1000151 NV_DEBUG(dev, "\n");
152
153 nv_wr32(dev, 0x400804, 0xc0000000);
154 nv_wr32(dev, 0x406800, 0xc0000000);
155 nv_wr32(dev, 0x400c04, 0xc0000000);
Marcin Koƛcielnicki716abaa2010-01-12 18:21:56 +0000156 nv_wr32(dev, 0x401800, 0xc0000000);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000157 nv_wr32(dev, 0x405018, 0xc0000000);
158 nv_wr32(dev, 0x402000, 0xc0000000);
159
Marcin Koƛcielnicki304424e2010-03-01 00:18:39 +0000160 for (i = 0; i < 16; i++) {
161 if (units & 1 << i) {
162 if (dev_priv->chipset < 0xa0) {
163 nv_wr32(dev, 0x408900 + (i << 12), 0xc0000000);
164 nv_wr32(dev, 0x408e08 + (i << 12), 0xc0000000);
165 nv_wr32(dev, 0x408314 + (i << 12), 0xc0000000);
166 } else {
167 nv_wr32(dev, 0x408600 + (i << 11), 0xc0000000);
168 nv_wr32(dev, 0x408708 + (i << 11), 0xc0000000);
169 nv_wr32(dev, 0x40831c + (i << 11), 0xc0000000);
170 }
171 }
172 }
173
Ben Skeggs6ee73862009-12-11 19:24:15 +1000174 nv_wr32(dev, 0x400108, 0xffffffff);
175
176 nv_wr32(dev, 0x400824, 0x00004000);
177 nv_wr32(dev, 0x400500, 0x00010001);
178}
179
180static void
Ben Skeggs562af102011-02-23 09:00:35 +1000181nv50_graph_init_zcull(struct drm_device *dev)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000182{
Ben Skeggs562af102011-02-23 09:00:35 +1000183 struct drm_nouveau_private *dev_priv = dev->dev_private;
184 int i;
185
Ben Skeggs6ee73862009-12-11 19:24:15 +1000186 NV_DEBUG(dev, "\n");
187
Ben Skeggs562af102011-02-23 09:00:35 +1000188 switch (dev_priv->chipset & 0xf0) {
189 case 0x50:
190 case 0x80:
191 case 0x90:
192 nv_wr32(dev, 0x402ca8, 0x00000800);
193 break;
194 case 0xa0:
195 default:
196 nv_wr32(dev, 0x402cc0, 0x00000000);
197 if (dev_priv->chipset == 0xa0 ||
198 dev_priv->chipset == 0xaa ||
199 dev_priv->chipset == 0xac) {
200 nv_wr32(dev, 0x402ca8, 0x00000802);
201 } else {
202 nv_wr32(dev, 0x402cc0, 0x00000000);
203 nv_wr32(dev, 0x402ca8, 0x00000002);
204 }
205
206 break;
207 }
208
209 /* zero out zcull regions */
210 for (i = 0; i < 8; i++) {
211 nv_wr32(dev, 0x402c20 + (i * 8), 0x00000000);
212 nv_wr32(dev, 0x402c24 + (i * 8), 0x00000000);
213 nv_wr32(dev, 0x402c28 + (i * 8), 0x00000000);
214 nv_wr32(dev, 0x402c2c + (i * 8), 0x00000000);
215 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000216}
217
218static int
219nv50_graph_init_ctxctl(struct drm_device *dev)
220{
Ben Skeggs2703c212011-04-01 09:50:18 +1000221 struct nv50_graph_engine *pgraph = nv_engine(dev, NVOBJ_ENGINE_GR);
Ben Skeggsec91db22010-07-08 11:53:19 +1000222 int i;
Ben Skeggs054b93e2009-12-15 22:02:47 +1000223
Ben Skeggs6ee73862009-12-11 19:24:15 +1000224 NV_DEBUG(dev, "\n");
225
Ben Skeggs2703c212011-04-01 09:50:18 +1000226 nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0);
227 for (i = 0; i < pgraph->ctxprog_size; i++)
228 nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_DATA, pgraph->ctxprog[i]);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000229
Ben Skeggs562af102011-02-23 09:00:35 +1000230 nv_wr32(dev, 0x40008c, 0x00000004); /* HW_CTX_SWITCH_ENABLED */
Ben Skeggs6ee73862009-12-11 19:24:15 +1000231 nv_wr32(dev, 0x400320, 4);
232 nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, 0);
233 nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, 0);
234 return 0;
235}
236
Ben Skeggs2703c212011-04-01 09:50:18 +1000237static int
238nv50_graph_init(struct drm_device *dev, int engine)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000239{
240 int ret;
241
242 NV_DEBUG(dev, "\n");
243
244 nv50_graph_init_reset(dev);
245 nv50_graph_init_regs__nv(dev);
Ben Skeggs562af102011-02-23 09:00:35 +1000246 nv50_graph_init_zcull(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000247
248 ret = nv50_graph_init_ctxctl(dev);
249 if (ret)
250 return ret;
251
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000252 nv50_graph_init_intr(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000253 return 0;
254}
255
Ben Skeggs2703c212011-04-01 09:50:18 +1000256static int
Ben Skeggs6c320fe2011-07-20 11:22:33 +1000257nv50_graph_fini(struct drm_device *dev, int engine, bool suspend)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000258{
Ben Skeggs9962cc62011-07-20 11:44:52 +1000259 nv_mask(dev, 0x400500, 0x00010001, 0x00000000);
260 if (!nv_wait(dev, 0x400700, ~0, 0) && suspend) {
261 nv_mask(dev, 0x400500, 0x00010001, 0x00010001);
262 return -EBUSY;
263 }
Ben Skeggs2703c212011-04-01 09:50:18 +1000264 nv50_graph_unload_context(dev);
Ben Skeggs274fec92010-11-03 13:16:18 +1000265 nv_wr32(dev, 0x40013c, 0x00000000);
Ben Skeggs2703c212011-04-01 09:50:18 +1000266 return 0;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000267}
268
Ben Skeggs2703c212011-04-01 09:50:18 +1000269static int
270nv50_graph_context_new(struct nouveau_channel *chan, int engine)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000271{
272 struct drm_device *dev = chan->dev;
273 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000274 struct nouveau_gpuobj *ramin = chan->ramin;
Ben Skeggs2703c212011-04-01 09:50:18 +1000275 struct nouveau_gpuobj *grctx = NULL;
276 struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
Ben Skeggsec91db22010-07-08 11:53:19 +1000277 struct nouveau_grctx ctx = {};
Ben Skeggs6ee73862009-12-11 19:24:15 +1000278 int hdr, ret;
279
280 NV_DEBUG(dev, "ch%d\n", chan->id);
281
Ben Skeggs2703c212011-04-01 09:50:18 +1000282 ret = nouveau_gpuobj_new(dev, NULL, pgraph->grctx_size, 0,
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000283 NVOBJ_FLAG_ZERO_ALLOC |
Ben Skeggs2703c212011-04-01 09:50:18 +1000284 NVOBJ_FLAG_ZERO_FREE, &grctx);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000285 if (ret)
286 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000287
Ben Skeggsac94a342010-07-08 15:28:48 +1000288 hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
Ben Skeggsb3beb162010-09-01 15:24:29 +1000289 nv_wo32(ramin, hdr + 0x00, 0x00190002);
Ben Skeggs2703c212011-04-01 09:50:18 +1000290 nv_wo32(ramin, hdr + 0x04, grctx->vinst + grctx->size - 1);
291 nv_wo32(ramin, hdr + 0x08, grctx->vinst);
Ben Skeggsb3beb162010-09-01 15:24:29 +1000292 nv_wo32(ramin, hdr + 0x0c, 0);
293 nv_wo32(ramin, hdr + 0x10, 0);
294 nv_wo32(ramin, hdr + 0x14, 0x00010000);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000295
Ben Skeggsec91db22010-07-08 11:53:19 +1000296 ctx.dev = chan->dev;
297 ctx.mode = NOUVEAU_GRCTX_VALS;
Ben Skeggs2703c212011-04-01 09:50:18 +1000298 ctx.data = grctx;
Ben Skeggsec91db22010-07-08 11:53:19 +1000299 nv50_grctx_init(&ctx);
300
Ben Skeggs2703c212011-04-01 09:50:18 +1000301 nv_wo32(grctx, 0x00000, chan->ramin->vinst >> 12);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000302
Ben Skeggsf56cb862010-07-08 11:29:10 +1000303 dev_priv->engine.instmem.flush(dev);
Ben Skeggs2703c212011-04-01 09:50:18 +1000304
305 atomic_inc(&chan->vm->engref[NVOBJ_ENGINE_GR]);
306 chan->engctx[NVOBJ_ENGINE_GR] = grctx;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000307 return 0;
308}
309
Ben Skeggs2703c212011-04-01 09:50:18 +1000310static void
311nv50_graph_context_del(struct nouveau_channel *chan, int engine)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000312{
Ben Skeggs2703c212011-04-01 09:50:18 +1000313 struct nouveau_gpuobj *grctx = chan->engctx[engine];
Ben Skeggs6ee73862009-12-11 19:24:15 +1000314 struct drm_device *dev = chan->dev;
315 struct drm_nouveau_private *dev_priv = dev->dev_private;
Francisco Jerez34311c72011-01-24 01:47:42 +0100316 struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
Ben Skeggsac94a342010-07-08 15:28:48 +1000317 int i, hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
Francisco Jerez3945e472010-10-18 03:53:39 +0200318 unsigned long flags;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000319
320 NV_DEBUG(dev, "ch%d\n", chan->id);
321
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000322 if (!chan->ramin)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000323 return;
324
Francisco Jerez3945e472010-10-18 03:53:39 +0200325 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
Francisco Jerez34311c72011-01-24 01:47:42 +0100326 pfifo->reassign(dev, false);
Ben Skeggs2703c212011-04-01 09:50:18 +1000327 nv50_graph_fifo_access(dev, false);
Francisco Jerez3945e472010-10-18 03:53:39 +0200328
Ben Skeggs2703c212011-04-01 09:50:18 +1000329 if (nv50_graph_channel(dev) == chan)
330 nv50_graph_unload_context(dev);
Francisco Jerez3945e472010-10-18 03:53:39 +0200331
Ben Skeggs6ee73862009-12-11 19:24:15 +1000332 for (i = hdr; i < hdr + 24; i += 4)
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000333 nv_wo32(chan->ramin, i, 0);
Ben Skeggsf56cb862010-07-08 11:29:10 +1000334 dev_priv->engine.instmem.flush(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000335
Ben Skeggs2703c212011-04-01 09:50:18 +1000336 nv50_graph_fifo_access(dev, true);
Francisco Jerez34311c72011-01-24 01:47:42 +0100337 pfifo->reassign(dev, true);
Francisco Jerez3945e472010-10-18 03:53:39 +0200338 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
339
Ben Skeggs2703c212011-04-01 09:50:18 +1000340 nouveau_gpuobj_ref(NULL, &grctx);
Ben Skeggs4c136142010-11-15 11:54:21 +1000341
Ben Skeggs2703c212011-04-01 09:50:18 +1000342 atomic_dec(&chan->vm->engref[engine]);
343 chan->engctx[engine] = NULL;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000344}
345
346static int
Ben Skeggs2703c212011-04-01 09:50:18 +1000347nv50_graph_object_new(struct nouveau_channel *chan, int engine,
348 u32 handle, u16 class)
Ben Skeggs4ea52f82011-03-31 13:44:16 +1000349{
350 struct drm_device *dev = chan->dev;
351 struct drm_nouveau_private *dev_priv = dev->dev_private;
352 struct nouveau_gpuobj *obj = NULL;
353 int ret;
354
355 ret = nouveau_gpuobj_new(dev, chan, 16, 16, NVOBJ_FLAG_ZERO_FREE, &obj);
356 if (ret)
357 return ret;
358 obj->engine = 1;
359 obj->class = class;
360
361 nv_wo32(obj, 0x00, class);
362 nv_wo32(obj, 0x04, 0x00000000);
363 nv_wo32(obj, 0x08, 0x00000000);
364 nv_wo32(obj, 0x0c, 0x00000000);
365 dev_priv->engine.instmem.flush(dev);
366
367 ret = nouveau_ramht_insert(chan, handle, obj);
368 nouveau_gpuobj_ref(NULL, &obj);
369 return ret;
370}
371
Ben Skeggs274fec92010-11-03 13:16:18 +1000372static void
Ben Skeggs6ee73862009-12-11 19:24:15 +1000373nv50_graph_context_switch(struct drm_device *dev)
374{
375 uint32_t inst;
376
377 nv50_graph_unload_context(dev);
378
379 inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_NEXT);
380 inst &= NV50_PGRAPH_CTXCTL_NEXT_INSTANCE;
381 nv50_graph_do_load_context(dev, inst);
382
383 nv_wr32(dev, NV40_PGRAPH_INTR_EN, nv_rd32(dev,
384 NV40_PGRAPH_INTR_EN) | NV_PGRAPH_INTR_CONTEXT_SWITCH);
385}
386
387static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000388nv50_graph_nvsw_dma_vblsem(struct nouveau_channel *chan,
389 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000390{
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000391 struct nouveau_gpuobj *gpuobj;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000392
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000393 gpuobj = nouveau_ramht_find(chan, data);
394 if (!gpuobj)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000395 return -ENOENT;
396
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000397 if (nouveau_notifier_offset(gpuobj, NULL))
Ben Skeggs6ee73862009-12-11 19:24:15 +1000398 return -EINVAL;
399
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000400 chan->nvsw.vblsem = gpuobj;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000401 chan->nvsw.vblsem_offset = ~0;
402 return 0;
403}
404
405static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000406nv50_graph_nvsw_vblsem_offset(struct nouveau_channel *chan,
407 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000408{
409 if (nouveau_notifier_offset(chan->nvsw.vblsem, &data))
410 return -ERANGE;
411
412 chan->nvsw.vblsem_offset = data >> 2;
413 return 0;
414}
415
416static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000417nv50_graph_nvsw_vblsem_release_val(struct nouveau_channel *chan,
418 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000419{
420 chan->nvsw.vblsem_rval = data;
421 return 0;
422}
423
424static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000425nv50_graph_nvsw_vblsem_release(struct nouveau_channel *chan,
426 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000427{
428 struct drm_device *dev = chan->dev;
429 struct drm_nouveau_private *dev_priv = dev->dev_private;
430
431 if (!chan->nvsw.vblsem || chan->nvsw.vblsem_offset == ~0 || data > 1)
432 return -EINVAL;
433
Francisco Jerez042206c2010-10-21 18:19:29 +0200434 drm_vblank_get(dev, data);
Francisco Jerez1f6d2de2010-10-24 14:15:58 +0200435
436 chan->nvsw.vblsem_head = data;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000437 list_add(&chan->nvsw.vbl_wait, &dev_priv->vbl_waiting);
Francisco Jerez1f6d2de2010-10-24 14:15:58 +0200438
Ben Skeggs6ee73862009-12-11 19:24:15 +1000439 return 0;
440}
441
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000442static int
Francisco Jerez332b2422010-10-20 23:35:40 +0200443nv50_graph_nvsw_mthd_page_flip(struct nouveau_channel *chan,
444 u32 class, u32 mthd, u32 data)
445{
Ben Skeggsd7117e02011-02-07 14:27:04 +1000446 nouveau_finish_page_flip(chan, NULL);
Francisco Jerez332b2422010-10-20 23:35:40 +0200447 return 0;
448}
449
Ben Skeggs6ee73862009-12-11 19:24:15 +1000450
Ben Skeggs2703c212011-04-01 09:50:18 +1000451static void
452nv50_graph_tlb_flush(struct drm_device *dev, int engine)
Ben Skeggs56ac7472010-10-22 10:26:24 +1000453{
Ben Skeggsa11c3192010-08-27 10:00:25 +1000454 nv50_vm_flush_engine(dev, 0);
Ben Skeggs56ac7472010-10-22 10:26:24 +1000455}
456
Ben Skeggs2703c212011-04-01 09:50:18 +1000457static void
458nv84_graph_tlb_flush(struct drm_device *dev, int engine)
Ben Skeggs56ac7472010-10-22 10:26:24 +1000459{
460 struct drm_nouveau_private *dev_priv = dev->dev_private;
461 struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer;
462 bool idle, timeout = false;
463 unsigned long flags;
464 u64 start;
465 u32 tmp;
466
467 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
468 nv_mask(dev, 0x400500, 0x00000001, 0x00000000);
469
470 start = ptimer->read(dev);
471 do {
472 idle = true;
473
474 for (tmp = nv_rd32(dev, 0x400380); tmp && idle; tmp >>= 3) {
475 if ((tmp & 7) == 1)
476 idle = false;
477 }
478
479 for (tmp = nv_rd32(dev, 0x400384); tmp && idle; tmp >>= 3) {
480 if ((tmp & 7) == 1)
481 idle = false;
482 }
483
484 for (tmp = nv_rd32(dev, 0x400388); tmp && idle; tmp >>= 3) {
485 if ((tmp & 7) == 1)
486 idle = false;
487 }
488 } while (!idle && !(timeout = ptimer->read(dev) - start > 2000000000));
489
490 if (timeout) {
491 NV_ERROR(dev, "PGRAPH TLB flush idle timeout fail: "
492 "0x%08x 0x%08x 0x%08x 0x%08x\n",
493 nv_rd32(dev, 0x400700), nv_rd32(dev, 0x400380),
494 nv_rd32(dev, 0x400384), nv_rd32(dev, 0x400388));
495 }
496
Ben Skeggsa11c3192010-08-27 10:00:25 +1000497 nv50_vm_flush_engine(dev, 0);
Ben Skeggs56ac7472010-10-22 10:26:24 +1000498
499 nv_mask(dev, 0x400500, 0x00000001, 0x00000001);
500 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
501}
Ben Skeggs274fec92010-11-03 13:16:18 +1000502
Emil Velikovf9ec8f62011-03-19 23:31:53 +0000503static struct nouveau_enum nv50_mp_exec_error_names[] = {
Ben Skeggsbb9b18a2011-03-08 08:39:43 +1000504 { 3, "STACK_UNDERFLOW", NULL },
505 { 4, "QUADON_ACTIVE", NULL },
506 { 8, "TIMEOUT", NULL },
507 { 0x10, "INVALID_OPCODE", NULL },
508 { 0x40, "BREAKPOINT", NULL },
Ben Skeggs274fec92010-11-03 13:16:18 +1000509 {}
510};
511
512static struct nouveau_bitfield nv50_graph_trap_m2mf[] = {
513 { 0x00000001, "NOTIFY" },
514 { 0x00000002, "IN" },
515 { 0x00000004, "OUT" },
516 {}
517};
518
519static struct nouveau_bitfield nv50_graph_trap_vfetch[] = {
520 { 0x00000001, "FAULT" },
521 {}
522};
523
524static struct nouveau_bitfield nv50_graph_trap_strmout[] = {
525 { 0x00000001, "FAULT" },
526 {}
527};
528
529static struct nouveau_bitfield nv50_graph_trap_ccache[] = {
530 { 0x00000001, "FAULT" },
531 {}
532};
533
534/* There must be a *lot* of these. Will take some time to gather them up. */
Ben Skeggs6effe392010-12-30 11:48:03 +1000535struct nouveau_enum nv50_data_error_names[] = {
Ben Skeggsbb9b18a2011-03-08 08:39:43 +1000536 { 0x00000003, "INVALID_QUERY_OR_TEXTURE", NULL },
537 { 0x00000004, "INVALID_VALUE", NULL },
538 { 0x00000005, "INVALID_ENUM", NULL },
539 { 0x00000008, "INVALID_OBJECT", NULL },
540 { 0x00000009, "READ_ONLY_OBJECT", NULL },
541 { 0x0000000a, "SUPERVISOR_OBJECT", NULL },
542 { 0x0000000b, "INVALID_ADDRESS_ALIGNMENT", NULL },
543 { 0x0000000c, "INVALID_BITFIELD", NULL },
544 { 0x0000000d, "BEGIN_END_ACTIVE", NULL },
545 { 0x0000000e, "SEMANTIC_COLOR_BACK_OVER_LIMIT", NULL },
546 { 0x0000000f, "VIEWPORT_ID_NEEDS_GP", NULL },
547 { 0x00000010, "RT_DOUBLE_BIND", NULL },
548 { 0x00000011, "RT_TYPES_MISMATCH", NULL },
549 { 0x00000012, "RT_LINEAR_WITH_ZETA", NULL },
550 { 0x00000015, "FP_TOO_FEW_REGS", NULL },
551 { 0x00000016, "ZETA_FORMAT_CSAA_MISMATCH", NULL },
552 { 0x00000017, "RT_LINEAR_WITH_MSAA", NULL },
553 { 0x00000018, "FP_INTERPOLANT_START_OVER_LIMIT", NULL },
554 { 0x00000019, "SEMANTIC_LAYER_OVER_LIMIT", NULL },
555 { 0x0000001a, "RT_INVALID_ALIGNMENT", NULL },
556 { 0x0000001b, "SAMPLER_OVER_LIMIT", NULL },
557 { 0x0000001c, "TEXTURE_OVER_LIMIT", NULL },
558 { 0x0000001e, "GP_TOO_MANY_OUTPUTS", NULL },
559 { 0x0000001f, "RT_BPP128_WITH_MS8", NULL },
560 { 0x00000021, "Z_OUT_OF_BOUNDS", NULL },
561 { 0x00000023, "XY_OUT_OF_BOUNDS", NULL },
562 { 0x00000027, "CP_MORE_PARAMS_THAN_SHARED", NULL },
563 { 0x00000028, "CP_NO_REG_SPACE_STRIPED", NULL },
564 { 0x00000029, "CP_NO_REG_SPACE_PACKED", NULL },
565 { 0x0000002a, "CP_NOT_ENOUGH_WARPS", NULL },
566 { 0x0000002b, "CP_BLOCK_SIZE_MISMATCH", NULL },
567 { 0x0000002c, "CP_NOT_ENOUGH_LOCAL_WARPS", NULL },
568 { 0x0000002d, "CP_NOT_ENOUGH_STACK_WARPS", NULL },
569 { 0x0000002e, "CP_NO_BLOCKDIM_LATCH", NULL },
570 { 0x00000031, "ENG2D_FORMAT_MISMATCH", NULL },
571 { 0x0000003f, "PRIMITIVE_ID_NEEDS_GP", NULL },
572 { 0x00000044, "SEMANTIC_VIEWPORT_OVER_LIMIT", NULL },
573 { 0x00000045, "SEMANTIC_COLOR_FRONT_OVER_LIMIT", NULL },
574 { 0x00000046, "LAYER_ID_NEEDS_GP", NULL },
575 { 0x00000047, "SEMANTIC_CLIP_OVER_LIMIT", NULL },
576 { 0x00000048, "SEMANTIC_PTSZ_OVER_LIMIT", NULL },
Ben Skeggs274fec92010-11-03 13:16:18 +1000577 {}
578};
579
580static struct nouveau_bitfield nv50_graph_intr[] = {
581 { 0x00000001, "NOTIFY" },
582 { 0x00000002, "COMPUTE_QUERY" },
583 { 0x00000010, "ILLEGAL_MTHD" },
584 { 0x00000020, "ILLEGAL_CLASS" },
585 { 0x00000040, "DOUBLE_NOTIFY" },
586 { 0x00001000, "CONTEXT_SWITCH" },
587 { 0x00010000, "BUFFER_NOTIFY" },
588 { 0x00100000, "DATA_ERROR" },
589 { 0x00200000, "TRAP" },
590 { 0x01000000, "SINGLE_STEP" },
591 {}
592};
593
594static void
595nv50_pgraph_mp_trap(struct drm_device *dev, int tpid, int display)
596{
597 struct drm_nouveau_private *dev_priv = dev->dev_private;
598 uint32_t units = nv_rd32(dev, 0x1540);
599 uint32_t addr, mp10, status, pc, oplow, ophigh;
600 int i;
601 int mps = 0;
602 for (i = 0; i < 4; i++) {
603 if (!(units & 1 << (i+24)))
604 continue;
605 if (dev_priv->chipset < 0xa0)
606 addr = 0x408200 + (tpid << 12) + (i << 7);
607 else
608 addr = 0x408100 + (tpid << 11) + (i << 7);
609 mp10 = nv_rd32(dev, addr + 0x10);
610 status = nv_rd32(dev, addr + 0x14);
611 if (!status)
612 continue;
613 if (display) {
614 nv_rd32(dev, addr + 0x20);
615 pc = nv_rd32(dev, addr + 0x24);
616 oplow = nv_rd32(dev, addr + 0x70);
Emil Velikov0b89a072011-03-19 23:31:54 +0000617 ophigh = nv_rd32(dev, addr + 0x74);
Ben Skeggs274fec92010-11-03 13:16:18 +1000618 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - "
619 "TP %d MP %d: ", tpid, i);
620 nouveau_enum_print(nv50_mp_exec_error_names, status);
621 printk(" at %06x warp %d, opcode %08x %08x\n",
622 pc&0xffffff, pc >> 24,
623 oplow, ophigh);
624 }
625 nv_wr32(dev, addr + 0x10, mp10);
626 nv_wr32(dev, addr + 0x14, 0);
627 mps++;
628 }
629 if (!mps && display)
630 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - TP %d: "
631 "No MPs claiming errors?\n", tpid);
632}
633
634static void
635nv50_pgraph_tp_trap(struct drm_device *dev, int type, uint32_t ustatus_old,
636 uint32_t ustatus_new, int display, const char *name)
637{
638 struct drm_nouveau_private *dev_priv = dev->dev_private;
639 int tps = 0;
640 uint32_t units = nv_rd32(dev, 0x1540);
641 int i, r;
642 uint32_t ustatus_addr, ustatus;
643 for (i = 0; i < 16; i++) {
644 if (!(units & (1 << i)))
645 continue;
646 if (dev_priv->chipset < 0xa0)
647 ustatus_addr = ustatus_old + (i << 12);
648 else
649 ustatus_addr = ustatus_new + (i << 11);
650 ustatus = nv_rd32(dev, ustatus_addr) & 0x7fffffff;
651 if (!ustatus)
652 continue;
653 tps++;
654 switch (type) {
655 case 6: /* texture error... unknown for now */
Ben Skeggs274fec92010-11-03 13:16:18 +1000656 if (display) {
657 NV_ERROR(dev, "magic set %d:\n", i);
658 for (r = ustatus_addr + 4; r <= ustatus_addr + 0x10; r += 4)
659 NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r,
660 nv_rd32(dev, r));
661 }
662 break;
663 case 7: /* MP error */
664 if (ustatus & 0x00010000) {
665 nv50_pgraph_mp_trap(dev, i, display);
666 ustatus &= ~0x00010000;
667 }
668 break;
669 case 8: /* TPDMA error */
670 {
671 uint32_t e0c = nv_rd32(dev, ustatus_addr + 4);
672 uint32_t e10 = nv_rd32(dev, ustatus_addr + 8);
673 uint32_t e14 = nv_rd32(dev, ustatus_addr + 0xc);
674 uint32_t e18 = nv_rd32(dev, ustatus_addr + 0x10);
675 uint32_t e1c = nv_rd32(dev, ustatus_addr + 0x14);
676 uint32_t e20 = nv_rd32(dev, ustatus_addr + 0x18);
677 uint32_t e24 = nv_rd32(dev, ustatus_addr + 0x1c);
Ben Skeggs274fec92010-11-03 13:16:18 +1000678 /* 2d engine destination */
679 if (ustatus & 0x00000010) {
680 if (display) {
681 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - Unknown fault at address %02x%08x\n",
682 i, e14, e10);
683 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
684 i, e0c, e18, e1c, e20, e24);
685 }
686 ustatus &= ~0x00000010;
687 }
688 /* Render target */
689 if (ustatus & 0x00000040) {
690 if (display) {
691 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - Unknown fault at address %02x%08x\n",
692 i, e14, e10);
693 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
694 i, e0c, e18, e1c, e20, e24);
695 }
696 ustatus &= ~0x00000040;
697 }
698 /* CUDA memory: l[], g[] or stack. */
699 if (ustatus & 0x00000080) {
700 if (display) {
701 if (e18 & 0x80000000) {
702 /* g[] read fault? */
703 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global read fault at address %02x%08x\n",
704 i, e14, e10 | ((e18 >> 24) & 0x1f));
705 e18 &= ~0x1f000000;
706 } else if (e18 & 0xc) {
707 /* g[] write fault? */
708 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global write fault at address %02x%08x\n",
709 i, e14, e10 | ((e18 >> 7) & 0x1f));
710 e18 &= ~0x00000f80;
711 } else {
712 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Unknown CUDA fault at address %02x%08x\n",
713 i, e14, e10);
714 }
715 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
716 i, e0c, e18, e1c, e20, e24);
717 }
718 ustatus &= ~0x00000080;
719 }
720 }
721 break;
722 }
723 if (ustatus) {
724 if (display)
725 NV_INFO(dev, "%s - TP%d: Unhandled ustatus 0x%08x\n", name, i, ustatus);
726 }
727 nv_wr32(dev, ustatus_addr, 0xc0000000);
728 }
729
730 if (!tps && display)
731 NV_INFO(dev, "%s - No TPs claiming errors?\n", name);
732}
733
734static int
735nv50_pgraph_trap_handler(struct drm_device *dev, u32 display, u64 inst, u32 chid)
736{
737 u32 status = nv_rd32(dev, 0x400108);
738 u32 ustatus;
739
740 if (!status && display) {
741 NV_INFO(dev, "PGRAPH - TRAP: no units reporting traps?\n");
742 return 1;
743 }
744
745 /* DISPATCH: Relays commands to other units and handles NOTIFY,
746 * COND, QUERY. If you get a trap from it, the command is still stuck
747 * in DISPATCH and you need to do something about it. */
748 if (status & 0x001) {
749 ustatus = nv_rd32(dev, 0x400804) & 0x7fffffff;
750 if (!ustatus && display) {
751 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - no ustatus?\n");
752 }
753
754 nv_wr32(dev, 0x400500, 0x00000000);
755
756 /* Known to be triggered by screwed up NOTIFY and COND... */
757 if (ustatus & 0x00000001) {
758 u32 addr = nv_rd32(dev, 0x400808);
759 u32 subc = (addr & 0x00070000) >> 16;
760 u32 mthd = (addr & 0x00001ffc);
761 u32 datal = nv_rd32(dev, 0x40080c);
762 u32 datah = nv_rd32(dev, 0x400810);
763 u32 class = nv_rd32(dev, 0x400814);
764 u32 r848 = nv_rd32(dev, 0x400848);
765
766 NV_INFO(dev, "PGRAPH - TRAP DISPATCH_FAULT\n");
767 if (display && (addr & 0x80000000)) {
768 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
769 "subc %d class 0x%04x mthd 0x%04x "
770 "data 0x%08x%08x "
771 "400808 0x%08x 400848 0x%08x\n",
772 chid, inst, subc, class, mthd, datah,
773 datal, addr, r848);
774 } else
775 if (display) {
776 NV_INFO(dev, "PGRAPH - no stuck command?\n");
777 }
778
779 nv_wr32(dev, 0x400808, 0);
780 nv_wr32(dev, 0x4008e8, nv_rd32(dev, 0x4008e8) & 3);
781 nv_wr32(dev, 0x400848, 0);
782 ustatus &= ~0x00000001;
783 }
784
785 if (ustatus & 0x00000002) {
786 u32 addr = nv_rd32(dev, 0x40084c);
787 u32 subc = (addr & 0x00070000) >> 16;
788 u32 mthd = (addr & 0x00001ffc);
789 u32 data = nv_rd32(dev, 0x40085c);
790 u32 class = nv_rd32(dev, 0x400814);
791
792 NV_INFO(dev, "PGRAPH - TRAP DISPATCH_QUERY\n");
793 if (display && (addr & 0x80000000)) {
794 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
795 "subc %d class 0x%04x mthd 0x%04x "
796 "data 0x%08x 40084c 0x%08x\n",
797 chid, inst, subc, class, mthd,
798 data, addr);
799 } else
800 if (display) {
801 NV_INFO(dev, "PGRAPH - no stuck command?\n");
802 }
803
804 nv_wr32(dev, 0x40084c, 0);
805 ustatus &= ~0x00000002;
806 }
807
808 if (ustatus && display) {
809 NV_INFO(dev, "PGRAPH - TRAP_DISPATCH (unknown "
810 "0x%08x)\n", ustatus);
811 }
812
813 nv_wr32(dev, 0x400804, 0xc0000000);
814 nv_wr32(dev, 0x400108, 0x001);
815 status &= ~0x001;
816 if (!status)
817 return 0;
818 }
819
820 /* M2MF: Memory to memory copy engine. */
821 if (status & 0x002) {
822 u32 ustatus = nv_rd32(dev, 0x406800) & 0x7fffffff;
823 if (display) {
824 NV_INFO(dev, "PGRAPH - TRAP_M2MF");
825 nouveau_bitfield_print(nv50_graph_trap_m2mf, ustatus);
826 printk("\n");
827 NV_INFO(dev, "PGRAPH - TRAP_M2MF %08x %08x %08x %08x\n",
828 nv_rd32(dev, 0x406804), nv_rd32(dev, 0x406808),
829 nv_rd32(dev, 0x40680c), nv_rd32(dev, 0x406810));
830
831 }
832
833 /* No sane way found yet -- just reset the bugger. */
834 nv_wr32(dev, 0x400040, 2);
835 nv_wr32(dev, 0x400040, 0);
836 nv_wr32(dev, 0x406800, 0xc0000000);
837 nv_wr32(dev, 0x400108, 0x002);
838 status &= ~0x002;
839 }
840
841 /* VFETCH: Fetches data from vertex buffers. */
842 if (status & 0x004) {
843 u32 ustatus = nv_rd32(dev, 0x400c04) & 0x7fffffff;
844 if (display) {
845 NV_INFO(dev, "PGRAPH - TRAP_VFETCH");
846 nouveau_bitfield_print(nv50_graph_trap_vfetch, ustatus);
847 printk("\n");
848 NV_INFO(dev, "PGRAPH - TRAP_VFETCH %08x %08x %08x %08x\n",
849 nv_rd32(dev, 0x400c00), nv_rd32(dev, 0x400c08),
850 nv_rd32(dev, 0x400c0c), nv_rd32(dev, 0x400c10));
851 }
852
853 nv_wr32(dev, 0x400c04, 0xc0000000);
854 nv_wr32(dev, 0x400108, 0x004);
855 status &= ~0x004;
856 }
857
858 /* STRMOUT: DirectX streamout / OpenGL transform feedback. */
859 if (status & 0x008) {
860 ustatus = nv_rd32(dev, 0x401800) & 0x7fffffff;
861 if (display) {
862 NV_INFO(dev, "PGRAPH - TRAP_STRMOUT");
863 nouveau_bitfield_print(nv50_graph_trap_strmout, ustatus);
864 printk("\n");
865 NV_INFO(dev, "PGRAPH - TRAP_STRMOUT %08x %08x %08x %08x\n",
866 nv_rd32(dev, 0x401804), nv_rd32(dev, 0x401808),
867 nv_rd32(dev, 0x40180c), nv_rd32(dev, 0x401810));
868
869 }
870
871 /* No sane way found yet -- just reset the bugger. */
872 nv_wr32(dev, 0x400040, 0x80);
873 nv_wr32(dev, 0x400040, 0);
874 nv_wr32(dev, 0x401800, 0xc0000000);
875 nv_wr32(dev, 0x400108, 0x008);
876 status &= ~0x008;
877 }
878
879 /* CCACHE: Handles code and c[] caches and fills them. */
880 if (status & 0x010) {
881 ustatus = nv_rd32(dev, 0x405018) & 0x7fffffff;
882 if (display) {
883 NV_INFO(dev, "PGRAPH - TRAP_CCACHE");
884 nouveau_bitfield_print(nv50_graph_trap_ccache, ustatus);
885 printk("\n");
886 NV_INFO(dev, "PGRAPH - TRAP_CCACHE %08x %08x %08x %08x"
887 " %08x %08x %08x\n",
Marcin Slusarz4dcf9052011-02-13 20:46:41 +0100888 nv_rd32(dev, 0x405000), nv_rd32(dev, 0x405004),
889 nv_rd32(dev, 0x405008), nv_rd32(dev, 0x40500c),
890 nv_rd32(dev, 0x405010), nv_rd32(dev, 0x405014),
891 nv_rd32(dev, 0x40501c));
Ben Skeggs274fec92010-11-03 13:16:18 +1000892
893 }
894
895 nv_wr32(dev, 0x405018, 0xc0000000);
896 nv_wr32(dev, 0x400108, 0x010);
897 status &= ~0x010;
898 }
899
900 /* Unknown, not seen yet... 0x402000 is the only trap status reg
901 * remaining, so try to handle it anyway. Perhaps related to that
902 * unknown DMA slot on tesla? */
903 if (status & 0x20) {
904 ustatus = nv_rd32(dev, 0x402000) & 0x7fffffff;
905 if (display)
906 NV_INFO(dev, "PGRAPH - TRAP_UNKC04 0x%08x\n", ustatus);
907 nv_wr32(dev, 0x402000, 0xc0000000);
908 /* no status modifiction on purpose */
909 }
910
911 /* TEXTURE: CUDA texturing units */
912 if (status & 0x040) {
913 nv50_pgraph_tp_trap(dev, 6, 0x408900, 0x408600, display,
914 "PGRAPH - TRAP_TEXTURE");
915 nv_wr32(dev, 0x400108, 0x040);
916 status &= ~0x040;
917 }
918
919 /* MP: CUDA execution engines. */
920 if (status & 0x080) {
921 nv50_pgraph_tp_trap(dev, 7, 0x408314, 0x40831c, display,
922 "PGRAPH - TRAP_MP");
923 nv_wr32(dev, 0x400108, 0x080);
924 status &= ~0x080;
925 }
926
927 /* TPDMA: Handles TP-initiated uncached memory accesses:
928 * l[], g[], stack, 2d surfaces, render targets. */
929 if (status & 0x100) {
930 nv50_pgraph_tp_trap(dev, 8, 0x408e08, 0x408708, display,
931 "PGRAPH - TRAP_TPDMA");
932 nv_wr32(dev, 0x400108, 0x100);
933 status &= ~0x100;
934 }
935
936 if (status) {
937 if (display)
938 NV_INFO(dev, "PGRAPH - TRAP: unknown 0x%08x\n", status);
939 nv_wr32(dev, 0x400108, status);
940 }
941
942 return 1;
943}
944
Ben Skeggs7ff54412011-03-18 10:25:59 +1000945int
Ben Skeggs274fec92010-11-03 13:16:18 +1000946nv50_graph_isr_chid(struct drm_device *dev, u64 inst)
947{
948 struct drm_nouveau_private *dev_priv = dev->dev_private;
949 struct nouveau_channel *chan;
950 unsigned long flags;
951 int i;
952
953 spin_lock_irqsave(&dev_priv->channels.lock, flags);
954 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
955 chan = dev_priv->channels.ptr[i];
956 if (!chan || !chan->ramin)
957 continue;
958
959 if (inst == chan->ramin->vinst)
960 break;
961 }
962 spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
963 return i;
964}
965
966static void
967nv50_graph_isr(struct drm_device *dev)
968{
969 u32 stat;
970
971 while ((stat = nv_rd32(dev, 0x400100))) {
972 u64 inst = (u64)(nv_rd32(dev, 0x40032c) & 0x0fffffff) << 12;
973 u32 chid = nv50_graph_isr_chid(dev, inst);
974 u32 addr = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR);
975 u32 subc = (addr & 0x00070000) >> 16;
976 u32 mthd = (addr & 0x00001ffc);
977 u32 data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA);
978 u32 class = nv_rd32(dev, 0x400814);
979 u32 show = stat;
980
981 if (stat & 0x00000010) {
982 if (!nouveau_gpuobj_mthd_call2(dev, chid, class,
983 mthd, data))
984 show &= ~0x00000010;
985 }
986
987 if (stat & 0x00001000) {
988 nv_wr32(dev, 0x400500, 0x00000000);
989 nv_wr32(dev, 0x400100, 0x00001000);
990 nv_mask(dev, 0x40013c, 0x00001000, 0x00000000);
991 nv50_graph_context_switch(dev);
992 stat &= ~0x00001000;
993 show &= ~0x00001000;
994 }
995
996 show = (show && nouveau_ratelimit()) ? show : 0;
997
998 if (show & 0x00100000) {
999 u32 ecode = nv_rd32(dev, 0x400110);
1000 NV_INFO(dev, "PGRAPH - DATA_ERROR ");
1001 nouveau_enum_print(nv50_data_error_names, ecode);
1002 printk("\n");
1003 }
1004
1005 if (stat & 0x00200000) {
1006 if (!nv50_pgraph_trap_handler(dev, show, inst, chid))
1007 show &= ~0x00200000;
1008 }
1009
1010 nv_wr32(dev, 0x400100, stat);
1011 nv_wr32(dev, 0x400500, 0x00010001);
1012
1013 if (show) {
1014 NV_INFO(dev, "PGRAPH -");
1015 nouveau_bitfield_print(nv50_graph_intr, show);
1016 printk("\n");
1017 NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) subc %d "
1018 "class 0x%04x mthd 0x%04x data 0x%08x\n",
1019 chid, inst, subc, class, mthd, data);
Ben Skeggs6fdb3832011-03-08 09:57:17 +10001020 nv50_fb_vm_trap(dev, 1);
Ben Skeggs274fec92010-11-03 13:16:18 +10001021 }
1022 }
1023
1024 if (nv_rd32(dev, 0x400824) & (1 << 31))
1025 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) & ~(1 << 31));
1026}
Ben Skeggs2703c212011-04-01 09:50:18 +10001027
1028static void
1029nv50_graph_destroy(struct drm_device *dev, int engine)
1030{
1031 struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
1032
1033 NVOBJ_ENGINE_DEL(dev, GR);
1034
1035 nouveau_irq_unregister(dev, 12);
1036 kfree(pgraph);
1037}
1038
1039int
1040nv50_graph_create(struct drm_device *dev)
1041{
1042 struct drm_nouveau_private *dev_priv = dev->dev_private;
1043 struct nv50_graph_engine *pgraph;
1044 struct nouveau_grctx ctx = {};
1045 int ret;
1046
1047 pgraph = kzalloc(sizeof(*pgraph),GFP_KERNEL);
1048 if (!pgraph)
1049 return -ENOMEM;
1050
1051 ctx.dev = dev;
1052 ctx.mode = NOUVEAU_GRCTX_PROG;
1053 ctx.data = pgraph->ctxprog;
1054 ctx.ctxprog_max = ARRAY_SIZE(pgraph->ctxprog);
1055
1056 ret = nv50_grctx_init(&ctx);
1057 if (ret) {
1058 NV_ERROR(dev, "PGRAPH: ctxprog build failed\n");
Ben Skeggs2703c212011-04-01 09:50:18 +10001059 kfree(pgraph);
1060 return 0;
1061 }
1062
1063 pgraph->grctx_size = ctx.ctxvals_pos * 4;
1064 pgraph->ctxprog_size = ctx.ctxprog_len;
1065
1066 pgraph->base.destroy = nv50_graph_destroy;
1067 pgraph->base.init = nv50_graph_init;
1068 pgraph->base.fini = nv50_graph_fini;
1069 pgraph->base.context_new = nv50_graph_context_new;
1070 pgraph->base.context_del = nv50_graph_context_del;
1071 pgraph->base.object_new = nv50_graph_object_new;
1072 if (dev_priv->chipset == 0x50 || dev_priv->chipset == 0xac)
1073 pgraph->base.tlb_flush = nv50_graph_tlb_flush;
1074 else
1075 pgraph->base.tlb_flush = nv84_graph_tlb_flush;
1076
1077 nouveau_irq_register(dev, 12, nv50_graph_isr);
1078
1079 /* NVSW really doesn't live here... */
1080 NVOBJ_CLASS(dev, 0x506e, SW); /* nvsw */
1081 NVOBJ_MTHD (dev, 0x506e, 0x018c, nv50_graph_nvsw_dma_vblsem);
1082 NVOBJ_MTHD (dev, 0x506e, 0x0400, nv50_graph_nvsw_vblsem_offset);
1083 NVOBJ_MTHD (dev, 0x506e, 0x0404, nv50_graph_nvsw_vblsem_release_val);
1084 NVOBJ_MTHD (dev, 0x506e, 0x0408, nv50_graph_nvsw_vblsem_release);
1085 NVOBJ_MTHD (dev, 0x506e, 0x0500, nv50_graph_nvsw_mthd_page_flip);
1086
1087 NVOBJ_ENGINE_ADD(dev, GR, &pgraph->base);
1088 NVOBJ_CLASS(dev, 0x0030, GR); /* null */
1089 NVOBJ_CLASS(dev, 0x5039, GR); /* m2mf */
1090 NVOBJ_CLASS(dev, 0x502d, GR); /* 2d */
1091
1092 /* tesla */
1093 if (dev_priv->chipset == 0x50)
1094 NVOBJ_CLASS(dev, 0x5097, GR); /* tesla (nv50) */
1095 else
1096 if (dev_priv->chipset < 0xa0)
1097 NVOBJ_CLASS(dev, 0x8297, GR); /* tesla (nv8x/nv9x) */
1098 else {
1099 switch (dev_priv->chipset) {
1100 case 0xa0:
1101 case 0xaa:
1102 case 0xac:
1103 NVOBJ_CLASS(dev, 0x8397, GR);
1104 break;
1105 case 0xa3:
1106 case 0xa5:
1107 case 0xa8:
1108 NVOBJ_CLASS(dev, 0x8597, GR);
1109 break;
1110 case 0xaf:
1111 NVOBJ_CLASS(dev, 0x8697, GR);
1112 break;
1113 }
1114 }
1115
1116 /* compute */
1117 NVOBJ_CLASS(dev, 0x50c0, GR);
1118 if (dev_priv->chipset > 0xa0 &&
1119 dev_priv->chipset != 0xaa &&
1120 dev_priv->chipset != 0xac)
1121 NVOBJ_CLASS(dev, 0x85c0, GR);
1122
1123 return 0;
1124}