blob: 316e0587fb01df3a1944d93ba548324157cdc80c [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
45void
46nouveau_irq_preinstall(struct drm_device *dev)
47{
48 struct drm_nouveau_private *dev_priv = dev->dev_private;
49
50 /* Master disable */
51 nv_wr32(dev, NV03_PMC_INTR_EN_0, 0);
52
Ben Skeggs4b223ee2010-08-03 10:00:56 +100053 if (dev_priv->card_type >= NV_50) {
Ben Skeggs6ee73862009-12-11 19:24:15 +100054 INIT_WORK(&dev_priv->irq_work, nv50_display_irq_handler_bh);
Ben Skeggsa5acac62010-03-30 15:14:41 +100055 INIT_WORK(&dev_priv->hpd_work, nv50_display_irq_hotplug_bh);
Ben Skeggs6ee73862009-12-11 19:24:15 +100056 INIT_LIST_HEAD(&dev_priv->vbl_waiting);
57 }
58}
59
60int
61nouveau_irq_postinstall(struct drm_device *dev)
62{
63 /* Master enable */
64 nv_wr32(dev, NV03_PMC_INTR_EN_0, NV_PMC_INTR_EN_0_MASTER_ENABLE);
65 return 0;
66}
67
68void
69nouveau_irq_uninstall(struct drm_device *dev)
70{
71 /* Master disable */
72 nv_wr32(dev, NV03_PMC_INTR_EN_0, 0);
73}
74
75static int
76nouveau_call_method(struct nouveau_channel *chan, int class, int mthd, int data)
77{
78 struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
79 struct nouveau_pgraph_object_method *grm;
80 struct nouveau_pgraph_object_class *grc;
81
82 grc = dev_priv->engine.graph.grclass;
83 while (grc->id) {
84 if (grc->id == class)
85 break;
86 grc++;
87 }
88
89 if (grc->id != class || !grc->methods)
90 return -ENOENT;
91
92 grm = grc->methods;
93 while (grm->id) {
94 if (grm->id == mthd)
95 return grm->exec(chan, class, mthd, data);
96 grm++;
97 }
98
99 return -ENOENT;
100}
101
102static bool
103nouveau_fifo_swmthd(struct nouveau_channel *chan, uint32_t addr, uint32_t data)
104{
105 struct drm_device *dev = chan->dev;
106 const int subc = (addr >> 13) & 0x7;
107 const int mthd = addr & 0x1ffc;
108
109 if (mthd == 0x0000) {
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000110 struct nouveau_gpuobj *gpuobj;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000111
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000112 gpuobj = nouveau_ramht_find(chan, data);
113 if (!gpuobj)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000114 return false;
115
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000116 if (gpuobj->engine != NVOBJ_ENGINE_SW)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000117 return false;
118
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000119 chan->sw_subchannel[subc] = gpuobj->class;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000120 nv_wr32(dev, NV04_PFIFO_CACHE1_ENGINE, nv_rd32(dev,
121 NV04_PFIFO_CACHE1_ENGINE) & ~(0xf << subc * 4));
122 return true;
123 }
124
125 /* hw object */
126 if (nv_rd32(dev, NV04_PFIFO_CACHE1_ENGINE) & (1 << (subc*4)))
127 return false;
128
129 if (nouveau_call_method(chan, chan->sw_subchannel[subc], mthd, data))
130 return false;
131
132 return true;
133}
134
135static void
136nouveau_fifo_irq_handler(struct drm_device *dev)
137{
138 struct drm_nouveau_private *dev_priv = dev->dev_private;
139 struct nouveau_engine *engine = &dev_priv->engine;
140 uint32_t status, reassign;
141 int cnt = 0;
142
143 reassign = nv_rd32(dev, NV03_PFIFO_CACHES) & 1;
144 while ((status = nv_rd32(dev, NV03_PFIFO_INTR_0)) && (cnt++ < 100)) {
145 struct nouveau_channel *chan = NULL;
146 uint32_t chid, get;
147
148 nv_wr32(dev, NV03_PFIFO_CACHES, 0);
149
150 chid = engine->fifo.channel_id(dev);
151 if (chid >= 0 && chid < engine->fifo.channels)
152 chan = dev_priv->fifos[chid];
153 get = nv_rd32(dev, NV03_PFIFO_CACHE1_GET);
154
155 if (status & NV_PFIFO_INTR_CACHE_ERROR) {
156 uint32_t mthd, data;
157 int ptr;
158
159 /* NV_PFIFO_CACHE1_GET actually goes to 0xffc before
160 * wrapping on my G80 chips, but CACHE1 isn't big
161 * enough for this much data.. Tests show that it
162 * wraps around to the start at GET=0x800.. No clue
163 * as to why..
164 */
165 ptr = (get & 0x7ff) >> 2;
166
167 if (dev_priv->card_type < NV_40) {
168 mthd = nv_rd32(dev,
169 NV04_PFIFO_CACHE1_METHOD(ptr));
170 data = nv_rd32(dev,
171 NV04_PFIFO_CACHE1_DATA(ptr));
172 } else {
173 mthd = nv_rd32(dev,
174 NV40_PFIFO_CACHE1_METHOD(ptr));
175 data = nv_rd32(dev,
176 NV40_PFIFO_CACHE1_DATA(ptr));
177 }
178
179 if (!chan || !nouveau_fifo_swmthd(chan, mthd, data)) {
180 NV_INFO(dev, "PFIFO_CACHE_ERROR - Ch %d/%d "
181 "Mthd 0x%04x Data 0x%08x\n",
182 chid, (mthd >> 13) & 7, mthd & 0x1ffc,
183 data);
184 }
185
186 nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_PUSH, 0);
187 nv_wr32(dev, NV03_PFIFO_INTR_0,
188 NV_PFIFO_INTR_CACHE_ERROR);
189
190 nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH0,
191 nv_rd32(dev, NV03_PFIFO_CACHE1_PUSH0) & ~1);
192 nv_wr32(dev, NV03_PFIFO_CACHE1_GET, get + 4);
193 nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH0,
194 nv_rd32(dev, NV03_PFIFO_CACHE1_PUSH0) | 1);
195 nv_wr32(dev, NV04_PFIFO_CACHE1_HASH, 0);
196
197 nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_PUSH,
198 nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_PUSH) | 1);
199 nv_wr32(dev, NV04_PFIFO_CACHE1_PULL0, 1);
200
201 status &= ~NV_PFIFO_INTR_CACHE_ERROR;
202 }
203
204 if (status & NV_PFIFO_INTR_DMA_PUSHER) {
205 NV_INFO(dev, "PFIFO_DMA_PUSHER - Ch %d\n", chid);
206
207 status &= ~NV_PFIFO_INTR_DMA_PUSHER;
208 nv_wr32(dev, NV03_PFIFO_INTR_0,
209 NV_PFIFO_INTR_DMA_PUSHER);
210
211 nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_STATE, 0x00000000);
212 if (nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_PUT) != get)
213 nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_GET,
214 get + 4);
215 }
216
Francisco Jerez139295b2010-01-30 18:28:00 +0100217 if (status & NV_PFIFO_INTR_SEMAPHORE) {
218 uint32_t sem;
219
220 status &= ~NV_PFIFO_INTR_SEMAPHORE;
221 nv_wr32(dev, NV03_PFIFO_INTR_0,
222 NV_PFIFO_INTR_SEMAPHORE);
223
224 sem = nv_rd32(dev, NV10_PFIFO_CACHE1_SEMAPHORE);
225 nv_wr32(dev, NV10_PFIFO_CACHE1_SEMAPHORE, sem | 0x1);
226
227 nv_wr32(dev, NV03_PFIFO_CACHE1_GET, get + 4);
228 nv_wr32(dev, NV04_PFIFO_CACHE1_PULL0, 1);
229 }
230
Ben Skeggs6ee73862009-12-11 19:24:15 +1000231 if (status) {
232 NV_INFO(dev, "PFIFO_INTR 0x%08x - Ch %d\n",
233 status, chid);
234 nv_wr32(dev, NV03_PFIFO_INTR_0, status);
235 status = 0;
236 }
237
238 nv_wr32(dev, NV03_PFIFO_CACHES, reassign);
239 }
240
241 if (status) {
242 NV_INFO(dev, "PFIFO still angry after %d spins, halt\n", cnt);
243 nv_wr32(dev, 0x2140, 0);
244 nv_wr32(dev, 0x140, 0);
245 }
246
247 nv_wr32(dev, NV03_PMC_INTR_0, NV_PMC_INTR_0_PFIFO_PENDING);
248}
249
250struct nouveau_bitfield_names {
251 uint32_t mask;
252 const char *name;
253};
254
255static struct nouveau_bitfield_names nstatus_names[] =
256{
257 { NV04_PGRAPH_NSTATUS_STATE_IN_USE, "STATE_IN_USE" },
258 { NV04_PGRAPH_NSTATUS_INVALID_STATE, "INVALID_STATE" },
259 { NV04_PGRAPH_NSTATUS_BAD_ARGUMENT, "BAD_ARGUMENT" },
260 { NV04_PGRAPH_NSTATUS_PROTECTION_FAULT, "PROTECTION_FAULT" }
261};
262
263static struct nouveau_bitfield_names nstatus_names_nv10[] =
264{
265 { NV10_PGRAPH_NSTATUS_STATE_IN_USE, "STATE_IN_USE" },
266 { NV10_PGRAPH_NSTATUS_INVALID_STATE, "INVALID_STATE" },
267 { NV10_PGRAPH_NSTATUS_BAD_ARGUMENT, "BAD_ARGUMENT" },
268 { NV10_PGRAPH_NSTATUS_PROTECTION_FAULT, "PROTECTION_FAULT" }
269};
270
271static struct nouveau_bitfield_names nsource_names[] =
272{
273 { NV03_PGRAPH_NSOURCE_NOTIFICATION, "NOTIFICATION" },
274 { NV03_PGRAPH_NSOURCE_DATA_ERROR, "DATA_ERROR" },
275 { NV03_PGRAPH_NSOURCE_PROTECTION_ERROR, "PROTECTION_ERROR" },
276 { NV03_PGRAPH_NSOURCE_RANGE_EXCEPTION, "RANGE_EXCEPTION" },
277 { NV03_PGRAPH_NSOURCE_LIMIT_COLOR, "LIMIT_COLOR" },
278 { NV03_PGRAPH_NSOURCE_LIMIT_ZETA, "LIMIT_ZETA" },
279 { NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD, "ILLEGAL_MTHD" },
280 { NV03_PGRAPH_NSOURCE_DMA_R_PROTECTION, "DMA_R_PROTECTION" },
281 { NV03_PGRAPH_NSOURCE_DMA_W_PROTECTION, "DMA_W_PROTECTION" },
282 { NV03_PGRAPH_NSOURCE_FORMAT_EXCEPTION, "FORMAT_EXCEPTION" },
283 { NV03_PGRAPH_NSOURCE_PATCH_EXCEPTION, "PATCH_EXCEPTION" },
284 { NV03_PGRAPH_NSOURCE_STATE_INVALID, "STATE_INVALID" },
285 { NV03_PGRAPH_NSOURCE_DOUBLE_NOTIFY, "DOUBLE_NOTIFY" },
286 { NV03_PGRAPH_NSOURCE_NOTIFY_IN_USE, "NOTIFY_IN_USE" },
287 { NV03_PGRAPH_NSOURCE_METHOD_CNT, "METHOD_CNT" },
288 { NV03_PGRAPH_NSOURCE_BFR_NOTIFICATION, "BFR_NOTIFICATION" },
289 { NV03_PGRAPH_NSOURCE_DMA_VTX_PROTECTION, "DMA_VTX_PROTECTION" },
290 { NV03_PGRAPH_NSOURCE_DMA_WIDTH_A, "DMA_WIDTH_A" },
291 { NV03_PGRAPH_NSOURCE_DMA_WIDTH_B, "DMA_WIDTH_B" },
292};
293
294static void
295nouveau_print_bitfield_names_(uint32_t value,
296 const struct nouveau_bitfield_names *namelist,
297 const int namelist_len)
298{
299 /*
300 * Caller must have already printed the KERN_* log level for us.
301 * Also the caller is responsible for adding the newline.
302 */
303 int i;
304 for (i = 0; i < namelist_len; ++i) {
305 uint32_t mask = namelist[i].mask;
306 if (value & mask) {
307 printk(" %s", namelist[i].name);
308 value &= ~mask;
309 }
310 }
311 if (value)
312 printk(" (unknown bits 0x%08x)", value);
313}
314#define nouveau_print_bitfield_names(val, namelist) \
315 nouveau_print_bitfield_names_((val), (namelist), ARRAY_SIZE(namelist))
316
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000317struct nouveau_enum_names {
318 uint32_t value;
319 const char *name;
320};
321
322static void
323nouveau_print_enum_names_(uint32_t value,
324 const struct nouveau_enum_names *namelist,
325 const int namelist_len)
326{
327 /*
328 * Caller must have already printed the KERN_* log level for us.
329 * Also the caller is responsible for adding the newline.
330 */
331 int i;
332 for (i = 0; i < namelist_len; ++i) {
333 if (value == namelist[i].value) {
334 printk("%s", namelist[i].name);
335 return;
336 }
337 }
338 printk("unknown value 0x%08x", value);
339}
340#define nouveau_print_enum_names(val, namelist) \
341 nouveau_print_enum_names_((val), (namelist), ARRAY_SIZE(namelist))
Ben Skeggs6ee73862009-12-11 19:24:15 +1000342
343static int
344nouveau_graph_chid_from_grctx(struct drm_device *dev)
345{
346 struct drm_nouveau_private *dev_priv = dev->dev_private;
347 uint32_t inst;
348 int i;
349
350 if (dev_priv->card_type < NV_40)
351 return dev_priv->engine.fifo.channels;
352 else
353 if (dev_priv->card_type < NV_50) {
354 inst = (nv_rd32(dev, 0x40032c) & 0xfffff) << 4;
355
356 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
357 struct nouveau_channel *chan = dev_priv->fifos[i];
358
359 if (!chan || !chan->ramin_grctx)
360 continue;
361
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000362 if (inst == chan->ramin_grctx->pinst)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000363 break;
364 }
365 } else {
366 inst = (nv_rd32(dev, 0x40032c) & 0xfffff) << 12;
367
368 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
369 struct nouveau_channel *chan = dev_priv->fifos[i];
370
371 if (!chan || !chan->ramin)
372 continue;
373
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000374 if (inst == chan->ramin->vinst)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000375 break;
376 }
377 }
378
379
380 return i;
381}
382
383static int
384nouveau_graph_trapped_channel(struct drm_device *dev, int *channel_ret)
385{
386 struct drm_nouveau_private *dev_priv = dev->dev_private;
387 struct nouveau_engine *engine = &dev_priv->engine;
388 int channel;
389
390 if (dev_priv->card_type < NV_10)
391 channel = (nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR) >> 24) & 0xf;
392 else
393 if (dev_priv->card_type < NV_40)
394 channel = (nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR) >> 20) & 0x1f;
395 else
396 channel = nouveau_graph_chid_from_grctx(dev);
397
398 if (channel >= engine->fifo.channels || !dev_priv->fifos[channel]) {
399 NV_ERROR(dev, "AIII, invalid/inactive channel id %d\n", channel);
400 return -EINVAL;
401 }
402
403 *channel_ret = channel;
404 return 0;
405}
406
407struct nouveau_pgraph_trap {
408 int channel;
409 int class;
410 int subc, mthd, size;
411 uint32_t data, data2;
412 uint32_t nsource, nstatus;
413};
414
415static void
416nouveau_graph_trap_info(struct drm_device *dev,
417 struct nouveau_pgraph_trap *trap)
418{
419 struct drm_nouveau_private *dev_priv = dev->dev_private;
420 uint32_t address;
421
422 trap->nsource = trap->nstatus = 0;
423 if (dev_priv->card_type < NV_50) {
424 trap->nsource = nv_rd32(dev, NV03_PGRAPH_NSOURCE);
425 trap->nstatus = nv_rd32(dev, NV03_PGRAPH_NSTATUS);
426 }
427
428 if (nouveau_graph_trapped_channel(dev, &trap->channel))
429 trap->channel = -1;
430 address = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR);
431
432 trap->mthd = address & 0x1FFC;
433 trap->data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA);
434 if (dev_priv->card_type < NV_10) {
435 trap->subc = (address >> 13) & 0x7;
436 } else {
437 trap->subc = (address >> 16) & 0x7;
438 trap->data2 = nv_rd32(dev, NV10_PGRAPH_TRAPPED_DATA_HIGH);
439 }
440
441 if (dev_priv->card_type < NV_10)
442 trap->class = nv_rd32(dev, 0x400180 + trap->subc*4) & 0xFF;
443 else if (dev_priv->card_type < NV_40)
444 trap->class = nv_rd32(dev, 0x400160 + trap->subc*4) & 0xFFF;
445 else if (dev_priv->card_type < NV_50)
446 trap->class = nv_rd32(dev, 0x400160 + trap->subc*4) & 0xFFFF;
447 else
448 trap->class = nv_rd32(dev, 0x400814);
449}
450
451static void
452nouveau_graph_dump_trap_info(struct drm_device *dev, const char *id,
453 struct nouveau_pgraph_trap *trap)
454{
455 struct drm_nouveau_private *dev_priv = dev->dev_private;
456 uint32_t nsource = trap->nsource, nstatus = trap->nstatus;
457
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000458 if (dev_priv->card_type < NV_50) {
459 NV_INFO(dev, "%s - nSource:", id);
460 nouveau_print_bitfield_names(nsource, nsource_names);
461 printk(", nStatus:");
462 if (dev_priv->card_type < NV_10)
463 nouveau_print_bitfield_names(nstatus, nstatus_names);
464 else
465 nouveau_print_bitfield_names(nstatus, nstatus_names_nv10);
466 printk("\n");
467 }
Ben Skeggs6ee73862009-12-11 19:24:15 +1000468
469 NV_INFO(dev, "%s - Ch %d/%d Class 0x%04x Mthd 0x%04x "
470 "Data 0x%08x:0x%08x\n",
471 id, trap->channel, trap->subc,
472 trap->class, trap->mthd,
473 trap->data2, trap->data);
474}
475
476static int
477nouveau_pgraph_intr_swmthd(struct drm_device *dev,
478 struct nouveau_pgraph_trap *trap)
479{
480 struct drm_nouveau_private *dev_priv = dev->dev_private;
481
482 if (trap->channel < 0 ||
483 trap->channel >= dev_priv->engine.fifo.channels ||
484 !dev_priv->fifos[trap->channel])
485 return -ENODEV;
486
487 return nouveau_call_method(dev_priv->fifos[trap->channel],
488 trap->class, trap->mthd, trap->data);
489}
490
491static inline void
492nouveau_pgraph_intr_notify(struct drm_device *dev, uint32_t nsource)
493{
494 struct nouveau_pgraph_trap trap;
495 int unhandled = 0;
496
497 nouveau_graph_trap_info(dev, &trap);
498
499 if (nsource & NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD) {
500 if (nouveau_pgraph_intr_swmthd(dev, &trap))
501 unhandled = 1;
502 } else {
503 unhandled = 1;
504 }
505
506 if (unhandled)
507 nouveau_graph_dump_trap_info(dev, "PGRAPH_NOTIFY", &trap);
508}
509
510static DEFINE_RATELIMIT_STATE(nouveau_ratelimit_state, 3 * HZ, 20);
511
512static int nouveau_ratelimit(void)
513{
514 return __ratelimit(&nouveau_ratelimit_state);
515}
516
517
518static inline void
519nouveau_pgraph_intr_error(struct drm_device *dev, uint32_t nsource)
520{
521 struct nouveau_pgraph_trap trap;
522 int unhandled = 0;
523
524 nouveau_graph_trap_info(dev, &trap);
525 trap.nsource = nsource;
526
527 if (nsource & NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD) {
528 if (nouveau_pgraph_intr_swmthd(dev, &trap))
529 unhandled = 1;
Luca Barbierid051bbb2010-01-16 15:27:51 +0100530 } else if (nsource & NV03_PGRAPH_NSOURCE_DMA_VTX_PROTECTION) {
531 uint32_t v = nv_rd32(dev, 0x402000);
532 nv_wr32(dev, 0x402000, v);
533
534 /* dump the error anyway for now: it's useful for
535 Gallium development */
536 unhandled = 1;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000537 } else {
538 unhandled = 1;
539 }
540
541 if (unhandled && nouveau_ratelimit())
542 nouveau_graph_dump_trap_info(dev, "PGRAPH_ERROR", &trap);
543}
544
545static inline void
546nouveau_pgraph_intr_context_switch(struct drm_device *dev)
547{
548 struct drm_nouveau_private *dev_priv = dev->dev_private;
549 struct nouveau_engine *engine = &dev_priv->engine;
550 uint32_t chid;
551
552 chid = engine->fifo.channel_id(dev);
553 NV_DEBUG(dev, "PGRAPH context switch interrupt channel %x\n", chid);
554
555 switch (dev_priv->card_type) {
556 case NV_04:
557 nv04_graph_context_switch(dev);
558 break;
559 case NV_10:
560 nv10_graph_context_switch(dev);
561 break;
562 default:
563 NV_ERROR(dev, "Context switch not implemented\n");
564 break;
565 }
566}
567
568static void
569nouveau_pgraph_irq_handler(struct drm_device *dev)
570{
571 uint32_t status;
572
573 while ((status = nv_rd32(dev, NV03_PGRAPH_INTR))) {
574 uint32_t nsource = nv_rd32(dev, NV03_PGRAPH_NSOURCE);
575
576 if (status & NV_PGRAPH_INTR_NOTIFY) {
577 nouveau_pgraph_intr_notify(dev, nsource);
578
579 status &= ~NV_PGRAPH_INTR_NOTIFY;
580 nv_wr32(dev, NV03_PGRAPH_INTR, NV_PGRAPH_INTR_NOTIFY);
581 }
582
583 if (status & NV_PGRAPH_INTR_ERROR) {
584 nouveau_pgraph_intr_error(dev, nsource);
585
586 status &= ~NV_PGRAPH_INTR_ERROR;
587 nv_wr32(dev, NV03_PGRAPH_INTR, NV_PGRAPH_INTR_ERROR);
588 }
589
590 if (status & NV_PGRAPH_INTR_CONTEXT_SWITCH) {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000591 status &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH;
592 nv_wr32(dev, NV03_PGRAPH_INTR,
593 NV_PGRAPH_INTR_CONTEXT_SWITCH);
Francisco Jerez308dceb2010-08-04 04:41:55 +0200594
595 nouveau_pgraph_intr_context_switch(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000596 }
597
598 if (status) {
599 NV_INFO(dev, "Unhandled PGRAPH_INTR - 0x%08x\n", status);
600 nv_wr32(dev, NV03_PGRAPH_INTR, status);
601 }
602
603 if ((nv_rd32(dev, NV04_PGRAPH_FIFO) & (1 << 0)) == 0)
604 nv_wr32(dev, NV04_PGRAPH_FIFO, 1);
605 }
606
607 nv_wr32(dev, NV03_PMC_INTR_0, NV_PMC_INTR_0_PGRAPH_PENDING);
608}
609
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000610static struct nouveau_enum_names nv50_mp_exec_error_names[] =
611{
612 { 3, "STACK_UNDERFLOW" },
613 { 4, "QUADON_ACTIVE" },
614 { 8, "TIMEOUT" },
615 { 0x10, "INVALID_OPCODE" },
616 { 0x40, "BREAKPOINT" },
617};
618
619static void
620nv50_pgraph_mp_trap(struct drm_device *dev, int tpid, int display)
621{
622 struct drm_nouveau_private *dev_priv = dev->dev_private;
623 uint32_t units = nv_rd32(dev, 0x1540);
624 uint32_t addr, mp10, status, pc, oplow, ophigh;
625 int i;
626 int mps = 0;
627 for (i = 0; i < 4; i++) {
628 if (!(units & 1 << (i+24)))
629 continue;
630 if (dev_priv->chipset < 0xa0)
631 addr = 0x408200 + (tpid << 12) + (i << 7);
632 else
633 addr = 0x408100 + (tpid << 11) + (i << 7);
634 mp10 = nv_rd32(dev, addr + 0x10);
635 status = nv_rd32(dev, addr + 0x14);
636 if (!status)
637 continue;
638 if (display) {
639 nv_rd32(dev, addr + 0x20);
640 pc = nv_rd32(dev, addr + 0x24);
641 oplow = nv_rd32(dev, addr + 0x70);
642 ophigh= nv_rd32(dev, addr + 0x74);
643 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - "
644 "TP %d MP %d: ", tpid, i);
645 nouveau_print_enum_names(status,
646 nv50_mp_exec_error_names);
647 printk(" at %06x warp %d, opcode %08x %08x\n",
648 pc&0xffffff, pc >> 24,
649 oplow, ophigh);
650 }
651 nv_wr32(dev, addr + 0x10, mp10);
652 nv_wr32(dev, addr + 0x14, 0);
653 mps++;
654 }
655 if (!mps && display)
656 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - TP %d: "
657 "No MPs claiming errors?\n", tpid);
658}
659
660static void
661nv50_pgraph_tp_trap(struct drm_device *dev, int type, uint32_t ustatus_old,
662 uint32_t ustatus_new, int display, const char *name)
663{
664 struct drm_nouveau_private *dev_priv = dev->dev_private;
665 int tps = 0;
666 uint32_t units = nv_rd32(dev, 0x1540);
667 int i, r;
668 uint32_t ustatus_addr, ustatus;
669 for (i = 0; i < 16; i++) {
670 if (!(units & (1 << i)))
671 continue;
672 if (dev_priv->chipset < 0xa0)
673 ustatus_addr = ustatus_old + (i << 12);
674 else
675 ustatus_addr = ustatus_new + (i << 11);
676 ustatus = nv_rd32(dev, ustatus_addr) & 0x7fffffff;
677 if (!ustatus)
678 continue;
679 tps++;
680 switch (type) {
681 case 6: /* texture error... unknown for now */
Ben Skeggsd96773e2010-09-03 15:46:58 +1000682 nv50_fb_vm_trap(dev, display, name);
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000683 if (display) {
684 NV_ERROR(dev, "magic set %d:\n", i);
685 for (r = ustatus_addr + 4; r <= ustatus_addr + 0x10; r += 4)
686 NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r,
687 nv_rd32(dev, r));
688 }
689 break;
690 case 7: /* MP error */
691 if (ustatus & 0x00010000) {
692 nv50_pgraph_mp_trap(dev, i, display);
693 ustatus &= ~0x00010000;
694 }
695 break;
696 case 8: /* TPDMA error */
697 {
698 uint32_t e0c = nv_rd32(dev, ustatus_addr + 4);
699 uint32_t e10 = nv_rd32(dev, ustatus_addr + 8);
700 uint32_t e14 = nv_rd32(dev, ustatus_addr + 0xc);
701 uint32_t e18 = nv_rd32(dev, ustatus_addr + 0x10);
702 uint32_t e1c = nv_rd32(dev, ustatus_addr + 0x14);
703 uint32_t e20 = nv_rd32(dev, ustatus_addr + 0x18);
704 uint32_t e24 = nv_rd32(dev, ustatus_addr + 0x1c);
Ben Skeggsd96773e2010-09-03 15:46:58 +1000705 nv50_fb_vm_trap(dev, display, name);
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000706 /* 2d engine destination */
707 if (ustatus & 0x00000010) {
708 if (display) {
709 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - Unknown fault at address %02x%08x\n",
710 i, e14, e10);
711 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
712 i, e0c, e18, e1c, e20, e24);
713 }
714 ustatus &= ~0x00000010;
715 }
716 /* Render target */
717 if (ustatus & 0x00000040) {
718 if (display) {
719 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - Unknown fault at address %02x%08x\n",
720 i, e14, e10);
721 NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
722 i, e0c, e18, e1c, e20, e24);
723 }
724 ustatus &= ~0x00000040;
725 }
726 /* CUDA memory: l[], g[] or stack. */
727 if (ustatus & 0x00000080) {
728 if (display) {
729 if (e18 & 0x80000000) {
730 /* g[] read fault? */
731 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global read fault at address %02x%08x\n",
732 i, e14, e10 | ((e18 >> 24) & 0x1f));
733 e18 &= ~0x1f000000;
734 } else if (e18 & 0xc) {
735 /* g[] write fault? */
736 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global write fault at address %02x%08x\n",
737 i, e14, e10 | ((e18 >> 7) & 0x1f));
738 e18 &= ~0x00000f80;
739 } else {
740 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Unknown CUDA fault at address %02x%08x\n",
741 i, e14, e10);
742 }
743 NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
744 i, e0c, e18, e1c, e20, e24);
745 }
746 ustatus &= ~0x00000080;
747 }
748 }
749 break;
750 }
751 if (ustatus) {
752 if (display)
753 NV_INFO(dev, "%s - TP%d: Unhandled ustatus 0x%08x\n", name, i, ustatus);
754 }
755 nv_wr32(dev, ustatus_addr, 0xc0000000);
756 }
757
758 if (!tps && display)
759 NV_INFO(dev, "%s - No TPs claiming errors?\n", name);
760}
761
762static void
763nv50_pgraph_trap_handler(struct drm_device *dev)
764{
765 struct nouveau_pgraph_trap trap;
766 uint32_t status = nv_rd32(dev, 0x400108);
767 uint32_t ustatus;
768 int display = nouveau_ratelimit();
769
770
771 if (!status && display) {
772 nouveau_graph_trap_info(dev, &trap);
773 nouveau_graph_dump_trap_info(dev, "PGRAPH_TRAP", &trap);
774 NV_INFO(dev, "PGRAPH_TRAP - no units reporting traps?\n");
775 }
776
777 /* DISPATCH: Relays commands to other units and handles NOTIFY,
778 * COND, QUERY. If you get a trap from it, the command is still stuck
779 * in DISPATCH and you need to do something about it. */
780 if (status & 0x001) {
781 ustatus = nv_rd32(dev, 0x400804) & 0x7fffffff;
782 if (!ustatus && display) {
783 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - no ustatus?\n");
784 }
785
786 /* Known to be triggered by screwed up NOTIFY and COND... */
787 if (ustatus & 0x00000001) {
Ben Skeggsd96773e2010-09-03 15:46:58 +1000788 nv50_fb_vm_trap(dev, display, "PGRAPH_TRAP_DISPATCH_FAULT");
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000789 nv_wr32(dev, 0x400500, 0);
790 if (nv_rd32(dev, 0x400808) & 0x80000000) {
791 if (display) {
792 if (nouveau_graph_trapped_channel(dev, &trap.channel))
793 trap.channel = -1;
794 trap.class = nv_rd32(dev, 0x400814);
795 trap.mthd = nv_rd32(dev, 0x400808) & 0x1ffc;
796 trap.subc = (nv_rd32(dev, 0x400808) >> 16) & 0x7;
797 trap.data = nv_rd32(dev, 0x40080c);
798 trap.data2 = nv_rd32(dev, 0x400810);
799 nouveau_graph_dump_trap_info(dev,
800 "PGRAPH_TRAP_DISPATCH_FAULT", &trap);
801 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_FAULT - 400808: %08x\n", nv_rd32(dev, 0x400808));
802 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_FAULT - 400848: %08x\n", nv_rd32(dev, 0x400848));
803 }
804 nv_wr32(dev, 0x400808, 0);
805 } else if (display) {
806 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_FAULT - No stuck command?\n");
807 }
808 nv_wr32(dev, 0x4008e8, nv_rd32(dev, 0x4008e8) & 3);
809 nv_wr32(dev, 0x400848, 0);
810 ustatus &= ~0x00000001;
811 }
812 if (ustatus & 0x00000002) {
Ben Skeggsd96773e2010-09-03 15:46:58 +1000813 nv50_fb_vm_trap(dev, display, "PGRAPH_TRAP_DISPATCH_QUERY");
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000814 nv_wr32(dev, 0x400500, 0);
815 if (nv_rd32(dev, 0x40084c) & 0x80000000) {
816 if (display) {
817 if (nouveau_graph_trapped_channel(dev, &trap.channel))
818 trap.channel = -1;
819 trap.class = nv_rd32(dev, 0x400814);
820 trap.mthd = nv_rd32(dev, 0x40084c) & 0x1ffc;
821 trap.subc = (nv_rd32(dev, 0x40084c) >> 16) & 0x7;
822 trap.data = nv_rd32(dev, 0x40085c);
823 trap.data2 = 0;
824 nouveau_graph_dump_trap_info(dev,
825 "PGRAPH_TRAP_DISPATCH_QUERY", &trap);
826 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_QUERY - 40084c: %08x\n", nv_rd32(dev, 0x40084c));
827 }
828 nv_wr32(dev, 0x40084c, 0);
829 } else if (display) {
830 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_QUERY - No stuck command?\n");
831 }
832 ustatus &= ~0x00000002;
833 }
834 if (ustatus && display)
835 NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - Unhandled ustatus 0x%08x\n", ustatus);
836 nv_wr32(dev, 0x400804, 0xc0000000);
837 nv_wr32(dev, 0x400108, 0x001);
838 status &= ~0x001;
839 }
840
841 /* TRAPs other than dispatch use the "normal" trap regs. */
842 if (status && display) {
843 nouveau_graph_trap_info(dev, &trap);
844 nouveau_graph_dump_trap_info(dev,
845 "PGRAPH_TRAP", &trap);
846 }
847
848 /* M2MF: Memory to memory copy engine. */
849 if (status & 0x002) {
850 ustatus = nv_rd32(dev, 0x406800) & 0x7fffffff;
851 if (!ustatus && display) {
852 NV_INFO(dev, "PGRAPH_TRAP_M2MF - no ustatus?\n");
853 }
854 if (ustatus & 0x00000001) {
Ben Skeggsd96773e2010-09-03 15:46:58 +1000855 nv50_fb_vm_trap(dev, display, "PGRAPH_TRAP_M2MF_NOTIFY");
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000856 ustatus &= ~0x00000001;
857 }
858 if (ustatus & 0x00000002) {
Ben Skeggsd96773e2010-09-03 15:46:58 +1000859 nv50_fb_vm_trap(dev, display, "PGRAPH_TRAP_M2MF_IN");
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000860 ustatus &= ~0x00000002;
861 }
862 if (ustatus & 0x00000004) {
Ben Skeggsd96773e2010-09-03 15:46:58 +1000863 nv50_fb_vm_trap(dev, display, "PGRAPH_TRAP_M2MF_OUT");
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000864 ustatus &= ~0x00000004;
865 }
866 NV_INFO (dev, "PGRAPH_TRAP_M2MF - %08x %08x %08x %08x\n",
867 nv_rd32(dev, 0x406804),
868 nv_rd32(dev, 0x406808),
869 nv_rd32(dev, 0x40680c),
870 nv_rd32(dev, 0x406810));
871 if (ustatus && display)
872 NV_INFO(dev, "PGRAPH_TRAP_M2MF - Unhandled ustatus 0x%08x\n", ustatus);
873 /* No sane way found yet -- just reset the bugger. */
874 nv_wr32(dev, 0x400040, 2);
875 nv_wr32(dev, 0x400040, 0);
876 nv_wr32(dev, 0x406800, 0xc0000000);
877 nv_wr32(dev, 0x400108, 0x002);
878 status &= ~0x002;
879 }
880
881 /* VFETCH: Fetches data from vertex buffers. */
882 if (status & 0x004) {
883 ustatus = nv_rd32(dev, 0x400c04) & 0x7fffffff;
884 if (!ustatus && display) {
885 NV_INFO(dev, "PGRAPH_TRAP_VFETCH - no ustatus?\n");
886 }
887 if (ustatus & 0x00000001) {
Ben Skeggsd96773e2010-09-03 15:46:58 +1000888 nv50_fb_vm_trap(dev, display, "PGRAPH_TRAP_VFETCH_FAULT");
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000889 NV_INFO (dev, "PGRAPH_TRAP_VFETCH_FAULT - %08x %08x %08x %08x\n",
890 nv_rd32(dev, 0x400c00),
891 nv_rd32(dev, 0x400c08),
892 nv_rd32(dev, 0x400c0c),
893 nv_rd32(dev, 0x400c10));
894 ustatus &= ~0x00000001;
895 }
896 if (ustatus && display)
897 NV_INFO(dev, "PGRAPH_TRAP_VFETCH - Unhandled ustatus 0x%08x\n", ustatus);
898 nv_wr32(dev, 0x400c04, 0xc0000000);
899 nv_wr32(dev, 0x400108, 0x004);
900 status &= ~0x004;
901 }
902
903 /* STRMOUT: DirectX streamout / OpenGL transform feedback. */
904 if (status & 0x008) {
905 ustatus = nv_rd32(dev, 0x401800) & 0x7fffffff;
906 if (!ustatus && display) {
907 NV_INFO(dev, "PGRAPH_TRAP_STRMOUT - no ustatus?\n");
908 }
909 if (ustatus & 0x00000001) {
Ben Skeggsd96773e2010-09-03 15:46:58 +1000910 nv50_fb_vm_trap(dev, display, "PGRAPH_TRAP_STRMOUT_FAULT");
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000911 NV_INFO (dev, "PGRAPH_TRAP_STRMOUT_FAULT - %08x %08x %08x %08x\n",
912 nv_rd32(dev, 0x401804),
913 nv_rd32(dev, 0x401808),
914 nv_rd32(dev, 0x40180c),
915 nv_rd32(dev, 0x401810));
916 ustatus &= ~0x00000001;
917 }
918 if (ustatus && display)
919 NV_INFO(dev, "PGRAPH_TRAP_STRMOUT - Unhandled ustatus 0x%08x\n", ustatus);
920 /* No sane way found yet -- just reset the bugger. */
921 nv_wr32(dev, 0x400040, 0x80);
922 nv_wr32(dev, 0x400040, 0);
923 nv_wr32(dev, 0x401800, 0xc0000000);
924 nv_wr32(dev, 0x400108, 0x008);
925 status &= ~0x008;
926 }
927
928 /* CCACHE: Handles code and c[] caches and fills them. */
929 if (status & 0x010) {
930 ustatus = nv_rd32(dev, 0x405018) & 0x7fffffff;
931 if (!ustatus && display) {
932 NV_INFO(dev, "PGRAPH_TRAP_CCACHE - no ustatus?\n");
933 }
934 if (ustatus & 0x00000001) {
Ben Skeggsd96773e2010-09-03 15:46:58 +1000935 nv50_fb_vm_trap(dev, display, "PGRAPH_TRAP_CCACHE_FAULT");
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000936 NV_INFO (dev, "PGRAPH_TRAP_CCACHE_FAULT - %08x %08x %08x %08x %08x %08x %08x\n",
937 nv_rd32(dev, 0x405800),
938 nv_rd32(dev, 0x405804),
939 nv_rd32(dev, 0x405808),
940 nv_rd32(dev, 0x40580c),
941 nv_rd32(dev, 0x405810),
942 nv_rd32(dev, 0x405814),
943 nv_rd32(dev, 0x40581c));
944 ustatus &= ~0x00000001;
945 }
946 if (ustatus && display)
947 NV_INFO(dev, "PGRAPH_TRAP_CCACHE - Unhandled ustatus 0x%08x\n", ustatus);
948 nv_wr32(dev, 0x405018, 0xc0000000);
949 nv_wr32(dev, 0x400108, 0x010);
950 status &= ~0x010;
951 }
952
953 /* Unknown, not seen yet... 0x402000 is the only trap status reg
954 * remaining, so try to handle it anyway. Perhaps related to that
955 * unknown DMA slot on tesla? */
956 if (status & 0x20) {
Ben Skeggsd96773e2010-09-03 15:46:58 +1000957 nv50_fb_vm_trap(dev, display, "PGRAPH_TRAP_UNKC04");
Marcin Kościelnicki304424e2010-03-01 00:18:39 +0000958 ustatus = nv_rd32(dev, 0x402000) & 0x7fffffff;
959 if (display)
960 NV_INFO(dev, "PGRAPH_TRAP_UNKC04 - Unhandled ustatus 0x%08x\n", ustatus);
961 nv_wr32(dev, 0x402000, 0xc0000000);
962 /* no status modifiction on purpose */
963 }
964
965 /* TEXTURE: CUDA texturing units */
966 if (status & 0x040) {
967 nv50_pgraph_tp_trap (dev, 6, 0x408900, 0x408600, display,
968 "PGRAPH_TRAP_TEXTURE");
969 nv_wr32(dev, 0x400108, 0x040);
970 status &= ~0x040;
971 }
972
973 /* MP: CUDA execution engines. */
974 if (status & 0x080) {
975 nv50_pgraph_tp_trap (dev, 7, 0x408314, 0x40831c, display,
976 "PGRAPH_TRAP_MP");
977 nv_wr32(dev, 0x400108, 0x080);
978 status &= ~0x080;
979 }
980
981 /* TPDMA: Handles TP-initiated uncached memory accesses:
982 * l[], g[], stack, 2d surfaces, render targets. */
983 if (status & 0x100) {
984 nv50_pgraph_tp_trap (dev, 8, 0x408e08, 0x408708, display,
985 "PGRAPH_TRAP_TPDMA");
986 nv_wr32(dev, 0x400108, 0x100);
987 status &= ~0x100;
988 }
989
990 if (status) {
991 if (display)
992 NV_INFO(dev, "PGRAPH_TRAP - Unknown trap 0x%08x\n",
993 status);
994 nv_wr32(dev, 0x400108, status);
995 }
996}
997
998/* There must be a *lot* of these. Will take some time to gather them up. */
999static struct nouveau_enum_names nv50_data_error_names[] =
1000{
1001 { 4, "INVALID_VALUE" },
1002 { 5, "INVALID_ENUM" },
1003 { 8, "INVALID_OBJECT" },
1004 { 0xc, "INVALID_BITFIELD" },
1005 { 0x28, "MP_NO_REG_SPACE" },
1006 { 0x2b, "MP_BLOCK_SIZE_MISMATCH" },
1007};
1008
1009static void
Ben Skeggs6ee73862009-12-11 19:24:15 +10001010nv50_pgraph_irq_handler(struct drm_device *dev)
1011{
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001012 struct nouveau_pgraph_trap trap;
1013 int unhandled = 0;
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001014 uint32_t status;
Ben Skeggs6ee73862009-12-11 19:24:15 +10001015
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001016 while ((status = nv_rd32(dev, NV03_PGRAPH_INTR))) {
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001017 /* NOTIFY: You've set a NOTIFY an a command and it's done. */
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001018 if (status & 0x00000001) {
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001019 nouveau_graph_trap_info(dev, &trap);
1020 if (nouveau_ratelimit())
1021 nouveau_graph_dump_trap_info(dev,
1022 "PGRAPH_NOTIFY", &trap);
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001023 status &= ~0x00000001;
1024 nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000001);
1025 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001026
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001027 /* COMPUTE_QUERY: Purpose and exact cause unknown, happens
1028 * when you write 0x200 to 0x50c0 method 0x31c. */
1029 if (status & 0x00000002) {
1030 nouveau_graph_trap_info(dev, &trap);
1031 if (nouveau_ratelimit())
1032 nouveau_graph_dump_trap_info(dev,
1033 "PGRAPH_COMPUTE_QUERY", &trap);
1034 status &= ~0x00000002;
1035 nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000002);
1036 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001037
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001038 /* Unknown, never seen: 0x4 */
1039
1040 /* ILLEGAL_MTHD: You used a wrong method for this class. */
1041 if (status & 0x00000010) {
1042 nouveau_graph_trap_info(dev, &trap);
1043 if (nouveau_pgraph_intr_swmthd(dev, &trap))
1044 unhandled = 1;
1045 if (unhandled && nouveau_ratelimit())
1046 nouveau_graph_dump_trap_info(dev,
1047 "PGRAPH_ILLEGAL_MTHD", &trap);
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001048 status &= ~0x00000010;
1049 nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000010);
1050 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001051
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001052 /* ILLEGAL_CLASS: You used a wrong class. */
1053 if (status & 0x00000020) {
1054 nouveau_graph_trap_info(dev, &trap);
1055 if (nouveau_ratelimit())
1056 nouveau_graph_dump_trap_info(dev,
1057 "PGRAPH_ILLEGAL_CLASS", &trap);
1058 status &= ~0x00000020;
1059 nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000020);
1060 }
1061
1062 /* DOUBLE_NOTIFY: You tried to set a NOTIFY on another NOTIFY. */
1063 if (status & 0x00000040) {
1064 nouveau_graph_trap_info(dev, &trap);
1065 if (nouveau_ratelimit())
1066 nouveau_graph_dump_trap_info(dev,
1067 "PGRAPH_DOUBLE_NOTIFY", &trap);
1068 status &= ~0x00000040;
1069 nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000040);
1070 }
1071
1072 /* CONTEXT_SWITCH: PGRAPH needs us to load a new context */
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001073 if (status & 0x00001000) {
1074 nv_wr32(dev, 0x400500, 0x00000000);
1075 nv_wr32(dev, NV03_PGRAPH_INTR,
1076 NV_PGRAPH_INTR_CONTEXT_SWITCH);
1077 nv_wr32(dev, NV40_PGRAPH_INTR_EN, nv_rd32(dev,
1078 NV40_PGRAPH_INTR_EN) &
1079 ~NV_PGRAPH_INTR_CONTEXT_SWITCH);
1080 nv_wr32(dev, 0x400500, 0x00010001);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001081
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001082 nv50_graph_context_switch(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001083
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001084 status &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH;
1085 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001086
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001087 /* BUFFER_NOTIFY: Your m2mf transfer finished */
1088 if (status & 0x00010000) {
1089 nouveau_graph_trap_info(dev, &trap);
1090 if (nouveau_ratelimit())
1091 nouveau_graph_dump_trap_info(dev,
1092 "PGRAPH_BUFFER_NOTIFY", &trap);
1093 status &= ~0x00010000;
1094 nv_wr32(dev, NV03_PGRAPH_INTR, 0x00010000);
1095 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001096
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001097 /* DATA_ERROR: Invalid value for this method, or invalid
1098 * state in current PGRAPH context for this operation */
1099 if (status & 0x00100000) {
1100 nouveau_graph_trap_info(dev, &trap);
1101 if (nouveau_ratelimit()) {
1102 nouveau_graph_dump_trap_info(dev,
1103 "PGRAPH_DATA_ERROR", &trap);
1104 NV_INFO (dev, "PGRAPH_DATA_ERROR - ");
1105 nouveau_print_enum_names(nv_rd32(dev, 0x400110),
1106 nv50_data_error_names);
1107 printk("\n");
1108 }
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001109 status &= ~0x00100000;
1110 nv_wr32(dev, NV03_PGRAPH_INTR, 0x00100000);
1111 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001112
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001113 /* TRAP: Something bad happened in the middle of command
1114 * execution. Has a billion types, subtypes, and even
1115 * subsubtypes. */
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001116 if (status & 0x00200000) {
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001117 nv50_pgraph_trap_handler(dev);
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001118 status &= ~0x00200000;
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001119 nv_wr32(dev, NV03_PGRAPH_INTR, 0x00200000);
1120 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001121
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001122 /* Unknown, never seen: 0x00400000 */
1123
1124 /* SINGLE_STEP: Happens on every method if you turned on
1125 * single stepping in 40008c */
1126 if (status & 0x01000000) {
1127 nouveau_graph_trap_info(dev, &trap);
1128 if (nouveau_ratelimit())
1129 nouveau_graph_dump_trap_info(dev,
1130 "PGRAPH_SINGLE_STEP", &trap);
1131 status &= ~0x01000000;
1132 nv_wr32(dev, NV03_PGRAPH_INTR, 0x01000000);
1133 }
1134
1135 /* 0x02000000 happens when you pause a ctxprog...
1136 * but the only way this can happen that I know is by
1137 * poking the relevant MMIO register, and we don't
1138 * do that. */
1139
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001140 if (status) {
1141 NV_INFO(dev, "Unhandled PGRAPH_INTR - 0x%08x\n",
1142 status);
1143 nv_wr32(dev, NV03_PGRAPH_INTR, status);
1144 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001145
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001146 {
1147 const int isb = (1 << 16) | (1 << 0);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001148
Maarten Maathuisb1d37aa2010-01-20 19:54:34 +01001149 if ((nv_rd32(dev, 0x400500) & isb) != isb)
1150 nv_wr32(dev, 0x400500,
1151 nv_rd32(dev, 0x400500) | isb);
1152 }
Ben Skeggs6ee73862009-12-11 19:24:15 +10001153 }
1154
1155 nv_wr32(dev, NV03_PMC_INTR_0, NV_PMC_INTR_0_PGRAPH_PENDING);
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001156 if (nv_rd32(dev, 0x400824) & (1 << 31))
1157 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) & ~(1 << 31));
Ben Skeggs6ee73862009-12-11 19:24:15 +10001158}
1159
1160static void
1161nouveau_crtc_irq_handler(struct drm_device *dev, int crtc)
1162{
1163 if (crtc & 1)
1164 nv_wr32(dev, NV_CRTC0_INTSTAT, NV_CRTC_INTR_VBLANK);
1165
1166 if (crtc & 2)
1167 nv_wr32(dev, NV_CRTC1_INTSTAT, NV_CRTC_INTR_VBLANK);
1168}
1169
1170irqreturn_t
1171nouveau_irq_handler(DRM_IRQ_ARGS)
1172{
1173 struct drm_device *dev = (struct drm_device *)arg;
1174 struct drm_nouveau_private *dev_priv = dev->dev_private;
Dave Airlie38651672010-03-30 05:34:13 +00001175 uint32_t status;
Maarten Maathuisff9e5272010-02-01 20:58:27 +01001176 unsigned long flags;
Ben Skeggs6ee73862009-12-11 19:24:15 +10001177
1178 status = nv_rd32(dev, NV03_PMC_INTR_0);
1179 if (!status)
1180 return IRQ_NONE;
1181
Maarten Maathuisff9e5272010-02-01 20:58:27 +01001182 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
1183
Ben Skeggs6ee73862009-12-11 19:24:15 +10001184 if (status & NV_PMC_INTR_0_PFIFO_PENDING) {
1185 nouveau_fifo_irq_handler(dev);
1186 status &= ~NV_PMC_INTR_0_PFIFO_PENDING;
1187 }
1188
1189 if (status & NV_PMC_INTR_0_PGRAPH_PENDING) {
1190 if (dev_priv->card_type >= NV_50)
1191 nv50_pgraph_irq_handler(dev);
1192 else
1193 nouveau_pgraph_irq_handler(dev);
1194
1195 status &= ~NV_PMC_INTR_0_PGRAPH_PENDING;
1196 }
1197
1198 if (status & NV_PMC_INTR_0_CRTCn_PENDING) {
1199 nouveau_crtc_irq_handler(dev, (status>>24)&3);
1200 status &= ~NV_PMC_INTR_0_CRTCn_PENDING;
1201 }
1202
1203 if (status & (NV_PMC_INTR_0_NV50_DISPLAY_PENDING |
1204 NV_PMC_INTR_0_NV50_I2C_PENDING)) {
1205 nv50_display_irq_handler(dev);
1206 status &= ~(NV_PMC_INTR_0_NV50_DISPLAY_PENDING |
1207 NV_PMC_INTR_0_NV50_I2C_PENDING);
1208 }
1209
1210 if (status)
1211 NV_ERROR(dev, "Unhandled PMC INTR status bits 0x%08x\n", status);
1212
Maarten Maathuisff9e5272010-02-01 20:58:27 +01001213 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
1214
Ben Skeggs6ee73862009-12-11 19:24:15 +10001215 return IRQ_HANDLED;
1216}