2 * Copyright 2012 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
25 #include "changk104.h"
27 #include <core/client.h>
28 #include <core/gpuobj.h>
29 #include <subdev/bar.h>
30 #include <subdev/timer.h>
31 #include <subdev/top.h>
32 #include <engine/sw.h>
34 #include <nvif/class.h>
36 struct gk104_fifo_engine_status
{
49 gk104_fifo_engine_status(struct gk104_fifo
*fifo
, int engn
,
50 struct gk104_fifo_engine_status
*status
)
52 struct nvkm_engine
*engine
= fifo
->engine
[engn
].engine
;
53 struct nvkm_subdev
*subdev
= &fifo
->base
.engine
.subdev
;
54 struct nvkm_device
*device
= subdev
->device
;
55 u32 stat
= nvkm_rd32(device
, 0x002640 + (engn
* 0x08));
57 status
->busy
= !!(stat
& 0x80000000);
58 status
->faulted
= !!(stat
& 0x40000000);
59 status
->next
.tsg
= !!(stat
& 0x10000000);
60 status
->next
.id
= (stat
& 0x0fff0000) >> 16;
61 status
->chsw
= !!(stat
& 0x00008000);
62 status
->save
= !!(stat
& 0x00004000);
63 status
->load
= !!(stat
& 0x00002000);
64 status
->prev
.tsg
= !!(stat
& 0x00001000);
65 status
->prev
.id
= (stat
& 0x00000fff);
68 if (status
->busy
&& status
->chsw
) {
69 if (status
->load
&& status
->save
) {
70 if (engine
&& nvkm_engine_chsw_load(engine
))
71 status
->chan
= &status
->next
;
73 status
->chan
= &status
->prev
;
76 status
->chan
= &status
->next
;
78 status
->chan
= &status
->prev
;
82 status
->chan
= &status
->prev
;
85 nvkm_debug(subdev
, "engine %02d: busy %d faulted %d chsw %d "
86 "save %d load %d %sid %d%s-> %sid %d%s\n",
87 engn
, status
->busy
, status
->faulted
,
88 status
->chsw
, status
->save
, status
->load
,
89 status
->prev
.tsg
? "tsg" : "ch", status
->prev
.id
,
90 status
->chan
== &status
->prev
? "*" : " ",
91 status
->next
.tsg
? "tsg" : "ch", status
->next
.id
,
92 status
->chan
== &status
->next
? "*" : " ");
96 gk104_fifo_class_get(struct nvkm_fifo
*base
, int index
,
97 const struct nvkm_fifo_chan_oclass
**psclass
)
99 struct gk104_fifo
*fifo
= gk104_fifo(base
);
102 while ((*psclass
= fifo
->func
->chan
[c
])) {
111 gk104_fifo_uevent_fini(struct nvkm_fifo
*fifo
)
113 struct nvkm_device
*device
= fifo
->engine
.subdev
.device
;
114 nvkm_mask(device
, 0x002140, 0x80000000, 0x00000000);
118 gk104_fifo_uevent_init(struct nvkm_fifo
*fifo
)
120 struct nvkm_device
*device
= fifo
->engine
.subdev
.device
;
121 nvkm_mask(device
, 0x002140, 0x80000000, 0x80000000);
125 gk104_fifo_runlist_commit(struct gk104_fifo
*fifo
, int runl
)
127 struct gk104_fifo_chan
*chan
;
128 struct nvkm_subdev
*subdev
= &fifo
->base
.engine
.subdev
;
129 struct nvkm_device
*device
= subdev
->device
;
130 struct nvkm_memory
*mem
;
134 mutex_lock(&subdev
->mutex
);
135 mem
= fifo
->runlist
[runl
].mem
[fifo
->runlist
[runl
].next
];
136 fifo
->runlist
[runl
].next
= !fifo
->runlist
[runl
].next
;
139 list_for_each_entry(chan
, &fifo
->runlist
[runl
].chan
, head
) {
140 nvkm_wo32(mem
, (nr
* 8) + 0, chan
->base
.chid
);
141 nvkm_wo32(mem
, (nr
* 8) + 4, 0x00000000);
146 switch (nvkm_memory_target(mem
)) {
147 case NVKM_MEM_TARGET_VRAM
: target
= 0; break;
148 case NVKM_MEM_TARGET_NCOH
: target
= 3; break;
154 nvkm_wr32(device
, 0x002270, (nvkm_memory_addr(mem
) >> 12) |
156 nvkm_wr32(device
, 0x002274, (runl
<< 20) | nr
);
158 if (wait_event_timeout(fifo
->runlist
[runl
].wait
,
159 !(nvkm_rd32(device
, 0x002284 + (runl
* 0x08))
161 msecs_to_jiffies(2000)) == 0)
162 nvkm_error(subdev
, "runlist %d update timeout\n", runl
);
164 mutex_unlock(&subdev
->mutex
);
168 gk104_fifo_runlist_remove(struct gk104_fifo
*fifo
, struct gk104_fifo_chan
*chan
)
170 mutex_lock(&fifo
->base
.engine
.subdev
.mutex
);
171 list_del_init(&chan
->head
);
172 mutex_unlock(&fifo
->base
.engine
.subdev
.mutex
);
176 gk104_fifo_runlist_insert(struct gk104_fifo
*fifo
, struct gk104_fifo_chan
*chan
)
178 mutex_lock(&fifo
->base
.engine
.subdev
.mutex
);
179 list_add_tail(&chan
->head
, &fifo
->runlist
[chan
->runl
].chan
);
180 mutex_unlock(&fifo
->base
.engine
.subdev
.mutex
);
184 gk104_fifo_recover_work(struct work_struct
*w
)
186 struct gk104_fifo
*fifo
= container_of(w
, typeof(*fifo
), recover
.work
);
187 struct nvkm_device
*device
= fifo
->base
.engine
.subdev
.device
;
188 struct nvkm_engine
*engine
;
190 u32 engm
, runm
, todo
;
193 spin_lock_irqsave(&fifo
->base
.lock
, flags
);
194 runm
= fifo
->recover
.runm
;
195 engm
= fifo
->recover
.engm
;
196 fifo
->recover
.engm
= 0;
197 fifo
->recover
.runm
= 0;
198 spin_unlock_irqrestore(&fifo
->base
.lock
, flags
);
200 nvkm_mask(device
, 0x002630, runm
, runm
);
202 for (todo
= engm
; engn
= __ffs(todo
), todo
; todo
&= ~BIT(engn
)) {
203 if ((engine
= fifo
->engine
[engn
].engine
)) {
204 nvkm_subdev_fini(&engine
->subdev
, false);
205 WARN_ON(nvkm_subdev_init(&engine
->subdev
));
209 for (todo
= runm
; runl
= __ffs(todo
), todo
; todo
&= ~BIT(runl
))
210 gk104_fifo_runlist_commit(fifo
, runl
);
212 nvkm_wr32(device
, 0x00262c, runm
);
213 nvkm_mask(device
, 0x002630, runm
, 0x00000000);
216 static void gk104_fifo_recover_engn(struct gk104_fifo
*fifo
, int engn
);
219 gk104_fifo_recover_runl(struct gk104_fifo
*fifo
, int runl
)
221 struct nvkm_subdev
*subdev
= &fifo
->base
.engine
.subdev
;
222 struct nvkm_device
*device
= subdev
->device
;
223 const u32 runm
= BIT(runl
);
225 assert_spin_locked(&fifo
->base
.lock
);
226 if (fifo
->recover
.runm
& runm
)
228 fifo
->recover
.runm
|= runm
;
230 /* Block runlist to prevent channel assignment(s) from changing. */
231 nvkm_mask(device
, 0x002630, runm
, runm
);
233 /* Schedule recovery. */
234 nvkm_warn(subdev
, "runlist %d: scheduled for recovery\n", runl
);
235 schedule_work(&fifo
->recover
.work
);
239 gk104_fifo_recover_chan(struct nvkm_fifo
*base
, int chid
)
241 struct gk104_fifo
*fifo
= gk104_fifo(base
);
242 struct nvkm_subdev
*subdev
= &fifo
->base
.engine
.subdev
;
243 struct nvkm_device
*device
= subdev
->device
;
244 const u32 stat
= nvkm_rd32(device
, 0x800004 + (chid
* 0x08));
245 const u32 runl
= (stat
& 0x000f0000) >> 16;
246 const bool used
= (stat
& 0x00000001);
247 unsigned long engn
, engm
= fifo
->runlist
[runl
].engm
;
248 struct gk104_fifo_chan
*chan
;
250 assert_spin_locked(&fifo
->base
.lock
);
254 /* Lookup SW state for channel, and mark it as dead. */
255 list_for_each_entry(chan
, &fifo
->runlist
[runl
].chan
, head
) {
256 if (chan
->base
.chid
== chid
) {
257 list_del_init(&chan
->head
);
259 nvkm_fifo_kevent(&fifo
->base
, chid
);
264 /* Disable channel. */
265 nvkm_wr32(device
, 0x800004 + (chid
* 0x08), stat
| 0x00000800);
266 nvkm_warn(subdev
, "channel %d: killed\n", chid
);
268 /* Block channel assignments from changing during recovery. */
269 gk104_fifo_recover_runl(fifo
, runl
);
271 /* Schedule recovery for any engines the channel is on. */
272 for_each_set_bit(engn
, &engm
, fifo
->engine_nr
) {
273 struct gk104_fifo_engine_status status
;
274 gk104_fifo_engine_status(fifo
, engn
, &status
);
275 if (!status
.chan
|| status
.chan
->id
!= chid
)
277 gk104_fifo_recover_engn(fifo
, engn
);
282 gk104_fifo_recover_engn(struct gk104_fifo
*fifo
, int engn
)
284 struct nvkm_engine
*engine
= fifo
->engine
[engn
].engine
;
285 struct nvkm_subdev
*subdev
= &fifo
->base
.engine
.subdev
;
286 struct nvkm_device
*device
= subdev
->device
;
287 const u32 runl
= fifo
->engine
[engn
].runl
;
288 const u32 engm
= BIT(engn
);
289 struct gk104_fifo_engine_status status
;
292 assert_spin_locked(&fifo
->base
.lock
);
293 if (fifo
->recover
.engm
& engm
)
295 fifo
->recover
.engm
|= engm
;
297 /* Block channel assignments from changing during recovery. */
298 gk104_fifo_recover_runl(fifo
, runl
);
300 /* Determine which channel (if any) is currently on the engine. */
301 gk104_fifo_engine_status(fifo
, engn
, &status
);
303 /* The channel is not longer viable, kill it. */
304 gk104_fifo_recover_chan(&fifo
->base
, status
.chan
->id
);
307 /* Determine MMU fault ID for the engine, if we're not being
308 * called from the fault handler already.
310 if (!status
.faulted
&& engine
) {
311 mmui
= nvkm_top_fault_id(device
, engine
->subdev
.index
);
313 const struct nvkm_enum
*en
= fifo
->func
->fault
.engine
;
314 for (; en
&& en
->name
; en
++) {
315 if (en
->data2
== engine
->subdev
.index
) {
324 /* Trigger a MMU fault for the engine.
326 * No good idea why this is needed, but nvgpu does something similar,
327 * and it makes recovery from CTXSW_TIMEOUT a lot more reliable.
330 nvkm_wr32(device
, 0x002a30 + (engn
* 0x04), 0x00000100 | mmui
);
332 /* Wait for fault to trigger. */
333 nvkm_msec(device
, 2000,
334 gk104_fifo_engine_status(fifo
, engn
, &status
);
339 /* Release MMU fault trigger, and ACK the fault. */
340 nvkm_wr32(device
, 0x002a30 + (engn
* 0x04), 0x00000000);
341 nvkm_wr32(device
, 0x00259c, BIT(mmui
));
342 nvkm_wr32(device
, 0x002100, 0x10000000);
345 /* Schedule recovery. */
346 nvkm_warn(subdev
, "engine %d: scheduled for recovery\n", engn
);
347 schedule_work(&fifo
->recover
.work
);
350 static const struct nvkm_enum
351 gk104_fifo_bind_reason
[] = {
352 { 0x01, "BIND_NOT_UNBOUND" },
353 { 0x02, "SNOOP_WITHOUT_BAR1" },
354 { 0x03, "UNBIND_WHILE_RUNNING" },
355 { 0x05, "INVALID_RUNLIST" },
356 { 0x06, "INVALID_CTX_TGT" },
357 { 0x0b, "UNBIND_WHILE_PARKED" },
362 gk104_fifo_intr_bind(struct gk104_fifo
*fifo
)
364 struct nvkm_subdev
*subdev
= &fifo
->base
.engine
.subdev
;
365 struct nvkm_device
*device
= subdev
->device
;
366 u32 intr
= nvkm_rd32(device
, 0x00252c);
367 u32 code
= intr
& 0x000000ff;
368 const struct nvkm_enum
*en
=
369 nvkm_enum_find(gk104_fifo_bind_reason
, code
);
371 nvkm_error(subdev
, "BIND_ERROR %02x [%s]\n", code
, en
? en
->name
: "");
374 static const struct nvkm_enum
375 gk104_fifo_sched_reason
[] = {
376 { 0x0a, "CTXSW_TIMEOUT" },
381 gk104_fifo_intr_sched_ctxsw(struct gk104_fifo
*fifo
)
383 struct nvkm_device
*device
= fifo
->base
.engine
.subdev
.device
;
384 unsigned long flags
, engm
= 0;
387 /* We need to ACK the SCHED_ERROR here, and prevent it reasserting,
388 * as MMU_FAULT cannot be triggered while it's pending.
390 spin_lock_irqsave(&fifo
->base
.lock
, flags
);
391 nvkm_mask(device
, 0x002140, 0x00000100, 0x00000000);
392 nvkm_wr32(device
, 0x002100, 0x00000100);
394 for (engn
= 0; engn
< fifo
->engine_nr
; engn
++) {
395 struct gk104_fifo_engine_status status
;
397 gk104_fifo_engine_status(fifo
, engn
, &status
);
398 if (!status
.busy
|| !status
.chsw
)
404 for_each_set_bit(engn
, &engm
, fifo
->engine_nr
)
405 gk104_fifo_recover_engn(fifo
, engn
);
407 nvkm_mask(device
, 0x002140, 0x00000100, 0x00000100);
408 spin_unlock_irqrestore(&fifo
->base
.lock
, flags
);
412 gk104_fifo_intr_sched(struct gk104_fifo
*fifo
)
414 struct nvkm_subdev
*subdev
= &fifo
->base
.engine
.subdev
;
415 struct nvkm_device
*device
= subdev
->device
;
416 u32 intr
= nvkm_rd32(device
, 0x00254c);
417 u32 code
= intr
& 0x000000ff;
418 const struct nvkm_enum
*en
=
419 nvkm_enum_find(gk104_fifo_sched_reason
, code
);
421 nvkm_error(subdev
, "SCHED_ERROR %02x [%s]\n", code
, en
? en
->name
: "");
425 gk104_fifo_intr_sched_ctxsw(fifo
);
433 gk104_fifo_intr_chsw(struct gk104_fifo
*fifo
)
435 struct nvkm_subdev
*subdev
= &fifo
->base
.engine
.subdev
;
436 struct nvkm_device
*device
= subdev
->device
;
437 u32 stat
= nvkm_rd32(device
, 0x00256c);
438 nvkm_error(subdev
, "CHSW_ERROR %08x\n", stat
);
439 nvkm_wr32(device
, 0x00256c, stat
);
443 gk104_fifo_intr_dropped_fault(struct gk104_fifo
*fifo
)
445 struct nvkm_subdev
*subdev
= &fifo
->base
.engine
.subdev
;
446 struct nvkm_device
*device
= subdev
->device
;
447 u32 stat
= nvkm_rd32(device
, 0x00259c);
448 nvkm_error(subdev
, "DROPPED_MMU_FAULT %08x\n", stat
);
452 gk104_fifo_intr_fault(struct gk104_fifo
*fifo
, int unit
)
454 struct nvkm_subdev
*subdev
= &fifo
->base
.engine
.subdev
;
455 struct nvkm_device
*device
= subdev
->device
;
456 u32 inst
= nvkm_rd32(device
, 0x002800 + (unit
* 0x10));
457 u32 valo
= nvkm_rd32(device
, 0x002804 + (unit
* 0x10));
458 u32 vahi
= nvkm_rd32(device
, 0x002808 + (unit
* 0x10));
459 u32 stat
= nvkm_rd32(device
, 0x00280c + (unit
* 0x10));
460 u32 gpc
= (stat
& 0x1f000000) >> 24;
461 u32 client
= (stat
& 0x00001f00) >> 8;
462 u32 write
= (stat
& 0x00000080);
463 u32 hub
= (stat
& 0x00000040);
464 u32 reason
= (stat
& 0x0000000f);
465 const struct nvkm_enum
*er
, *eu
, *ec
;
466 struct nvkm_engine
*engine
= NULL
;
467 struct nvkm_fifo_chan
*chan
;
469 char gpcid
[8] = "", en
[16] = "";
472 er
= nvkm_enum_find(fifo
->func
->fault
.reason
, reason
);
473 eu
= nvkm_enum_find(fifo
->func
->fault
.engine
, unit
);
475 ec
= nvkm_enum_find(fifo
->func
->fault
.hubclient
, client
);
477 ec
= nvkm_enum_find(fifo
->func
->fault
.gpcclient
, client
);
478 snprintf(gpcid
, sizeof(gpcid
), "GPC%d/", gpc
);
481 if (eu
&& eu
->data2
) {
483 case NVKM_SUBDEV_BAR
:
484 nvkm_mask(device
, 0x001704, 0x00000000, 0x00000000);
486 case NVKM_SUBDEV_INSTMEM
:
487 nvkm_mask(device
, 0x001714, 0x00000000, 0x00000000);
489 case NVKM_ENGINE_IFB
:
490 nvkm_mask(device
, 0x001718, 0x00000000, 0x00000000);
493 engine
= nvkm_device_engine(device
, eu
->data2
);
499 enum nvkm_devidx engidx
= nvkm_top_fault(device
, unit
);
500 if (engidx
< NVKM_SUBDEV_NR
) {
501 const char *src
= nvkm_subdev_name
[engidx
];
504 *dst
++ = toupper(*src
++);
506 engine
= nvkm_device_engine(device
, engidx
);
509 snprintf(en
, sizeof(en
), "%s", eu
->name
);
512 spin_lock_irqsave(&fifo
->base
.lock
, flags
);
513 chan
= nvkm_fifo_chan_inst_locked(&fifo
->base
, (u64
)inst
<< 12);
516 "%s fault at %010llx engine %02x [%s] client %02x [%s%s] "
517 "reason %02x [%s] on channel %d [%010llx %s]\n",
518 write
? "write" : "read", (u64
)vahi
<< 32 | valo
,
519 unit
, en
, client
, gpcid
, ec
? ec
->name
: "",
520 reason
, er
? er
->name
: "", chan
? chan
->chid
: -1,
522 chan
? chan
->object
.client
->name
: "unknown");
525 /* Kill the channel that caused the fault. */
527 gk104_fifo_recover_chan(&fifo
->base
, chan
->chid
);
529 /* Channel recovery will probably have already done this for the
530 * correct engine(s), but just in case we can't find the channel
533 for (engn
= 0; engn
< fifo
->engine_nr
&& engine
; engn
++) {
534 if (fifo
->engine
[engn
].engine
== engine
) {
535 gk104_fifo_recover_engn(fifo
, engn
);
540 spin_unlock_irqrestore(&fifo
->base
.lock
, flags
);
543 static const struct nvkm_bitfield gk104_fifo_pbdma_intr_0
[] = {
544 { 0x00000001, "MEMREQ" },
545 { 0x00000002, "MEMACK_TIMEOUT" },
546 { 0x00000004, "MEMACK_EXTRA" },
547 { 0x00000008, "MEMDAT_TIMEOUT" },
548 { 0x00000010, "MEMDAT_EXTRA" },
549 { 0x00000020, "MEMFLUSH" },
550 { 0x00000040, "MEMOP" },
551 { 0x00000080, "LBCONNECT" },
552 { 0x00000100, "LBREQ" },
553 { 0x00000200, "LBACK_TIMEOUT" },
554 { 0x00000400, "LBACK_EXTRA" },
555 { 0x00000800, "LBDAT_TIMEOUT" },
556 { 0x00001000, "LBDAT_EXTRA" },
557 { 0x00002000, "GPFIFO" },
558 { 0x00004000, "GPPTR" },
559 { 0x00008000, "GPENTRY" },
560 { 0x00010000, "GPCRC" },
561 { 0x00020000, "PBPTR" },
562 { 0x00040000, "PBENTRY" },
563 { 0x00080000, "PBCRC" },
564 { 0x00100000, "XBARCONNECT" },
565 { 0x00200000, "METHOD" },
566 { 0x00400000, "METHODCRC" },
567 { 0x00800000, "DEVICE" },
568 { 0x02000000, "SEMAPHORE" },
569 { 0x04000000, "ACQUIRE" },
570 { 0x08000000, "PRI" },
571 { 0x20000000, "NO_CTXSW_SEG" },
572 { 0x40000000, "PBSEG" },
573 { 0x80000000, "SIGNATURE" },
578 gk104_fifo_intr_pbdma_0(struct gk104_fifo
*fifo
, int unit
)
580 struct nvkm_subdev
*subdev
= &fifo
->base
.engine
.subdev
;
581 struct nvkm_device
*device
= subdev
->device
;
582 u32 mask
= nvkm_rd32(device
, 0x04010c + (unit
* 0x2000));
583 u32 stat
= nvkm_rd32(device
, 0x040108 + (unit
* 0x2000)) & mask
;
584 u32 addr
= nvkm_rd32(device
, 0x0400c0 + (unit
* 0x2000));
585 u32 data
= nvkm_rd32(device
, 0x0400c4 + (unit
* 0x2000));
586 u32 chid
= nvkm_rd32(device
, 0x040120 + (unit
* 0x2000)) & 0xfff;
587 u32 subc
= (addr
& 0x00070000) >> 16;
588 u32 mthd
= (addr
& 0x00003ffc);
590 struct nvkm_fifo_chan
*chan
;
594 if (stat
& 0x00800000) {
596 if (nvkm_sw_mthd(device
->sw
, chid
, subc
, mthd
, data
))
601 nvkm_wr32(device
, 0x0400c0 + (unit
* 0x2000), 0x80600008);
604 nvkm_snprintbf(msg
, sizeof(msg
), gk104_fifo_pbdma_intr_0
, show
);
605 chan
= nvkm_fifo_chan_chid(&fifo
->base
, chid
, &flags
);
606 nvkm_error(subdev
, "PBDMA%d: %08x [%s] ch %d [%010llx %s] "
607 "subc %d mthd %04x data %08x\n",
608 unit
, show
, msg
, chid
, chan
? chan
->inst
->addr
: 0,
609 chan
? chan
->object
.client
->name
: "unknown",
611 nvkm_fifo_chan_put(&fifo
->base
, flags
, &chan
);
614 nvkm_wr32(device
, 0x040108 + (unit
* 0x2000), stat
);
617 static const struct nvkm_bitfield gk104_fifo_pbdma_intr_1
[] = {
618 { 0x00000001, "HCE_RE_ILLEGAL_OP" },
619 { 0x00000002, "HCE_RE_ALIGNB" },
620 { 0x00000004, "HCE_PRIV" },
621 { 0x00000008, "HCE_ILLEGAL_MTHD" },
622 { 0x00000010, "HCE_ILLEGAL_CLASS" },
627 gk104_fifo_intr_pbdma_1(struct gk104_fifo
*fifo
, int unit
)
629 struct nvkm_subdev
*subdev
= &fifo
->base
.engine
.subdev
;
630 struct nvkm_device
*device
= subdev
->device
;
631 u32 mask
= nvkm_rd32(device
, 0x04014c + (unit
* 0x2000));
632 u32 stat
= nvkm_rd32(device
, 0x040148 + (unit
* 0x2000)) & mask
;
633 u32 chid
= nvkm_rd32(device
, 0x040120 + (unit
* 0x2000)) & 0xfff;
637 nvkm_snprintbf(msg
, sizeof(msg
), gk104_fifo_pbdma_intr_1
, stat
);
638 nvkm_error(subdev
, "PBDMA%d: %08x [%s] ch %d %08x %08x\n",
639 unit
, stat
, msg
, chid
,
640 nvkm_rd32(device
, 0x040150 + (unit
* 0x2000)),
641 nvkm_rd32(device
, 0x040154 + (unit
* 0x2000)));
644 nvkm_wr32(device
, 0x040148 + (unit
* 0x2000), stat
);
648 gk104_fifo_intr_runlist(struct gk104_fifo
*fifo
)
650 struct nvkm_device
*device
= fifo
->base
.engine
.subdev
.device
;
651 u32 mask
= nvkm_rd32(device
, 0x002a00);
653 int runl
= __ffs(mask
);
654 wake_up(&fifo
->runlist
[runl
].wait
);
655 nvkm_wr32(device
, 0x002a00, 1 << runl
);
656 mask
&= ~(1 << runl
);
661 gk104_fifo_intr_engine(struct gk104_fifo
*fifo
)
663 nvkm_fifo_uevent(&fifo
->base
);
667 gk104_fifo_intr(struct nvkm_fifo
*base
)
669 struct gk104_fifo
*fifo
= gk104_fifo(base
);
670 struct nvkm_subdev
*subdev
= &fifo
->base
.engine
.subdev
;
671 struct nvkm_device
*device
= subdev
->device
;
672 u32 mask
= nvkm_rd32(device
, 0x002140);
673 u32 stat
= nvkm_rd32(device
, 0x002100) & mask
;
675 if (stat
& 0x00000001) {
676 gk104_fifo_intr_bind(fifo
);
677 nvkm_wr32(device
, 0x002100, 0x00000001);
681 if (stat
& 0x00000010) {
682 nvkm_error(subdev
, "PIO_ERROR\n");
683 nvkm_wr32(device
, 0x002100, 0x00000010);
687 if (stat
& 0x00000100) {
688 gk104_fifo_intr_sched(fifo
);
689 nvkm_wr32(device
, 0x002100, 0x00000100);
693 if (stat
& 0x00010000) {
694 gk104_fifo_intr_chsw(fifo
);
695 nvkm_wr32(device
, 0x002100, 0x00010000);
699 if (stat
& 0x00800000) {
700 nvkm_error(subdev
, "FB_FLUSH_TIMEOUT\n");
701 nvkm_wr32(device
, 0x002100, 0x00800000);
705 if (stat
& 0x01000000) {
706 nvkm_error(subdev
, "LB_ERROR\n");
707 nvkm_wr32(device
, 0x002100, 0x01000000);
711 if (stat
& 0x08000000) {
712 gk104_fifo_intr_dropped_fault(fifo
);
713 nvkm_wr32(device
, 0x002100, 0x08000000);
717 if (stat
& 0x10000000) {
718 u32 mask
= nvkm_rd32(device
, 0x00259c);
720 u32 unit
= __ffs(mask
);
721 gk104_fifo_intr_fault(fifo
, unit
);
722 nvkm_wr32(device
, 0x00259c, (1 << unit
));
723 mask
&= ~(1 << unit
);
728 if (stat
& 0x20000000) {
729 u32 mask
= nvkm_rd32(device
, 0x0025a0);
731 u32 unit
= __ffs(mask
);
732 gk104_fifo_intr_pbdma_0(fifo
, unit
);
733 gk104_fifo_intr_pbdma_1(fifo
, unit
);
734 nvkm_wr32(device
, 0x0025a0, (1 << unit
));
735 mask
&= ~(1 << unit
);
740 if (stat
& 0x40000000) {
741 gk104_fifo_intr_runlist(fifo
);
745 if (stat
& 0x80000000) {
746 nvkm_wr32(device
, 0x002100, 0x80000000);
747 gk104_fifo_intr_engine(fifo
);
752 nvkm_error(subdev
, "INTR %08x\n", stat
);
753 nvkm_mask(device
, 0x002140, stat
, 0x00000000);
754 nvkm_wr32(device
, 0x002100, stat
);
759 gk104_fifo_fini(struct nvkm_fifo
*base
)
761 struct gk104_fifo
*fifo
= gk104_fifo(base
);
762 struct nvkm_device
*device
= fifo
->base
.engine
.subdev
.device
;
763 flush_work(&fifo
->recover
.work
);
764 /* allow mmu fault interrupts, even when we're not using fifo */
765 nvkm_mask(device
, 0x002140, 0x10000000, 0x10000000);
769 gk104_fifo_oneinit(struct nvkm_fifo
*base
)
771 struct gk104_fifo
*fifo
= gk104_fifo(base
);
772 struct nvkm_subdev
*subdev
= &fifo
->base
.engine
.subdev
;
773 struct nvkm_device
*device
= subdev
->device
;
774 struct nvkm_vmm
*bar
= nvkm_bar_bar1_vmm(device
);
775 int engn
, runl
, pbid
, ret
, i
, j
;
776 enum nvkm_devidx engidx
;
779 /* Determine number of PBDMAs by checking valid enable bits. */
780 nvkm_wr32(device
, 0x000204, 0xffffffff);
781 fifo
->pbdma_nr
= hweight32(nvkm_rd32(device
, 0x000204));
782 nvkm_debug(subdev
, "%d PBDMA(s)\n", fifo
->pbdma_nr
);
784 /* Read PBDMA->runlist(s) mapping from HW. */
785 if (!(map
= kzalloc(sizeof(*map
) * fifo
->pbdma_nr
, GFP_KERNEL
)))
788 for (i
= 0; i
< fifo
->pbdma_nr
; i
++)
789 map
[i
] = nvkm_rd32(device
, 0x002390 + (i
* 0x04));
791 /* Determine runlist configuration from topology device info. */
793 while ((int)(engidx
= nvkm_top_engine(device
, i
++, &runl
, &engn
)) >= 0) {
794 /* Determine which PBDMA handles requests for this engine. */
795 for (j
= 0, pbid
= -1; j
< fifo
->pbdma_nr
; j
++) {
796 if (map
[j
] & (1 << runl
)) {
802 nvkm_debug(subdev
, "engine %2d: runlist %2d pbdma %2d (%s)\n",
803 engn
, runl
, pbid
, nvkm_subdev_name
[engidx
]);
805 fifo
->engine
[engn
].engine
= nvkm_device_engine(device
, engidx
);
806 fifo
->engine
[engn
].runl
= runl
;
807 fifo
->engine
[engn
].pbid
= pbid
;
808 fifo
->engine_nr
= max(fifo
->engine_nr
, engn
+ 1);
809 fifo
->runlist
[runl
].engm
|= 1 << engn
;
810 fifo
->runlist_nr
= max(fifo
->runlist_nr
, runl
+ 1);
815 for (i
= 0; i
< fifo
->runlist_nr
; i
++) {
816 ret
= nvkm_memory_new(device
, NVKM_MEM_TARGET_INST
,
817 0x8000, 0x1000, false,
818 &fifo
->runlist
[i
].mem
[0]);
822 ret
= nvkm_memory_new(device
, NVKM_MEM_TARGET_INST
,
823 0x8000, 0x1000, false,
824 &fifo
->runlist
[i
].mem
[1]);
828 init_waitqueue_head(&fifo
->runlist
[i
].wait
);
829 INIT_LIST_HEAD(&fifo
->runlist
[i
].chan
);
832 ret
= nvkm_memory_new(device
, NVKM_MEM_TARGET_INST
,
833 fifo
->base
.nr
* 0x200, 0x1000, true,
838 ret
= nvkm_vmm_get(bar
, 12, nvkm_memory_size(fifo
->user
.mem
),
843 return nvkm_memory_map(fifo
->user
.mem
, 0, bar
, fifo
->user
.bar
, NULL
, 0);
847 gk104_fifo_init(struct nvkm_fifo
*base
)
849 struct gk104_fifo
*fifo
= gk104_fifo(base
);
850 struct nvkm_device
*device
= fifo
->base
.engine
.subdev
.device
;
854 nvkm_wr32(device
, 0x000204, (1 << fifo
->pbdma_nr
) - 1);
857 for (i
= 0; i
< fifo
->pbdma_nr
; i
++) {
858 nvkm_mask(device
, 0x04013c + (i
* 0x2000), 0x10000100, 0x00000000);
859 nvkm_wr32(device
, 0x040108 + (i
* 0x2000), 0xffffffff); /* INTR */
860 nvkm_wr32(device
, 0x04010c + (i
* 0x2000), 0xfffffeff); /* INTREN */
864 for (i
= 0; i
< fifo
->pbdma_nr
; i
++) {
865 nvkm_wr32(device
, 0x040148 + (i
* 0x2000), 0xffffffff); /* INTR */
866 nvkm_wr32(device
, 0x04014c + (i
* 0x2000), 0xffffffff); /* INTREN */
869 nvkm_wr32(device
, 0x002254, 0x10000000 | fifo
->user
.bar
->addr
>> 12);
871 nvkm_wr32(device
, 0x002100, 0xffffffff);
872 nvkm_wr32(device
, 0x002140, 0x7fffffff);
876 gk104_fifo_dtor(struct nvkm_fifo
*base
)
878 struct gk104_fifo
*fifo
= gk104_fifo(base
);
879 struct nvkm_device
*device
= fifo
->base
.engine
.subdev
.device
;
882 nvkm_vmm_put(nvkm_bar_bar1_vmm(device
), &fifo
->user
.bar
);
883 nvkm_memory_unref(&fifo
->user
.mem
);
885 for (i
= 0; i
< fifo
->runlist_nr
; i
++) {
886 nvkm_memory_unref(&fifo
->runlist
[i
].mem
[1]);
887 nvkm_memory_unref(&fifo
->runlist
[i
].mem
[0]);
893 static const struct nvkm_fifo_func
895 .dtor
= gk104_fifo_dtor
,
896 .oneinit
= gk104_fifo_oneinit
,
897 .init
= gk104_fifo_init
,
898 .fini
= gk104_fifo_fini
,
899 .intr
= gk104_fifo_intr
,
900 .uevent_init
= gk104_fifo_uevent_init
,
901 .uevent_fini
= gk104_fifo_uevent_fini
,
902 .recover_chan
= gk104_fifo_recover_chan
,
903 .class_get
= gk104_fifo_class_get
,
907 gk104_fifo_new_(const struct gk104_fifo_func
*func
, struct nvkm_device
*device
,
908 int index
, int nr
, struct nvkm_fifo
**pfifo
)
910 struct gk104_fifo
*fifo
;
912 if (!(fifo
= kzalloc(sizeof(*fifo
), GFP_KERNEL
)))
915 INIT_WORK(&fifo
->recover
.work
, gk104_fifo_recover_work
);
916 *pfifo
= &fifo
->base
;
918 return nvkm_fifo_ctor(&gk104_fifo_
, device
, index
, nr
, &fifo
->base
);
921 const struct nvkm_enum
922 gk104_fifo_fault_engine
[] = {
923 { 0x00, "GR", NULL
, NVKM_ENGINE_GR
},
926 { 0x03, "IFB", NULL
, NVKM_ENGINE_IFB
},
927 { 0x04, "BAR1", NULL
, NVKM_SUBDEV_BAR
},
928 { 0x05, "BAR2", NULL
, NVKM_SUBDEV_INSTMEM
},
930 { 0x07, "HOST0", NULL
, NVKM_ENGINE_FIFO
},
931 { 0x08, "HOST1", NULL
, NVKM_ENGINE_FIFO
},
932 { 0x09, "HOST2", NULL
, NVKM_ENGINE_FIFO
},
933 { 0x0a, "HOST3", NULL
, NVKM_ENGINE_FIFO
},
934 { 0x0b, "HOST4", NULL
, NVKM_ENGINE_FIFO
},
935 { 0x0c, "HOST5", NULL
, NVKM_ENGINE_FIFO
},
936 { 0x0d, "HOST6", NULL
, NVKM_ENGINE_FIFO
},
937 { 0x0e, "HOST7", NULL
, NVKM_ENGINE_FIFO
},
939 { 0x10, "MSVLD", NULL
, NVKM_ENGINE_MSVLD
},
940 { 0x11, "MSPPP", NULL
, NVKM_ENGINE_MSPPP
},
942 { 0x14, "MSPDEC", NULL
, NVKM_ENGINE_MSPDEC
},
943 { 0x15, "CE0", NULL
, NVKM_ENGINE_CE0
},
944 { 0x16, "CE1", NULL
, NVKM_ENGINE_CE1
},
947 { 0x19, "MSENC", NULL
, NVKM_ENGINE_MSENC
},
948 { 0x1b, "CE2", NULL
, NVKM_ENGINE_CE2
},
952 const struct nvkm_enum
953 gk104_fifo_fault_reason
[] = {
955 { 0x01, "PDE_SIZE" },
957 { 0x03, "VA_LIMIT_VIOLATION" },
958 { 0x04, "UNBOUND_INST_BLOCK" },
959 { 0x05, "PRIV_VIOLATION" },
960 { 0x06, "RO_VIOLATION" },
961 { 0x07, "WO_VIOLATION" },
962 { 0x08, "PITCH_MASK_VIOLATION" },
963 { 0x09, "WORK_CREATION" },
964 { 0x0a, "UNSUPPORTED_APERTURE" },
965 { 0x0b, "COMPRESSION_FAILURE" },
966 { 0x0c, "UNSUPPORTED_KIND" },
967 { 0x0d, "REGION_VIOLATION" },
968 { 0x0e, "BOTH_PTES_VALID" },
969 { 0x0f, "INFO_TYPE_POISONED" },
973 const struct nvkm_enum
974 gk104_fifo_fault_hubclient
[] = {
982 { 0x07, "HOST_CPU" },
983 { 0x08, "HOST_CPU_NB" },
994 { 0x13, "RASTERTWOD" },
1004 { 0x1d, "DFALCON" },
1006 { 0x1f, "AFALCON" },
1010 const struct nvkm_enum
1011 gk104_fifo_fault_gpcclient
[] = {
1012 { 0x00, "L1_0" }, { 0x01, "T1_0" }, { 0x02, "PE_0" },
1013 { 0x03, "L1_1" }, { 0x04, "T1_1" }, { 0x05, "PE_1" },
1014 { 0x06, "L1_2" }, { 0x07, "T1_2" }, { 0x08, "PE_2" },
1015 { 0x09, "L1_3" }, { 0x0a, "T1_3" }, { 0x0b, "PE_3" },
1023 { 0x13, "L1_4" }, { 0x14, "T1_4" }, { 0x15, "PE_4" },
1024 { 0x16, "L1_5" }, { 0x17, "T1_5" }, { 0x18, "PE_5" },
1025 { 0x19, "L1_6" }, { 0x1a, "T1_6" }, { 0x1b, "PE_6" },
1026 { 0x1c, "L1_7" }, { 0x1d, "T1_7" }, { 0x1e, "PE_7" },
1028 { 0x20, "LTP_UTLB_0" },
1029 { 0x21, "LTP_UTLB_1" },
1030 { 0x22, "LTP_UTLB_2" },
1031 { 0x23, "LTP_UTLB_3" },
1032 { 0x24, "GPC_RGG_UTLB" },
1036 static const struct gk104_fifo_func
1038 .fault
.engine
= gk104_fifo_fault_engine
,
1039 .fault
.reason
= gk104_fifo_fault_reason
,
1040 .fault
.hubclient
= gk104_fifo_fault_hubclient
,
1041 .fault
.gpcclient
= gk104_fifo_fault_gpcclient
,
1043 &gk104_fifo_gpfifo_oclass
,
1049 gk104_fifo_new(struct nvkm_device
*device
, int index
, struct nvkm_fifo
**pfifo
)
1051 return gk104_fifo_new_(&gk104_fifo
, device
, index
, 4096, pfifo
);