blob: a4fa9e14d66d95d3c6b5e56036806ae33e9adcf5 [file] [log] [blame]
Ben Skeggs6ee73862009-12-11 19:24:15 +10001/*
2 * Copyright (C) 2006 Ben Skeggs.
3 *
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 */
27
28/*
29 * Authors:
30 * Ben Skeggs <darktama@iinet.net.au>
31 */
32
33#include "drmP.h"
34#include "drm.h"
35#include "nouveau_drm.h"
36#include "nouveau_drv.h"
37#include "nouveau_reg.h"
Ben Skeggsa8eaebc2010-09-01 15:24:31 +100038#include "nouveau_ramht.h"
Ben Skeggs6ee73862009-12-11 19:24:15 +100039#include <linux/ratelimit.h>
40
41/* needed for hotplug irq */
42#include "nouveau_connector.h"
43#include "nv50_display.h"
44
Jiri Slabyda3bd822010-10-05 15:07:33 +020045static DEFINE_RATELIMIT_STATE(nouveau_ratelimit_state, 3 * HZ, 20);
46
47static int nouveau_ratelimit(void)
48{
49 return __ratelimit(&nouveau_ratelimit_state);
50}
51
Ben Skeggs6ee73862009-12-11 19:24:15 +100052void
53nouveau_irq_preinstall(struct drm_device *dev)
54{
55 struct drm_nouveau_private *dev_priv = dev->dev_private;
56
57 /* Master disable */
58 nv_wr32(dev, NV03_PMC_INTR_EN_0, 0);
59
Ben Skeggs4b223ee2010-08-03 10:00:56 +100060 if (dev_priv->card_type >= NV_50) {
Ben Skeggs6ee73862009-12-11 19:24:15 +100061 INIT_WORK(&dev_priv->irq_work, nv50_display_irq_handler_bh);
Ben Skeggsa5acac62010-03-30 15:14:41 +100062 INIT_WORK(&dev_priv->hpd_work, nv50_display_irq_hotplug_bh);
Andy Lutomirskiab838332010-11-16 18:40:52 -050063 spin_lock_init(&dev_priv->hpd_state.lock);
Ben Skeggs6ee73862009-12-11 19:24:15 +100064 INIT_LIST_HEAD(&dev_priv->vbl_waiting);
65 }
66}
67
68int
69nouveau_irq_postinstall(struct drm_device *dev)
70{
71 /* Master enable */
72 nv_wr32(dev, NV03_PMC_INTR_EN_0, NV_PMC_INTR_EN_0_MASTER_ENABLE);
73 return 0;
74}
75
76void
77nouveau_irq_uninstall(struct drm_device *dev)
78{
79 /* Master disable */
80 nv_wr32(dev, NV03_PMC_INTR_EN_0, 0);
81}
82
83static int
84nouveau_call_method(struct nouveau_channel *chan, int class, int mthd, int data)
85{
86 struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
87 struct nouveau_pgraph_object_method *grm;
88 struct nouveau_pgraph_object_class *grc;
89
90 grc = dev_priv->engine.graph.grclass;
91 while (grc->id) {
92 if (grc->id == class)
93 break;
94 grc++;
95 }
96
97 if (grc->id != class || !grc->methods)
98 return -ENOENT;
99
100 grm = grc->methods;
101 while (grm->id) {
102 if (grm->id == mthd)
103 return grm->exec(chan, class, mthd, data);
104 grm++;
105 }
106
107 return -ENOENT;
108}
109
110static bool
Ben Skeggs7c74cbd2010-09-23 11:03:01 +1000111nouveau_fifo_swmthd(struct drm_device *dev, u32 chid, u32 addr, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000112{
Ben Skeggs7c74cbd2010-09-23 11:03:01 +1000113 struct drm_nouveau_private *dev_priv = dev->dev_private;
114 struct nouveau_channel *chan = NULL;
115 struct nouveau_gpuobj *obj;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000116 const int subc = (addr >> 13) & 0x7;
117 const int mthd = addr & 0x1ffc;
Ben Skeggs7c74cbd2010-09-23 11:03:01 +1000118 bool handled = false;
119 u32 engine;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000120
Ben Skeggs7c74cbd2010-09-23 11:03:01 +1000121 if (likely(chid >= 0 && chid < dev_priv->engine.fifo.channels))
122 chan = dev_priv->fifos[chid];
123 if (unlikely(!chan))
124 return false;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000125
Ben Skeggs7c74cbd2010-09-23 11:03:01 +1000126 switch (mthd) {
127 case 0x0000: /* bind object to subchannel */
128 obj = nouveau_ramht_find(chan, data);
129 if (unlikely(!obj || obj->engine != NVOBJ_ENGINE_SW))
130 break;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000131
Ben Skeggs7c74cbd2010-09-23 11:03:01 +1000132 chan->sw_subchannel[subc] = obj->class;
133 engine = 0x0000000f << (subc * 4);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000134
Ben Skeggs7c74cbd2010-09-23 11:03:01 +1000135 nv_mask(dev, NV04_PFIFO_CACHE1_ENGINE, engine, 0x00000000);
136 handled = true;
137 break;
138 default:
139 engine = nv_rd32(dev, NV04_PFIFO_CACHE1_ENGINE);
140 if (unlikely(((engine >> (subc * 4)) & 0xf) != 0))
141 break;
142
143 if (!nouveau_call_method(chan, chan->sw_subchannel[subc],
144 mthd, data))
145 handled = true;
146 break;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000147 }
148
Ben Skeggs7c74cbd2010-09-23 11:03:01 +1000149 return handled;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000150}
151
152static void
153nouveau_fifo_irq_handler(struct drm_device *dev)
154{
155 struct drm_nouveau_private *dev_priv = dev->dev_private;
156 struct nouveau_engine *engine = &dev_priv->engine;
157 uint32_t status, reassign;
158 int cnt = 0;
159
160 reassign = nv_rd32(dev, NV03_PFIFO_CACHES) & 1;
161 while ((status = nv_rd32(dev, NV03_PFIFO_INTR_0)) && (cnt++ < 100)) {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000162 uint32_t chid, get;
163
164 nv_wr32(dev, NV03_PFIFO_CACHES, 0);
165
166 chid = engine->fifo.channel_id(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000167 get = nv_rd32(dev, NV03_PFIFO_CACHE1_GET);
168
169 if (status & NV_PFIFO_INTR_CACHE_ERROR) {
170 uint32_t mthd, data;
171 int ptr;
172
173 /* NV_PFIFO_CACHE1_GET actually goes to 0xffc before
174 * wrapping on my G80 chips, but CACHE1 isn't big
175 * enough for this much data.. Tests show that it
176 * wraps around to the start at GET=0x800.. No clue
177 * as to why..
178 */
179 ptr = (get & 0x7ff) >> 2;
180
181 if (dev_priv->card_type < NV_40) {
182 mthd = nv_rd32(dev,
183 NV04_PFIFO_CACHE1_METHOD(ptr));
184 data = nv_rd32(dev,
185 NV04_PFIFO_CACHE1_DATA(ptr));
186 } else {
187 mthd = nv_rd32(dev,
188 NV40_PFIFO_CACHE1_METHOD(ptr));
189 data = nv_rd32(dev,
190 NV40_PFIFO_CACHE1_DATA(ptr));
191 }
192
Ben Skeggs7c74cbd2010-09-23 11:03:01 +1000193 if (!nouveau_fifo_swmthd(dev, chid, mthd, data)) {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000194 NV_INFO(dev, "PFIFO_CACHE_ERROR - Ch %d/%d "
195 "Mthd 0x%04x Data 0x%08x\n",
196 chid, (mthd >> 13) & 7, mthd & 0x1ffc,
197 data);
198 }
199
200 nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_PUSH, 0);
201 nv_wr32(dev, NV03_PFIFO_INTR_0,
202 NV_PFIFO_INTR_CACHE_ERROR);
203
204 nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH0,
205 nv_rd32(dev, NV03_PFIFO_CACHE1_PUSH0) & ~1);
206 nv_wr32(dev, NV03_PFIFO_CACHE1_GET, get + 4);
207 nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH0,
208 nv_rd32(dev, NV03_PFIFO_CACHE1_PUSH0) | 1);
209 nv_wr32(dev, NV04_PFIFO_CACHE1_HASH, 0);
210
211 nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_PUSH,
212 nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_PUSH) | 1);
213 nv_wr32(dev, NV04_PFIFO_CACHE1_PULL0, 1);
214
215 status &= ~NV_PFIFO_INTR_CACHE_ERROR;
216 }
217
218 if (status & NV_PFIFO_INTR_DMA_PUSHER) {
Francisco Jerezcbab95db2010-10-11 03:43:58 +0200219 u32 dma_get = nv_rd32(dev, 0x003244);
220 u32 dma_put = nv_rd32(dev, 0x003240);
Ben Skeggse071f8c2010-09-08 15:40:30 +1000221 u32 push = nv_rd32(dev, 0x003220);
222 u32 state = nv_rd32(dev, 0x003228);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000223
Ben Skeggse071f8c2010-09-08 15:40:30 +1000224 if (dev_priv->card_type == NV_50) {
225 u32 ho_get = nv_rd32(dev, 0x003328);
226 u32 ho_put = nv_rd32(dev, 0x003320);
227 u32 ib_get = nv_rd32(dev, 0x003334);
228 u32 ib_put = nv_rd32(dev, 0x003330);
229
Jiri Slabyda3bd822010-10-05 15:07:33 +0200230 if (nouveau_ratelimit())
231 NV_INFO(dev, "PFIFO_DMA_PUSHER - Ch %d Get 0x%02x%08x "
Ben Skeggse071f8c2010-09-08 15:40:30 +1000232 "Put 0x%02x%08x IbGet 0x%08x IbPut 0x%08x "
233 "State 0x%08x Push 0x%08x\n",
Francisco Jerezcbab95db2010-10-11 03:43:58 +0200234 chid, ho_get, dma_get, ho_put,
235 dma_put, ib_get, ib_put, state,
236 push);
Ben Skeggse071f8c2010-09-08 15:40:30 +1000237
238 /* METHOD_COUNT, in DMA_STATE on earlier chipsets */
239 nv_wr32(dev, 0x003364, 0x00000000);
Francisco Jerezcbab95db2010-10-11 03:43:58 +0200240 if (dma_get != dma_put || ho_get != ho_put) {
241 nv_wr32(dev, 0x003244, dma_put);
Ben Skeggse071f8c2010-09-08 15:40:30 +1000242 nv_wr32(dev, 0x003328, ho_put);
243 } else
244 if (ib_get != ib_put) {
245 nv_wr32(dev, 0x003334, ib_put);
246 }
247 } else {
248 NV_INFO(dev, "PFIFO_DMA_PUSHER - Ch %d Get 0x%08x "
249 "Put 0x%08x State 0x%08x Push 0x%08x\n",
Francisco Jerezcbab95db2010-10-11 03:43:58 +0200250 chid, dma_get, dma_put, state, push);
Ben Skeggse071f8c2010-09-08 15:40:30 +1000251
Francisco Jerezcbab95db2010-10-11 03:43:58 +0200252 if (dma_get != dma_put)
253 nv_wr32(dev, 0x003244, dma_put);
Ben Skeggse071f8c2010-09-08 15:40:30 +1000254 }
255
256 nv_wr32(dev, 0x003228, 0x00000000);
257 nv_wr32(dev, 0x003220, 0x00000001);
258 nv_wr32(dev, 0x002100, NV_PFIFO_INTR_DMA_PUSHER);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000259 status &= ~NV_PFIFO_INTR_DMA_PUSHER;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000260 }
261
Francisco Jerez139295b2010-01-30 18:28:00 +0100262 if (status & NV_PFIFO_INTR_SEMAPHORE) {
263 uint32_t sem;
264
265 status &= ~NV_PFIFO_INTR_SEMAPHORE;
266 nv_wr32(dev, NV03_PFIFO_INTR_0,
267 NV_PFIFO_INTR_SEMAPHORE);
268
269 sem = nv_rd32(dev, NV10_PFIFO_CACHE1_SEMAPHORE);
270 nv_wr32(dev, NV10_PFIFO_CACHE1_SEMAPHORE, sem | 0x1);
271
272 nv_wr32(dev, NV03_PFIFO_CACHE1_GET, get + 4);
273 nv_wr32(dev, NV04_PFIFO_CACHE1_PULL0, 1);
274 }
275
Ben Skeggs1da26562010-09-03 15:56:12 +1000276 if (dev_priv->card_type == NV_50) {
277 if (status & 0x00000010) {
278 nv50_fb_vm_trap(dev, 1, "PFIFO_BAR_FAULT");
279 status &= ~0x00000010;
280 nv_wr32(dev, 0x002100, 0x00000010);
281 }
282 }
283
Ben Skeggs6ee73862009-12-11 19:24:15 +1000284 if (status) {
Jiri Slabyda3bd822010-10-05 15:07:33 +0200285 if (nouveau_ratelimit())
286 NV_INFO(dev, "PFIFO_INTR 0x%08x - Ch %d\n",
287 status, chid);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000288 nv_wr32(dev, NV03_PFIFO_INTR_0, status);
289 status = 0;
290 }
291
292 nv_wr32(dev, NV03_PFIFO_CACHES, reassign);
293 }
294
295 if (status) {
296 NV_INFO(dev, "PFIFO still angry after %d spins, halt\n", cnt);
297 nv_wr32(dev, 0x2140, 0);
298 nv_wr32(dev, 0x140, 0);
299 }
300
301 nv_wr32(dev, NV03_PMC_INTR_0, NV_PMC_INTR_0_PFIFO_PENDING);
302}
303
304struct nouveau_bitfield_names {
305 uint32_t mask;
306 const char *name;
307};
308
309static struct nouveau_bitfield_names nstatus_names[] =
310{
311 { NV04_PGRAPH_NSTATUS_STATE_IN_USE, "STATE_IN_USE" },
312 { NV04_PGRAPH_NSTATUS_INVALID_STATE, "INVALID_STATE" },
313 { NV04_PGRAPH_NSTATUS_BAD_ARGUMENT, "BAD_ARGUMENT" },
314 { NV04_PGRAPH_NSTATUS_PROTECTION_FAULT, "PROTECTION_FAULT" }
315};
316
317static struct nouveau_bitfield_names nstatus_names_nv10[] =
318{
319 { NV10_PGRAPH_NSTATUS_STATE_IN_USE, "STATE_IN_USE" },
320 { NV10_PGRAPH_NSTATUS_INVALID_STATE, "INVALID_STATE" },
321 { NV10_PGRAPH_NSTATUS_BAD_ARGUMENT, "BAD_ARGUMENT" },
322 { NV10_PGRAPH_NSTATUS_PROTECTION_FAULT, "PROTECTION_FAULT" }
323};
324
325static struct nouveau_bitfield_names nsource_names[] =
326{
327 { NV03_PGRAPH_NSOURCE_NOTIFICATION, "NOTIFICATION" },
328 { NV03_PGRAPH_NSOURCE_DATA_ERROR, "DATA_ERROR" },
329 { NV03_PGRAPH_NSOURCE_PROTECTION_ERROR, "PROTECTION_ERROR" },
330 { NV03_PGRAPH_NSOURCE_RANGE_EXCEPTION, "RANGE_EXCEPTION" },
331 { NV03_PGRAPH_NSOURCE_LIMIT_COLOR, "LIMIT_COLOR" },
332 { NV03_PGRAPH_NSOURCE_LIMIT_ZETA, "LIMIT_ZETA" },
333 { NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD, "ILLEGAL_MTHD" },
334 { NV03_PGRAPH_NSOURCE_DMA_R_PROTECTION, "DMA_R_PROTECTION" },
335 { NV03_PGRAPH_NSOURCE_DMA_W_PROTECTION, "DMA_W_PROTECTION" },
336 { NV03_PGRAPH_NSOURCE_FORMAT_EXCEPTION, "FORMAT_EXCEPTION" },
337 { NV03_PGRAPH_NSOURCE_PATCH_EXCEPTION, "PATCH_EXCEPTION" },
338 { NV03_PGRAPH_NSOURCE_STATE_INVALID, "STATE_INVALID" },
339 { NV03_PGRAPH_NSOURCE_DOUBLE_NOTIFY, "DOUBLE_NOTIFY" },
340 { NV03_PGRAPH_NSOURCE_NOTIFY_IN_USE, "NOTIFY_IN_USE" },
341 { NV03_PGRAPH_NSOURCE_METHOD_CNT, "METHOD_CNT" },
342 { NV03_PGRAPH_NSOURCE_BFR_NOTIFICATION, "BFR_NOTIFICATION" },
343 { NV03_PGRAPH_NSOURCE_DMA_VTX_PROTECTION, "DMA_VTX_PROTECTION" },
344 { NV03_PGRAPH_NSOURCE_DMA_WIDTH_A, "DMA_WIDTH_A" },
345 { NV03_PGRAPH_NSOURCE_DMA_WIDTH_B, "DMA_WIDTH_B" },
346};
347
348static void
349nouveau_print_bitfield_names_(uint32_t value,
350 const struct nouveau_bitfield_names *namelist,
351 const int namelist_len)
352{
353 /*
354 * Caller must have already printed the KERN_* log level for us.
355 * Also the caller is responsible for adding the newline.
356 */
357 int i;
358 for (i = 0; i < namelist_len; ++i) {
359 uint32_t mask = namelist[i].mask;
360 if (value & mask) {
361 printk(" %s", namelist[i].name);
362 value &= ~mask;
363 }
364 }
365 if (value)
366 printk(" (unknown bits 0x%08x)", value);
367}
368#define nouveau_print_bitfield_names(val, namelist) \
369 nouveau_print_bitfield_names_((val), (namelist), ARRAY_SIZE(namelist))
370
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000371struct nouveau_enum_names {
372 uint32_t value;
373 const char *name;
374};
375
376static void
377nouveau_print_enum_names_(uint32_t value,
378 const struct nouveau_enum_names *namelist,
379 const int namelist_len)
380{
381 /*
382 * Caller must have already printed the KERN_* log level for us.
383 * Also the caller is responsible for adding the newline.
384 */
385 int i;
386 for (i = 0; i < namelist_len; ++i) {
387 if (value == namelist[i].value) {
388 printk("%s", namelist[i].name);
389 return;
390 }
391 }
392 printk("unknown value 0x%08x", value);
393}
394#define nouveau_print_enum_names(val, namelist) \
395 nouveau_print_enum_names_((val), (namelist), ARRAY_SIZE(namelist))
Ben Skeggs6ee73862009-12-11 19:24:15 +1000396
397static int
398nouveau_graph_chid_from_grctx(struct drm_device *dev)
399{
400 struct drm_nouveau_private *dev_priv = dev->dev_private;
401 uint32_t inst;
402 int i;
403
404 if (dev_priv->card_type < NV_40)
405 return dev_priv->engine.fifo.channels;
406 else
407 if (dev_priv->card_type < NV_50) {
408 inst = (nv_rd32(dev, 0x40032c) & 0xfffff) << 4;
409
410 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
411 struct nouveau_channel *chan = dev_priv->fifos[i];
412
413 if (!chan || !chan->ramin_grctx)
414 continue;
415
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000416 if (inst == chan->ramin_grctx->pinst)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000417 break;
418 }
419 } else {
420 inst = (nv_rd32(dev, 0x40032c) & 0xfffff) << 12;
421
422 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
423 struct nouveau_channel *chan = dev_priv->fifos[i];
424
425 if (!chan || !chan->ramin)
426 continue;
427
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000428 if (inst == chan->ramin->vinst)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000429 break;
430 }
431 }
432
433
434 return i;
435}
436
437static int
438nouveau_graph_trapped_channel(struct drm_device *dev, int *channel_ret)
439{
440 struct drm_nouveau_private *dev_priv = dev->dev_private;
441 struct nouveau_engine *engine = &dev_priv->engine;
442 int channel;
443
444 if (dev_priv->card_type < NV_10)
445 channel = (nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR) >> 24) & 0xf;
446 else
447 if (dev_priv->card_type < NV_40)
448 channel = (nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR) >> 20) & 0x1f;
449 else
450 channel = nouveau_graph_chid_from_grctx(dev);
451
452 if (channel >= engine->fifo.channels || !dev_priv->fifos[channel]) {
453 NV_ERROR(dev, "AIII, invalid/inactive channel id %d\n", channel);
454 return -EINVAL;
455 }
456
457 *channel_ret = channel;
458 return 0;
459}
460
461struct nouveau_pgraph_trap {
462 int channel;
463 int class;
464 int subc, mthd, size;
465 uint32_t data, data2;
466 uint32_t nsource, nstatus;
467};
468
469static void
470nouveau_graph_trap_info(struct drm_device *dev,
471 struct nouveau_pgraph_trap *trap)
472{
473 struct drm_nouveau_private *dev_priv = dev->dev_private;
474 uint32_t address;
475
476 trap->nsource = trap->nstatus = 0;
477 if (dev_priv->card_type < NV_50) {
478 trap->nsource = nv_rd32(dev, NV03_PGRAPH_NSOURCE);
479 trap->nstatus = nv_rd32(dev, NV03_PGRAPH_NSTATUS);
480 }
481
482 if (nouveau_graph_trapped_channel(dev, &trap->channel))
483 trap->channel = -1;
484 address = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR);
485
486 trap->mthd = address & 0x1FFC;
487 trap->data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA);
488 if (dev_priv->card_type < NV_10) {
489 trap->subc = (address >> 13) & 0x7;
490 } else {
491 trap->subc = (address >> 16) & 0x7;
492 trap->data2 = nv_rd32(dev, NV10_PGRAPH_TRAPPED_DATA_HIGH);
493 }
494
495 if (dev_priv->card_type < NV_10)
496 trap->class = nv_rd32(dev, 0x400180 + trap->subc*4) & 0xFF;
497 else if (dev_priv->card_type < NV_40)
498 trap->class = nv_rd32(dev, 0x400160 + trap->subc*4) & 0xFFF;
499 else if (dev_priv->card_type < NV_50)
500 trap->class = nv_rd32(dev, 0x400160 + trap->subc*4) & 0xFFFF;
501 else
502 trap->class = nv_rd32(dev, 0x400814);
503}
504
505static void
506nouveau_graph_dump_trap_info(struct drm_device *dev, const char *id,
507 struct nouveau_pgraph_trap *trap)
508{
509 struct drm_nouveau_private *dev_priv = dev->dev_private;
510 uint32_t nsource = trap->nsource, nstatus = trap->nstatus;
511
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000512 if (dev_priv->card_type < NV_50) {
513 NV_INFO(dev, "%s - nSource:", id);
514 nouveau_print_bitfield_names(nsource, nsource_names);
515 printk(", nStatus:");
516 if (dev_priv->card_type < NV_10)
517 nouveau_print_bitfield_names(nstatus, nstatus_names);
518 else
519 nouveau_print_bitfield_names(nstatus, nstatus_names_nv10);
520 printk("\n");
521 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000522
523 NV_INFO(dev, "%s - Ch %d/%d Class 0x%04x Mthd 0x%04x "
524 "Data 0x%08x:0x%08x\n",
525 id, trap->channel, trap->subc,
526 trap->class, trap->mthd,
527 trap->data2, trap->data);
528}
529
530static int
531nouveau_pgraph_intr_swmthd(struct drm_device *dev,
532 struct nouveau_pgraph_trap *trap)
533{
534 struct drm_nouveau_private *dev_priv = dev->dev_private;
535
536 if (trap->channel < 0 ||
537 trap->channel >= dev_priv->engine.fifo.channels ||
538 !dev_priv->fifos[trap->channel])
539 return -ENODEV;
540
541 return nouveau_call_method(dev_priv->fifos[trap->channel],
542 trap->class, trap->mthd, trap->data);
543}
544
545static inline void
546nouveau_pgraph_intr_notify(struct drm_device *dev, uint32_t nsource)
547{
548 struct nouveau_pgraph_trap trap;
549 int unhandled = 0;
550
551 nouveau_graph_trap_info(dev, &trap);
552
553 if (nsource & NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD) {
554 if (nouveau_pgraph_intr_swmthd(dev, &trap))
555 unhandled = 1;
556 } else {
557 unhandled = 1;
558 }
559
560 if (unhandled)
561 nouveau_graph_dump_trap_info(dev, "PGRAPH_NOTIFY", &trap);
562}
563
Ben Skeggs6ee73862009-12-11 19:24:15 +1000564
565static inline void
566nouveau_pgraph_intr_error(struct drm_device *dev, uint32_t nsource)
567{
568 struct nouveau_pgraph_trap trap;
569 int unhandled = 0;
570
571 nouveau_graph_trap_info(dev, &trap);
572 trap.nsource = nsource;
573
574 if (nsource & NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD) {
575 if (nouveau_pgraph_intr_swmthd(dev, &trap))
576 unhandled = 1;
Luca Barbierid051bbb2010-01-16 15:27:51 +0100577 } else if (nsource & NV03_PGRAPH_NSOURCE_DMA_VTX_PROTECTION) {
578 uint32_t v = nv_rd32(dev, 0x402000);
579 nv_wr32(dev, 0x402000, v);
580
581 /* dump the error anyway for now: it's useful for
582 Gallium development */
583 unhandled = 1;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000584 } else {
585 unhandled = 1;
586 }
587
588 if (unhandled && nouveau_ratelimit())
589 nouveau_graph_dump_trap_info(dev, "PGRAPH_ERROR", &trap);
590}
591
592static inline void
593nouveau_pgraph_intr_context_switch(struct drm_device *dev)
594{
595 struct drm_nouveau_private *dev_priv = dev->dev_private;
596 struct nouveau_engine *engine = &dev_priv->engine;
597 uint32_t chid;
598
599 chid = engine->fifo.channel_id(dev);
600 NV_DEBUG(dev, "PGRAPH context switch interrupt channel %x\n", chid);
601
602 switch (dev_priv->card_type) {
603 case NV_04:
604 nv04_graph_context_switch(dev);
605 break;
606 case NV_10:
607 nv10_graph_context_switch(dev);
608 break;
609 default:
610 NV_ERROR(dev, "Context switch not implemented\n");
611 break;
612 }
613}
614
615static void
616nouveau_pgraph_irq_handler(struct drm_device *dev)
617{
618 uint32_t status;
619
620 while ((status = nv_rd32(dev, NV03_PGRAPH_INTR))) {
621 uint32_t nsource = nv_rd32(dev, NV03_PGRAPH_NSOURCE);
622
623 if (status & NV_PGRAPH_INTR_NOTIFY) {
624 nouveau_pgraph_intr_notify(dev, nsource);
625
626 status &= ~NV_PGRAPH_INTR_NOTIFY;
627 nv_wr32(dev, NV03_PGRAPH_INTR, NV_PGRAPH_INTR_NOTIFY);
628 }
629
630 if (status & NV_PGRAPH_INTR_ERROR) {
631 nouveau_pgraph_intr_error(dev, nsource);
632
633 status &= ~NV_PGRAPH_INTR_ERROR;
634 nv_wr32(dev, NV03_PGRAPH_INTR, NV_PGRAPH_INTR_ERROR);
635 }
636
637 if (status & NV_PGRAPH_INTR_CONTEXT_SWITCH) {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000638 status &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH;
639 nv_wr32(dev, NV03_PGRAPH_INTR,
640 NV_PGRAPH_INTR_CONTEXT_SWITCH);
Francisco Jerez308dceb2010-08-04 04:41:55 +0200641
642 nouveau_pgraph_intr_context_switch(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000643 }
644
645 if (status) {
646 NV_INFO(dev, "Unhandled PGRAPH_INTR - 0x%08x\n", status);
647 nv_wr32(dev, NV03_PGRAPH_INTR, status);
648 }
649
650 if ((nv_rd32(dev, NV04_PGRAPH_FIFO) & (1 << 0)) == 0)
651 nv_wr32(dev, NV04_PGRAPH_FIFO, 1);
652 }
653
654 nv_wr32(dev, NV03_PMC_INTR_0, NV_PMC_INTR_0_PGRAPH_PENDING);
655}
656
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000657static struct nouveau_enum_names nv50_mp_exec_error_names[] =
658{
659 { 3, "STACK_UNDERFLOW" },
660 { 4, "QUADON_ACTIVE" },
661 { 8, "TIMEOUT" },
662 { 0x10, "INVALID_OPCODE" },
663 { 0x40, "BREAKPOINT" },
664};
665
666static void
667nv50_pgraph_mp_trap(struct drm_device *dev, int tpid, int display)
668{
669 struct drm_nouveau_private *dev_priv = dev->dev_private;
670 uint32_t units = nv_rd32(dev, 0x1540);
671 uint32_t addr, mp10, status, pc, oplow, ophigh;
672 int i;
673 int mps = 0;
674 for (i = 0; i < 4; i++) {
675 if (!(units & 1 << (i+24)))
676 continue;
677 if (dev_priv->chipset < 0xa0)
678 addr = 0x408200 + (tpid << 12) + (i << 7);
679 else
680 addr = 0x408100 + (tpid << 11) + (i << 7);
681 mp10 = nv_rd32(dev, addr + 0x10);
682 status = nv_rd32(dev, addr + 0x14);
683 if (!status)
684 continue;
685 if (display) {
686 nv_rd32(dev, addr + 0x20);
687 pc = nv_rd32(dev, addr + 0x24);
688 oplow = nv_rd32(dev, addr + 0x70);
689 ophigh= nv_rd32(dev, addr + 0x74);
690 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - "
691 "TP %d MP %d: ", tpid, i);
692 nouveau_print_enum_names(status,
693 nv50_mp_exec_error_names);
694 printk(" at %06x warp %d, opcode %08x %08x\n",
695 pc&0xffffff, pc >> 24,
696 oplow, ophigh);
697 }
698 nv_wr32(dev, addr + 0x10, mp10);
699 nv_wr32(dev, addr + 0x14, 0);
700 mps++;
701 }
702 if (!mps && display)
703 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - TP %d: "
704 "No MPs claiming errors?\n", tpid);
705}
706
707static void
708nv50_pgraph_tp_trap(struct drm_device *dev, int type, uint32_t ustatus_old,
709 uint32_t ustatus_new, int display, const char *name)
710{
711 struct drm_nouveau_private *dev_priv = dev->dev_private;
712 int tps = 0;
713 uint32_t units = nv_rd32(dev, 0x1540);
714 int i, r;
715 uint32_t ustatus_addr, ustatus;
716 for (i = 0; i < 16; i++) {
717 if (!(units & (1 << i)))
718 continue;
719 if (dev_priv->chipset < 0xa0)
720 ustatus_addr = ustatus_old + (i << 12);
721 else
722 ustatus_addr = ustatus_new + (i << 11);
723 ustatus = nv_rd32(dev, ustatus_addr) & 0x7fffffff;
724 if (!ustatus)
725 continue;
726 tps++;
727 switch (type) {
728 case 6: /* texture error... unknown for now */
Ben Skeggsd96773e2010-09-03 15:46:58 +1000729 nv50_fb_vm_trap(dev, display, name);
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000730 if (display) {
731 NV_ERROR(dev, "magic set %d:\n", i);
732 for (r = ustatus_addr + 4; r <= ustatus_addr + 0x10; r += 4)
733 NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r,
734 nv_rd32(dev, r));
735 }
736 break;
737 case 7: /* MP error */
738 if (ustatus & 0x00010000) {
739 nv50_pgraph_mp_trap(dev, i, display);
740 ustatus &= ~0x00010000;
741 }
742 break;
743 case 8: /* TPDMA error */
744 {
745 uint32_t e0c = nv_rd32(dev, ustatus_addr + 4);
746 uint32_t e10 = nv_rd32(dev, ustatus_addr + 8);
747 uint32_t e14 = nv_rd32(dev, ustatus_addr + 0xc);
748 uint32_t e18 = nv_rd32(dev, ustatus_addr + 0x10);
749 uint32_t e1c = nv_rd32(dev, ustatus_addr + 0x14);
750 uint32_t e20 = nv_rd32(dev, ustatus_addr + 0x18);
751 uint32_t e24 = nv_rd32(dev, ustatus_addr + 0x1c);
Ben Skeggsd96773e2010-09-03 15:46:58 +1000752 nv50_fb_vm_trap(dev, display, name);
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000753 /* 2d engine destination */
754 if (ustatus & 0x00000010) {
755 if (display) {
756 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - Unknown fault at address %02x%08x\n",
757 i, e14, e10);
758 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
759 i, e0c, e18, e1c, e20, e24);
760 }
761 ustatus &= ~0x00000010;
762 }
763 /* Render target */
764 if (ustatus & 0x00000040) {
765 if (display) {
766 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - Unknown fault at address %02x%08x\n",
767 i, e14, e10);
768 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
769 i, e0c, e18, e1c, e20, e24);
770 }
771 ustatus &= ~0x00000040;
772 }
773 /* CUDA memory: l[], g[] or stack. */
774 if (ustatus & 0x00000080) {
775 if (display) {
776 if (e18 & 0x80000000) {
777 /* g[] read fault? */
778 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global read fault at address %02x%08x\n",
779 i, e14, e10 | ((e18 >> 24) & 0x1f));
780 e18 &= ~0x1f000000;
781 } else if (e18 & 0xc) {
782 /* g[] write fault? */
783 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global write fault at address %02x%08x\n",
784 i, e14, e10 | ((e18 >> 7) & 0x1f));
785 e18 &= ~0x00000f80;
786 } else {
787 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Unknown CUDA fault at address %02x%08x\n",
788 i, e14, e10);
789 }
790 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
791 i, e0c, e18, e1c, e20, e24);
792 }
793 ustatus &= ~0x00000080;
794 }
795 }
796 break;
797 }
798 if (ustatus) {
799 if (display)
800 NV_INFO(dev, "%s - TP%d: Unhandled ustatus 0x%08x\n", name, i, ustatus);
801 }
802 nv_wr32(dev, ustatus_addr, 0xc0000000);
803 }
804
805 if (!tps && display)
806 NV_INFO(dev, "%s - No TPs claiming errors?\n", name);
807}
808
809static void
810nv50_pgraph_trap_handler(struct drm_device *dev)
811{
812 struct nouveau_pgraph_trap trap;
813 uint32_t status = nv_rd32(dev, 0x400108);
814 uint32_t ustatus;
815 int display = nouveau_ratelimit();
816
817
818 if (!status && display) {
819 nouveau_graph_trap_info(dev, &trap);
820 nouveau_graph_dump_trap_info(dev, "PGRAPH_TRAP", &trap);
821 NV_INFO(dev, "PGRAPH_TRAP - no units reporting traps?\n");
822 }
823
824 /* DISPATCH: Relays commands to other units and handles NOTIFY,
825 * COND, QUERY. If you get a trap from it, the command is still stuck
826 * in DISPATCH and you need to do something about it. */
827 if (status & 0x001) {
828 ustatus = nv_rd32(dev, 0x400804) & 0x7fffffff;
829 if (!ustatus && display) {
830 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - no ustatus?\n");
831 }
832
833 /* Known to be triggered by screwed up NOTIFY and COND... */
834 if (ustatus & 0x00000001) {
Ben Skeggsd96773e2010-09-03 15:46:58 +1000835 nv50_fb_vm_trap(dev, display, "PGRAPH_TRAP_DISPATCH_FAULT");
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000836 nv_wr32(dev, 0x400500, 0);
837 if (nv_rd32(dev, 0x400808) & 0x80000000) {
838 if (display) {
839 if (nouveau_graph_trapped_channel(dev, &trap.channel))
840 trap.channel = -1;
841 trap.class = nv_rd32(dev, 0x400814);
842 trap.mthd = nv_rd32(dev, 0x400808) & 0x1ffc;
843 trap.subc = (nv_rd32(dev, 0x400808) >> 16) & 0x7;
844 trap.data = nv_rd32(dev, 0x40080c);
845 trap.data2 = nv_rd32(dev, 0x400810);
846 nouveau_graph_dump_trap_info(dev,
847 "PGRAPH_TRAP_DISPATCH_FAULT", &trap);
848 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_FAULT - 400808: %08x\n", nv_rd32(dev, 0x400808));
849 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_FAULT - 400848: %08x\n", nv_rd32(dev, 0x400848));
850 }
851 nv_wr32(dev, 0x400808, 0);
852 } else if (display) {
853 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_FAULT - No stuck command?\n");
854 }
855 nv_wr32(dev, 0x4008e8, nv_rd32(dev, 0x4008e8) & 3);
856 nv_wr32(dev, 0x400848, 0);
857 ustatus &= ~0x00000001;
858 }
859 if (ustatus & 0x00000002) {
Ben Skeggsd96773e2010-09-03 15:46:58 +1000860 nv50_fb_vm_trap(dev, display, "PGRAPH_TRAP_DISPATCH_QUERY");
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000861 nv_wr32(dev, 0x400500, 0);
862 if (nv_rd32(dev, 0x40084c) & 0x80000000) {
863 if (display) {
864 if (nouveau_graph_trapped_channel(dev, &trap.channel))
865 trap.channel = -1;
866 trap.class = nv_rd32(dev, 0x400814);
867 trap.mthd = nv_rd32(dev, 0x40084c) & 0x1ffc;
868 trap.subc = (nv_rd32(dev, 0x40084c) >> 16) & 0x7;
869 trap.data = nv_rd32(dev, 0x40085c);
870 trap.data2 = 0;
871 nouveau_graph_dump_trap_info(dev,
872 "PGRAPH_TRAP_DISPATCH_QUERY", &trap);
873 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_QUERY - 40084c: %08x\n", nv_rd32(dev, 0x40084c));
874 }
875 nv_wr32(dev, 0x40084c, 0);
876 } else if (display) {
877 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_QUERY - No stuck command?\n");
878 }
879 ustatus &= ~0x00000002;
880 }
881 if (ustatus && display)
882 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - Unhandled ustatus 0x%08x\n", ustatus);
883 nv_wr32(dev, 0x400804, 0xc0000000);
884 nv_wr32(dev, 0x400108, 0x001);
885 status &= ~0x001;
886 }
887
888 /* TRAPs other than dispatch use the "normal" trap regs. */
889 if (status && display) {
890 nouveau_graph_trap_info(dev, &trap);
891 nouveau_graph_dump_trap_info(dev,
892 "PGRAPH_TRAP", &trap);
893 }
894
895 /* M2MF: Memory to memory copy engine. */
896 if (status & 0x002) {
897 ustatus = nv_rd32(dev, 0x406800) & 0x7fffffff;
898 if (!ustatus && display) {
899 NV_INFO(dev, "PGRAPH_TRAP_M2MF - no ustatus?\n");
900 }
901 if (ustatus & 0x00000001) {
Ben Skeggsd96773e2010-09-03 15:46:58 +1000902 nv50_fb_vm_trap(dev, display, "PGRAPH_TRAP_M2MF_NOTIFY");
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000903 ustatus &= ~0x00000001;
904 }
905 if (ustatus & 0x00000002) {
Ben Skeggsd96773e2010-09-03 15:46:58 +1000906 nv50_fb_vm_trap(dev, display, "PGRAPH_TRAP_M2MF_IN");
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000907 ustatus &= ~0x00000002;
908 }
909 if (ustatus & 0x00000004) {
Ben Skeggsd96773e2010-09-03 15:46:58 +1000910 nv50_fb_vm_trap(dev, display, "PGRAPH_TRAP_M2MF_OUT");
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000911 ustatus &= ~0x00000004;
912 }
913 NV_INFO (dev, "PGRAPH_TRAP_M2MF - %08x %08x %08x %08x\n",
914 nv_rd32(dev, 0x406804),
915 nv_rd32(dev, 0x406808),
916 nv_rd32(dev, 0x40680c),
917 nv_rd32(dev, 0x406810));
918 if (ustatus && display)
919 NV_INFO(dev, "PGRAPH_TRAP_M2MF - Unhandled ustatus 0x%08x\n", ustatus);
920 /* No sane way found yet -- just reset the bugger. */
921 nv_wr32(dev, 0x400040, 2);
922 nv_wr32(dev, 0x400040, 0);
923 nv_wr32(dev, 0x406800, 0xc0000000);
924 nv_wr32(dev, 0x400108, 0x002);
925 status &= ~0x002;
926 }
927
928 /* VFETCH: Fetches data from vertex buffers. */
929 if (status & 0x004) {
930 ustatus = nv_rd32(dev, 0x400c04) & 0x7fffffff;
931 if (!ustatus && display) {
932 NV_INFO(dev, "PGRAPH_TRAP_VFETCH - no ustatus?\n");
933 }
934 if (ustatus & 0x00000001) {
Ben Skeggsd96773e2010-09-03 15:46:58 +1000935 nv50_fb_vm_trap(dev, display, "PGRAPH_TRAP_VFETCH_FAULT");
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000936 NV_INFO (dev, "PGRAPH_TRAP_VFETCH_FAULT - %08x %08x %08x %08x\n",
937 nv_rd32(dev, 0x400c00),
938 nv_rd32(dev, 0x400c08),
939 nv_rd32(dev, 0x400c0c),
940 nv_rd32(dev, 0x400c10));
941 ustatus &= ~0x00000001;
942 }
943 if (ustatus && display)
944 NV_INFO(dev, "PGRAPH_TRAP_VFETCH - Unhandled ustatus 0x%08x\n", ustatus);
945 nv_wr32(dev, 0x400c04, 0xc0000000);
946 nv_wr32(dev, 0x400108, 0x004);
947 status &= ~0x004;
948 }
949
950 /* STRMOUT: DirectX streamout / OpenGL transform feedback. */
951 if (status & 0x008) {
952 ustatus = nv_rd32(dev, 0x401800) & 0x7fffffff;
953 if (!ustatus && display) {
954 NV_INFO(dev, "PGRAPH_TRAP_STRMOUT - no ustatus?\n");
955 }
956 if (ustatus & 0x00000001) {
Ben Skeggsd96773e2010-09-03 15:46:58 +1000957 nv50_fb_vm_trap(dev, display, "PGRAPH_TRAP_STRMOUT_FAULT");
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000958 NV_INFO (dev, "PGRAPH_TRAP_STRMOUT_FAULT - %08x %08x %08x %08x\n",
959 nv_rd32(dev, 0x401804),
960 nv_rd32(dev, 0x401808),
961 nv_rd32(dev, 0x40180c),
962 nv_rd32(dev, 0x401810));
963 ustatus &= ~0x00000001;
964 }
965 if (ustatus && display)
966 NV_INFO(dev, "PGRAPH_TRAP_STRMOUT - Unhandled ustatus 0x%08x\n", ustatus);
967 /* No sane way found yet -- just reset the bugger. */
968 nv_wr32(dev, 0x400040, 0x80);
969 nv_wr32(dev, 0x400040, 0);
970 nv_wr32(dev, 0x401800, 0xc0000000);
971 nv_wr32(dev, 0x400108, 0x008);
972 status &= ~0x008;
973 }
974
975 /* CCACHE: Handles code and c[] caches and fills them. */
976 if (status & 0x010) {
977 ustatus = nv_rd32(dev, 0x405018) & 0x7fffffff;
978 if (!ustatus && display) {
979 NV_INFO(dev, "PGRAPH_TRAP_CCACHE - no ustatus?\n");
980 }
981 if (ustatus & 0x00000001) {
Ben Skeggsd96773e2010-09-03 15:46:58 +1000982 nv50_fb_vm_trap(dev, display, "PGRAPH_TRAP_CCACHE_FAULT");
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000983 NV_INFO (dev, "PGRAPH_TRAP_CCACHE_FAULT - %08x %08x %08x %08x %08x %08x %08x\n",
984 nv_rd32(dev, 0x405800),
985 nv_rd32(dev, 0x405804),
986 nv_rd32(dev, 0x405808),
987 nv_rd32(dev, 0x40580c),
988 nv_rd32(dev, 0x405810),
989 nv_rd32(dev, 0x405814),
990 nv_rd32(dev, 0x40581c));
991 ustatus &= ~0x00000001;
992 }
993 if (ustatus && display)
994 NV_INFO(dev, "PGRAPH_TRAP_CCACHE - Unhandled ustatus 0x%08x\n", ustatus);
995 nv_wr32(dev, 0x405018, 0xc0000000);
996 nv_wr32(dev, 0x400108, 0x010);
997 status &= ~0x010;
998 }
999
1000 /* Unknown, not seen yet... 0x402000 is the only trap status reg
1001 * remaining, so try to handle it anyway. Perhaps related to that
1002 * unknown DMA slot on tesla? */
1003 if (status & 0x20) {
Ben Skeggsd96773e2010-09-03 15:46:58 +10001004 nv50_fb_vm_trap(dev, display, "PGRAPH_TRAP_UNKC04");
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001005 ustatus = nv_rd32(dev, 0x402000) & 0x7fffffff;
1006 if (display)
1007 NV_INFO(dev, "PGRAPH_TRAP_UNKC04 - Unhandled ustatus 0x%08x\n", ustatus);
1008 nv_wr32(dev, 0x402000, 0xc0000000);
1009 /* no status modifiction on purpose */
1010 }
1011
1012 /* TEXTURE: CUDA texturing units */
1013 if (status & 0x040) {
1014 nv50_pgraph_tp_trap (dev, 6, 0x408900, 0x408600, display,
1015 "PGRAPH_TRAP_TEXTURE");
1016 nv_wr32(dev, 0x400108, 0x040);
1017 status &= ~0x040;
1018 }
1019
1020 /* MP: CUDA execution engines. */
1021 if (status & 0x080) {
1022 nv50_pgraph_tp_trap (dev, 7, 0x408314, 0x40831c, display,
1023 "PGRAPH_TRAP_MP");
1024 nv_wr32(dev, 0x400108, 0x080);
1025 status &= ~0x080;
1026 }
1027
1028 /* TPDMA: Handles TP-initiated uncached memory accesses:
1029 * l[], g[], stack, 2d surfaces, render targets. */
1030 if (status & 0x100) {
1031 nv50_pgraph_tp_trap (dev, 8, 0x408e08, 0x408708, display,
1032 "PGRAPH_TRAP_TPDMA");
1033 nv_wr32(dev, 0x400108, 0x100);
1034 status &= ~0x100;
1035 }
1036
1037 if (status) {
1038 if (display)
1039 NV_INFO(dev, "PGRAPH_TRAP - Unknown trap 0x%08x\n",
1040 status);
1041 nv_wr32(dev, 0x400108, status);
1042 }
1043}
1044
1045/* There must be a *lot* of these. Will take some time to gather them up. */
1046static struct nouveau_enum_names nv50_data_error_names[] =
1047{
1048 { 4, "INVALID_VALUE" },
1049 { 5, "INVALID_ENUM" },
1050 { 8, "INVALID_OBJECT" },
1051 { 0xc, "INVALID_BITFIELD" },
1052 { 0x28, "MP_NO_REG_SPACE" },
1053 { 0x2b, "MP_BLOCK_SIZE_MISMATCH" },
1054};
1055
1056static void
Ben Skeggs6ee73862009-12-11 19:24:15 +10001057nv50_pgraph_irq_handler(struct drm_device *dev)
1058{
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001059 struct nouveau_pgraph_trap trap;
1060 int unhandled = 0;
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001061 uint32_t status;
Ben Skeggs6ee73862009-12-11 19:24:15 +10001062
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001063 while ((status = nv_rd32(dev, NV03_PGRAPH_INTR))) {
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001064 /* NOTIFY: You've set a NOTIFY an a command and it's done. */
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001065 if (status & 0x00000001) {
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001066 nouveau_graph_trap_info(dev, &trap);
1067 if (nouveau_ratelimit())
1068 nouveau_graph_dump_trap_info(dev,
1069 "PGRAPH_NOTIFY", &trap);
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001070 status &= ~0x00000001;
1071 nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000001);
1072 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001073
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001074 /* COMPUTE_QUERY: Purpose and exact cause unknown, happens
1075 * when you write 0x200 to 0x50c0 method 0x31c. */
1076 if (status & 0x00000002) {
1077 nouveau_graph_trap_info(dev, &trap);
1078 if (nouveau_ratelimit())
1079 nouveau_graph_dump_trap_info(dev,
1080 "PGRAPH_COMPUTE_QUERY", &trap);
1081 status &= ~0x00000002;
1082 nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000002);
1083 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001084
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001085 /* Unknown, never seen: 0x4 */
1086
1087 /* ILLEGAL_MTHD: You used a wrong method for this class. */
1088 if (status & 0x00000010) {
1089 nouveau_graph_trap_info(dev, &trap);
1090 if (nouveau_pgraph_intr_swmthd(dev, &trap))
1091 unhandled = 1;
1092 if (unhandled && nouveau_ratelimit())
1093 nouveau_graph_dump_trap_info(dev,
1094 "PGRAPH_ILLEGAL_MTHD", &trap);
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001095 status &= ~0x00000010;
1096 nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000010);
1097 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001098
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001099 /* ILLEGAL_CLASS: You used a wrong class. */
1100 if (status & 0x00000020) {
1101 nouveau_graph_trap_info(dev, &trap);
1102 if (nouveau_ratelimit())
1103 nouveau_graph_dump_trap_info(dev,
1104 "PGRAPH_ILLEGAL_CLASS", &trap);
1105 status &= ~0x00000020;
1106 nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000020);
1107 }
1108
1109 /* DOUBLE_NOTIFY: You tried to set a NOTIFY on another NOTIFY. */
1110 if (status & 0x00000040) {
1111 nouveau_graph_trap_info(dev, &trap);
1112 if (nouveau_ratelimit())
1113 nouveau_graph_dump_trap_info(dev,
1114 "PGRAPH_DOUBLE_NOTIFY", &trap);
1115 status &= ~0x00000040;
1116 nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000040);
1117 }
1118
1119 /* CONTEXT_SWITCH: PGRAPH needs us to load a new context */
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001120 if (status & 0x00001000) {
1121 nv_wr32(dev, 0x400500, 0x00000000);
1122 nv_wr32(dev, NV03_PGRAPH_INTR,
1123 NV_PGRAPH_INTR_CONTEXT_SWITCH);
1124 nv_wr32(dev, NV40_PGRAPH_INTR_EN, nv_rd32(dev,
1125 NV40_PGRAPH_INTR_EN) &
1126 ~NV_PGRAPH_INTR_CONTEXT_SWITCH);
1127 nv_wr32(dev, 0x400500, 0x00010001);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001128
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001129 nv50_graph_context_switch(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001130
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001131 status &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH;
1132 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001133
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001134 /* BUFFER_NOTIFY: Your m2mf transfer finished */
1135 if (status & 0x00010000) {
1136 nouveau_graph_trap_info(dev, &trap);
1137 if (nouveau_ratelimit())
1138 nouveau_graph_dump_trap_info(dev,
1139 "PGRAPH_BUFFER_NOTIFY", &trap);
1140 status &= ~0x00010000;
1141 nv_wr32(dev, NV03_PGRAPH_INTR, 0x00010000);
1142 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001143
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001144 /* DATA_ERROR: Invalid value for this method, or invalid
1145 * state in current PGRAPH context for this operation */
1146 if (status & 0x00100000) {
1147 nouveau_graph_trap_info(dev, &trap);
1148 if (nouveau_ratelimit()) {
1149 nouveau_graph_dump_trap_info(dev,
1150 "PGRAPH_DATA_ERROR", &trap);
1151 NV_INFO (dev, "PGRAPH_DATA_ERROR - ");
1152 nouveau_print_enum_names(nv_rd32(dev, 0x400110),
1153 nv50_data_error_names);
1154 printk("\n");
1155 }
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001156 status &= ~0x00100000;
1157 nv_wr32(dev, NV03_PGRAPH_INTR, 0x00100000);
1158 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001159
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001160 /* TRAP: Something bad happened in the middle of command
1161 * execution. Has a billion types, subtypes, and even
1162 * subsubtypes. */
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001163 if (status & 0x00200000) {
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001164 nv50_pgraph_trap_handler(dev);
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001165 status &= ~0x00200000;
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001166 nv_wr32(dev, NV03_PGRAPH_INTR, 0x00200000);
1167 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001168
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001169 /* Unknown, never seen: 0x00400000 */
1170
1171 /* SINGLE_STEP: Happens on every method if you turned on
1172 * single stepping in 40008c */
1173 if (status & 0x01000000) {
1174 nouveau_graph_trap_info(dev, &trap);
1175 if (nouveau_ratelimit())
1176 nouveau_graph_dump_trap_info(dev,
1177 "PGRAPH_SINGLE_STEP", &trap);
1178 status &= ~0x01000000;
1179 nv_wr32(dev, NV03_PGRAPH_INTR, 0x01000000);
1180 }
1181
1182 /* 0x02000000 happens when you pause a ctxprog...
1183 * but the only way this can happen that I know is by
1184 * poking the relevant MMIO register, and we don't
1185 * do that. */
1186
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001187 if (status) {
1188 NV_INFO(dev, "Unhandled PGRAPH_INTR - 0x%08x\n",
1189 status);
1190 nv_wr32(dev, NV03_PGRAPH_INTR, status);
1191 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001192
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001193 {
1194 const int isb = (1 << 16) | (1 << 0);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001195
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001196 if ((nv_rd32(dev, 0x400500) & isb) != isb)
1197 nv_wr32(dev, 0x400500,
1198 nv_rd32(dev, 0x400500) | isb);
1199 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001200 }
1201
1202 nv_wr32(dev, NV03_PMC_INTR_0, NV_PMC_INTR_0_PGRAPH_PENDING);
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001203 if (nv_rd32(dev, 0x400824) & (1 << 31))
1204 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) & ~(1 << 31));
Ben Skeggs6ee73862009-12-11 19:24:15 +10001205}
1206
1207static void
1208nouveau_crtc_irq_handler(struct drm_device *dev, int crtc)
1209{
1210 if (crtc & 1)
1211 nv_wr32(dev, NV_CRTC0_INTSTAT, NV_CRTC_INTR_VBLANK);
1212
1213 if (crtc & 2)
1214 nv_wr32(dev, NV_CRTC1_INTSTAT, NV_CRTC_INTR_VBLANK);
1215}
1216
1217irqreturn_t
1218nouveau_irq_handler(DRM_IRQ_ARGS)
1219{
1220 struct drm_device *dev = (struct drm_device *)arg;
1221 struct drm_nouveau_private *dev_priv = dev->dev_private;
Dave Airlie38651672010-03-30 05:34:13 +00001222 uint32_t status;
Maarten Maathuisff9e5272010-02-01 20:58:27 +01001223 unsigned long flags;
Ben Skeggs6ee73862009-12-11 19:24:15 +10001224
1225 status = nv_rd32(dev, NV03_PMC_INTR_0);
1226 if (!status)
1227 return IRQ_NONE;
1228
Maarten Maathuisff9e5272010-02-01 20:58:27 +01001229 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
1230
Ben Skeggs6ee73862009-12-11 19:24:15 +10001231 if (status & NV_PMC_INTR_0_PFIFO_PENDING) {
1232 nouveau_fifo_irq_handler(dev);
1233 status &= ~NV_PMC_INTR_0_PFIFO_PENDING;
1234 }
1235
1236 if (status & NV_PMC_INTR_0_PGRAPH_PENDING) {
1237 if (dev_priv->card_type >= NV_50)
1238 nv50_pgraph_irq_handler(dev);
1239 else
1240 nouveau_pgraph_irq_handler(dev);
1241
1242 status &= ~NV_PMC_INTR_0_PGRAPH_PENDING;
1243 }
1244
1245 if (status & NV_PMC_INTR_0_CRTCn_PENDING) {
1246 nouveau_crtc_irq_handler(dev, (status>>24)&3);
1247 status &= ~NV_PMC_INTR_0_CRTCn_PENDING;
1248 }
1249
1250 if (status & (NV_PMC_INTR_0_NV50_DISPLAY_PENDING |
1251 NV_PMC_INTR_0_NV50_I2C_PENDING)) {
1252 nv50_display_irq_handler(dev);
1253 status &= ~(NV_PMC_INTR_0_NV50_DISPLAY_PENDING |
1254 NV_PMC_INTR_0_NV50_I2C_PENDING);
1255 }
1256
1257 if (status)
1258 NV_ERROR(dev, "Unhandled PMC INTR status bits 0x%08x\n", status);
1259
Maarten Maathuisff9e5272010-02-01 20:58:27 +01001260 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
1261
Ben Skeggs6ee73862009-12-11 19:24:15 +10001262 return IRQ_HANDLED;
1263}