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 <core/client.h>
26 #include <core/handle.h>
27 #include <core/namedb.h>
28 #include <core/gpuobj.h>
29 #include <core/engctx.h>
30 #include <core/event.h>
31 #include <nvif/unpack.h>
32 #include <nvif/class.h>
33 #include <core/enum.h>
35 #include <subdev/timer.h>
36 #include <subdev/bar.h>
37 #include <subdev/fb.h>
38 #include <subdev/mmu.h>
40 #include <engine/dmaobj.h>
41 #include <engine/fifo.h>
43 struct nvc0_fifo_priv {
44 struct nouveau_fifo base;
46 struct work_struct fault;
50 struct nouveau_gpuobj *mem[2];
52 wait_queue_head_t wait;
56 struct nouveau_gpuobj *mem;
57 struct nouveau_vma bar;
62 struct nvc0_fifo_base {
63 struct nouveau_fifo_base base;
64 struct nouveau_gpuobj *pgd;
65 struct nouveau_vm *vm;
68 struct nvc0_fifo_chan {
69 struct nouveau_fifo_chan base;
77 /*******************************************************************************
78 * FIFO channel objects
79 ******************************************************************************/
82 nvc0_fifo_runlist_update(struct nvc0_fifo_priv *priv)
84 struct nouveau_bar *bar = nouveau_bar(priv);
85 struct nouveau_gpuobj *cur;
88 mutex_lock(&nv_subdev(priv)->mutex);
89 cur = priv->runlist.mem[priv->runlist.active];
90 priv->runlist.active = !priv->runlist.active;
92 for (i = 0, p = 0; i < 128; i++) {
93 struct nvc0_fifo_chan *chan = (void *)priv->base.channel[i];
94 if (chan && chan->state == RUNNING) {
95 nv_wo32(cur, p + 0, i);
96 nv_wo32(cur, p + 4, 0x00000004);
102 nv_wr32(priv, 0x002270, cur->addr >> 12);
103 nv_wr32(priv, 0x002274, 0x01f00000 | (p >> 3));
105 if (wait_event_timeout(priv->runlist.wait,
106 !(nv_rd32(priv, 0x00227c) & 0x00100000),
107 msecs_to_jiffies(2000)) == 0)
108 nv_error(priv, "runlist update timeout\n");
109 mutex_unlock(&nv_subdev(priv)->mutex);
113 nvc0_fifo_context_attach(struct nouveau_object *parent,
114 struct nouveau_object *object)
116 struct nouveau_bar *bar = nouveau_bar(parent);
117 struct nvc0_fifo_base *base = (void *)parent->parent;
118 struct nouveau_engctx *ectx = (void *)object;
122 switch (nv_engidx(object->engine)) {
123 case NVDEV_ENGINE_SW : return 0;
124 case NVDEV_ENGINE_GR : addr = 0x0210; break;
125 case NVDEV_ENGINE_CE0 : addr = 0x0230; break;
126 case NVDEV_ENGINE_CE1 : addr = 0x0240; break;
127 case NVDEV_ENGINE_MSVLD: addr = 0x0270; break;
128 case NVDEV_ENGINE_VP : addr = 0x0250; break;
129 case NVDEV_ENGINE_PPP : addr = 0x0260; break;
134 if (!ectx->vma.node) {
135 ret = nouveau_gpuobj_map_vm(nv_gpuobj(ectx), base->vm,
136 NV_MEM_ACCESS_RW, &ectx->vma);
140 nv_engctx(ectx)->addr = nv_gpuobj(base)->addr >> 12;
143 nv_wo32(base, addr + 0x00, lower_32_bits(ectx->vma.offset) | 4);
144 nv_wo32(base, addr + 0x04, upper_32_bits(ectx->vma.offset));
150 nvc0_fifo_context_detach(struct nouveau_object *parent, bool suspend,
151 struct nouveau_object *object)
153 struct nouveau_bar *bar = nouveau_bar(parent);
154 struct nvc0_fifo_priv *priv = (void *)parent->engine;
155 struct nvc0_fifo_base *base = (void *)parent->parent;
156 struct nvc0_fifo_chan *chan = (void *)parent;
159 switch (nv_engidx(object->engine)) {
160 case NVDEV_ENGINE_SW : return 0;
161 case NVDEV_ENGINE_GR : addr = 0x0210; break;
162 case NVDEV_ENGINE_CE0 : addr = 0x0230; break;
163 case NVDEV_ENGINE_CE1 : addr = 0x0240; break;
164 case NVDEV_ENGINE_MSVLD: addr = 0x0270; break;
165 case NVDEV_ENGINE_VP : addr = 0x0250; break;
166 case NVDEV_ENGINE_PPP : addr = 0x0260; break;
171 nv_wr32(priv, 0x002634, chan->base.chid);
172 if (!nv_wait(priv, 0x002634, 0xffffffff, chan->base.chid)) {
173 nv_error(priv, "channel %d [%s] kick timeout\n",
174 chan->base.chid, nouveau_client_name(chan));
179 nv_wo32(base, addr + 0x00, 0x00000000);
180 nv_wo32(base, addr + 0x04, 0x00000000);
186 nvc0_fifo_chan_ctor(struct nouveau_object *parent,
187 struct nouveau_object *engine,
188 struct nouveau_oclass *oclass, void *data, u32 size,
189 struct nouveau_object **pobject)
192 struct nv50_channel_gpfifo_v0 v0;
194 struct nouveau_bar *bar = nouveau_bar(parent);
195 struct nvc0_fifo_priv *priv = (void *)engine;
196 struct nvc0_fifo_base *base = (void *)parent;
197 struct nvc0_fifo_chan *chan;
198 u64 usermem, ioffset, ilength;
201 nv_ioctl(parent, "create channel gpfifo size %d\n", size);
202 if (nvif_unpack(args->v0, 0, 0, false)) {
203 nv_ioctl(parent, "create channel gpfifo vers %d pushbuf %08x "
204 "ioffset %016llx ilength %08x\n",
205 args->v0.version, args->v0.pushbuf, args->v0.ioffset,
210 ret = nouveau_fifo_channel_create(parent, engine, oclass, 1,
211 priv->user.bar.offset, 0x1000,
213 (1ULL << NVDEV_ENGINE_SW) |
214 (1ULL << NVDEV_ENGINE_GR) |
215 (1ULL << NVDEV_ENGINE_CE0) |
216 (1ULL << NVDEV_ENGINE_CE1) |
217 (1ULL << NVDEV_ENGINE_MSVLD) |
218 (1ULL << NVDEV_ENGINE_VP) |
219 (1ULL << NVDEV_ENGINE_PPP), &chan);
220 *pobject = nv_object(chan);
224 args->v0.chid = chan->base.chid;
226 nv_parent(chan)->context_attach = nvc0_fifo_context_attach;
227 nv_parent(chan)->context_detach = nvc0_fifo_context_detach;
229 usermem = chan->base.chid * 0x1000;
230 ioffset = args->v0.ioffset;
231 ilength = order_base_2(args->v0.ilength / 8);
233 for (i = 0; i < 0x1000; i += 4)
234 nv_wo32(priv->user.mem, usermem + i, 0x00000000);
236 nv_wo32(base, 0x08, lower_32_bits(priv->user.mem->addr + usermem));
237 nv_wo32(base, 0x0c, upper_32_bits(priv->user.mem->addr + usermem));
238 nv_wo32(base, 0x10, 0x0000face);
239 nv_wo32(base, 0x30, 0xfffff902);
240 nv_wo32(base, 0x48, lower_32_bits(ioffset));
241 nv_wo32(base, 0x4c, upper_32_bits(ioffset) | (ilength << 16));
242 nv_wo32(base, 0x54, 0x00000002);
243 nv_wo32(base, 0x84, 0x20400000);
244 nv_wo32(base, 0x94, 0x30000001);
245 nv_wo32(base, 0x9c, 0x00000100);
246 nv_wo32(base, 0xa4, 0x1f1f1f1f);
247 nv_wo32(base, 0xa8, 0x1f1f1f1f);
248 nv_wo32(base, 0xac, 0x0000001f);
249 nv_wo32(base, 0xb8, 0xf8000000);
250 nv_wo32(base, 0xf8, 0x10003080); /* 0x002310 */
251 nv_wo32(base, 0xfc, 0x10000010); /* 0x002350 */
257 nvc0_fifo_chan_init(struct nouveau_object *object)
259 struct nouveau_gpuobj *base = nv_gpuobj(object->parent);
260 struct nvc0_fifo_priv *priv = (void *)object->engine;
261 struct nvc0_fifo_chan *chan = (void *)object;
262 u32 chid = chan->base.chid;
265 ret = nouveau_fifo_channel_init(&chan->base);
269 nv_wr32(priv, 0x003000 + (chid * 8), 0xc0000000 | base->addr >> 12);
271 if (chan->state == STOPPED && (chan->state = RUNNING) == RUNNING) {
272 nv_wr32(priv, 0x003004 + (chid * 8), 0x001f0001);
273 nvc0_fifo_runlist_update(priv);
279 static void nvc0_fifo_intr_engine(struct nvc0_fifo_priv *priv);
282 nvc0_fifo_chan_fini(struct nouveau_object *object, bool suspend)
284 struct nvc0_fifo_priv *priv = (void *)object->engine;
285 struct nvc0_fifo_chan *chan = (void *)object;
286 u32 chid = chan->base.chid;
288 if (chan->state == RUNNING && (chan->state = STOPPED) == STOPPED) {
289 nv_mask(priv, 0x003004 + (chid * 8), 0x00000001, 0x00000000);
290 nvc0_fifo_runlist_update(priv);
293 nvc0_fifo_intr_engine(priv);
295 nv_wr32(priv, 0x003000 + (chid * 8), 0x00000000);
296 return nouveau_fifo_channel_fini(&chan->base, suspend);
299 static struct nouveau_ofuncs
301 .ctor = nvc0_fifo_chan_ctor,
302 .dtor = _nouveau_fifo_channel_dtor,
303 .init = nvc0_fifo_chan_init,
304 .fini = nvc0_fifo_chan_fini,
305 .map = _nouveau_fifo_channel_map,
306 .rd32 = _nouveau_fifo_channel_rd32,
307 .wr32 = _nouveau_fifo_channel_wr32,
308 .ntfy = _nouveau_fifo_channel_ntfy
311 static struct nouveau_oclass
312 nvc0_fifo_sclass[] = {
313 { FERMI_CHANNEL_GPFIFO, &nvc0_fifo_ofuncs },
317 /*******************************************************************************
318 * FIFO context - instmem heap and vm setup
319 ******************************************************************************/
322 nvc0_fifo_context_ctor(struct nouveau_object *parent,
323 struct nouveau_object *engine,
324 struct nouveau_oclass *oclass, void *data, u32 size,
325 struct nouveau_object **pobject)
327 struct nvc0_fifo_base *base;
330 ret = nouveau_fifo_context_create(parent, engine, oclass, NULL, 0x1000,
331 0x1000, NVOBJ_FLAG_ZERO_ALLOC |
332 NVOBJ_FLAG_HEAP, &base);
333 *pobject = nv_object(base);
337 ret = nouveau_gpuobj_new(nv_object(base), NULL, 0x10000, 0x1000, 0,
342 nv_wo32(base, 0x0200, lower_32_bits(base->pgd->addr));
343 nv_wo32(base, 0x0204, upper_32_bits(base->pgd->addr));
344 nv_wo32(base, 0x0208, 0xffffffff);
345 nv_wo32(base, 0x020c, 0x000000ff);
347 ret = nouveau_vm_ref(nouveau_client(parent)->vm, &base->vm, base->pgd);
355 nvc0_fifo_context_dtor(struct nouveau_object *object)
357 struct nvc0_fifo_base *base = (void *)object;
358 nouveau_vm_ref(NULL, &base->vm, base->pgd);
359 nouveau_gpuobj_ref(NULL, &base->pgd);
360 nouveau_fifo_context_destroy(&base->base);
363 static struct nouveau_oclass
365 .handle = NV_ENGCTX(FIFO, 0xc0),
366 .ofuncs = &(struct nouveau_ofuncs) {
367 .ctor = nvc0_fifo_context_ctor,
368 .dtor = nvc0_fifo_context_dtor,
369 .init = _nouveau_fifo_context_init,
370 .fini = _nouveau_fifo_context_fini,
371 .rd32 = _nouveau_fifo_context_rd32,
372 .wr32 = _nouveau_fifo_context_wr32,
376 /*******************************************************************************
378 ******************************************************************************/
381 nvc0_fifo_engidx(struct nvc0_fifo_priv *priv, u32 engn)
384 case NVDEV_ENGINE_GR : engn = 0; break;
385 case NVDEV_ENGINE_MSVLD: engn = 1; break;
386 case NVDEV_ENGINE_PPP : engn = 2; break;
387 case NVDEV_ENGINE_VP : engn = 3; break;
388 case NVDEV_ENGINE_CE0 : engn = 4; break;
389 case NVDEV_ENGINE_CE1 : engn = 5; break;
397 static inline struct nouveau_engine *
398 nvc0_fifo_engine(struct nvc0_fifo_priv *priv, u32 engn)
401 case 0: engn = NVDEV_ENGINE_GR; break;
402 case 1: engn = NVDEV_ENGINE_MSVLD; break;
403 case 2: engn = NVDEV_ENGINE_PPP; break;
404 case 3: engn = NVDEV_ENGINE_VP; break;
405 case 4: engn = NVDEV_ENGINE_CE0; break;
406 case 5: engn = NVDEV_ENGINE_CE1; break;
411 return nouveau_engine(priv, engn);
415 nvc0_fifo_recover_work(struct work_struct *work)
417 struct nvc0_fifo_priv *priv = container_of(work, typeof(*priv), fault);
418 struct nouveau_object *engine;
423 spin_lock_irqsave(&priv->base.lock, flags);
426 spin_unlock_irqrestore(&priv->base.lock, flags);
428 for (todo = mask; engn = __ffs64(todo), todo; todo &= ~(1 << engn))
429 engm |= 1 << nvc0_fifo_engidx(priv, engn);
430 nv_mask(priv, 0x002630, engm, engm);
432 for (todo = mask; engn = __ffs64(todo), todo; todo &= ~(1 << engn)) {
433 if ((engine = (void *)nouveau_engine(priv, engn))) {
434 nv_ofuncs(engine)->fini(engine, false);
435 WARN_ON(nv_ofuncs(engine)->init(engine));
439 nvc0_fifo_runlist_update(priv);
440 nv_wr32(priv, 0x00262c, engm);
441 nv_mask(priv, 0x002630, engm, 0x00000000);
445 nvc0_fifo_recover(struct nvc0_fifo_priv *priv, struct nouveau_engine *engine,
446 struct nvc0_fifo_chan *chan)
448 u32 chid = chan->base.chid;
451 nv_error(priv, "%s engine fault on channel %d, recovering...\n",
452 nv_subdev(engine)->name, chid);
454 nv_mask(priv, 0x003004 + (chid * 0x08), 0x00000001, 0x00000000);
455 chan->state = KILLED;
457 spin_lock_irqsave(&priv->base.lock, flags);
458 priv->mask |= 1ULL << nv_engidx(engine);
459 spin_unlock_irqrestore(&priv->base.lock, flags);
460 schedule_work(&priv->fault);
464 nvc0_fifo_swmthd(struct nvc0_fifo_priv *priv, u32 chid, u32 mthd, u32 data)
466 struct nvc0_fifo_chan *chan = NULL;
467 struct nouveau_handle *bind;
471 spin_lock_irqsave(&priv->base.lock, flags);
472 if (likely(chid >= priv->base.min && chid <= priv->base.max))
473 chan = (void *)priv->base.channel[chid];
477 bind = nouveau_namedb_get_class(nv_namedb(chan), 0x906e);
479 if (!mthd || !nv_call(bind->object, mthd, data))
481 nouveau_namedb_put(bind);
485 spin_unlock_irqrestore(&priv->base.lock, flags);
489 static const struct nouveau_enum
490 nvc0_fifo_sched_reason[] = {
491 { 0x0a, "CTXSW_TIMEOUT" },
496 nvc0_fifo_intr_sched_ctxsw(struct nvc0_fifo_priv *priv)
498 struct nouveau_engine *engine;
499 struct nvc0_fifo_chan *chan;
502 for (engn = 0; engn < 6; engn++) {
503 u32 stat = nv_rd32(priv, 0x002640 + (engn * 0x04));
504 u32 busy = (stat & 0x80000000);
505 u32 save = (stat & 0x00100000); /* maybe? */
506 u32 unk0 = (stat & 0x00040000);
507 u32 unk1 = (stat & 0x00001000);
508 u32 chid = (stat & 0x0000007f);
511 if (busy && unk0 && unk1) {
512 if (!(chan = (void *)priv->base.channel[chid]))
514 if (!(engine = nvc0_fifo_engine(priv, engn)))
516 nvc0_fifo_recover(priv, engine, chan);
522 nvc0_fifo_intr_sched(struct nvc0_fifo_priv *priv)
524 u32 intr = nv_rd32(priv, 0x00254c);
525 u32 code = intr & 0x000000ff;
526 const struct nouveau_enum *en;
529 en = nouveau_enum_find(nvc0_fifo_sched_reason, code);
531 snprintf(enunk, sizeof(enunk), "UNK%02x", code);
533 nv_error(priv, "SCHED_ERROR [ %s ]\n", en ? en->name : enunk);
537 nvc0_fifo_intr_sched_ctxsw(priv);
544 static const struct nouveau_enum
545 nvc0_fifo_fault_engine[] = {
546 { 0x00, "PGRAPH", NULL, NVDEV_ENGINE_GR },
547 { 0x03, "PEEPHOLE", NULL, NVDEV_ENGINE_IFB },
548 { 0x04, "BAR1", NULL, NVDEV_SUBDEV_BAR },
549 { 0x05, "BAR3", NULL, NVDEV_SUBDEV_INSTMEM },
550 { 0x07, "PFIFO", NULL, NVDEV_ENGINE_FIFO },
551 { 0x10, "PMSVLD", NULL, NVDEV_ENGINE_MSVLD },
552 { 0x11, "PPPP", NULL, NVDEV_ENGINE_PPP },
553 { 0x13, "PCOUNTER" },
554 { 0x14, "PVP", NULL, NVDEV_ENGINE_VP },
555 { 0x15, "PCE0", NULL, NVDEV_ENGINE_CE0 },
556 { 0x16, "PCE1", NULL, NVDEV_ENGINE_CE1 },
561 static const struct nouveau_enum
562 nvc0_fifo_fault_reason[] = {
563 { 0x00, "PT_NOT_PRESENT" },
564 { 0x01, "PT_TOO_SHORT" },
565 { 0x02, "PAGE_NOT_PRESENT" },
566 { 0x03, "VM_LIMIT_EXCEEDED" },
567 { 0x04, "NO_CHANNEL" },
568 { 0x05, "PAGE_SYSTEM_ONLY" },
569 { 0x06, "PAGE_READ_ONLY" },
570 { 0x0a, "COMPRESSED_SYSRAM" },
571 { 0x0c, "INVALID_STORAGE_TYPE" },
575 static const struct nouveau_enum
576 nvc0_fifo_fault_hubclient[] = {
579 { 0x04, "DISPATCH" },
582 { 0x07, "BAR_READ" },
583 { 0x08, "BAR_WRITE" },
587 { 0x11, "PCOUNTER" },
590 { 0x15, "CCACHE_POST" },
594 static const struct nouveau_enum
595 nvc0_fifo_fault_gpcclient[] = {
604 nvc0_fifo_intr_fault(struct nvc0_fifo_priv *priv, int unit)
606 u32 inst = nv_rd32(priv, 0x002800 + (unit * 0x10));
607 u32 valo = nv_rd32(priv, 0x002804 + (unit * 0x10));
608 u32 vahi = nv_rd32(priv, 0x002808 + (unit * 0x10));
609 u32 stat = nv_rd32(priv, 0x00280c + (unit * 0x10));
610 u32 gpc = (stat & 0x1f000000) >> 24;
611 u32 client = (stat & 0x00001f00) >> 8;
612 u32 write = (stat & 0x00000080);
613 u32 hub = (stat & 0x00000040);
614 u32 reason = (stat & 0x0000000f);
615 struct nouveau_object *engctx = NULL, *object;
616 struct nouveau_engine *engine = NULL;
617 const struct nouveau_enum *er, *eu, *ec;
623 er = nouveau_enum_find(nvc0_fifo_fault_reason, reason);
625 snprintf(erunk, sizeof(erunk), "UNK%02X", reason);
627 eu = nouveau_enum_find(nvc0_fifo_fault_engine, unit);
630 case NVDEV_SUBDEV_BAR:
631 nv_mask(priv, 0x001704, 0x00000000, 0x00000000);
633 case NVDEV_SUBDEV_INSTMEM:
634 nv_mask(priv, 0x001714, 0x00000000, 0x00000000);
636 case NVDEV_ENGINE_IFB:
637 nv_mask(priv, 0x001718, 0x00000000, 0x00000000);
640 engine = nouveau_engine(priv, eu->data2);
642 engctx = nouveau_engctx_get(engine, inst);
646 snprintf(euunk, sizeof(euunk), "UNK%02x", unit);
650 ec = nouveau_enum_find(nvc0_fifo_fault_hubclient, client);
652 ec = nouveau_enum_find(nvc0_fifo_fault_gpcclient, client);
653 snprintf(gpcid, sizeof(gpcid), "%d", gpc);
657 snprintf(ecunk, sizeof(ecunk), "UNK%02x", client);
659 nv_error(priv, "%s fault at 0x%010llx [%s] from %s/%s%s%s%s on "
660 "channel 0x%010llx [%s]\n", write ? "write" : "read",
661 (u64)vahi << 32 | valo, er ? er->name : erunk,
662 eu ? eu->name : euunk, hub ? "" : "GPC", gpcid, hub ? "" : "/",
663 ec ? ec->name : ecunk, (u64)inst << 12,
664 nouveau_client_name(engctx));
668 switch (nv_mclass(object)) {
669 case FERMI_CHANNEL_GPFIFO:
670 nvc0_fifo_recover(priv, engine, (void *)object);
673 object = object->parent;
676 nouveau_engctx_put(engctx);
679 static const struct nouveau_bitfield
680 nvc0_fifo_pbdma_intr[] = {
681 /* { 0x00008000, "" } seen with null ib push */
682 { 0x00200000, "ILLEGAL_MTHD" },
683 { 0x00800000, "EMPTY_SUBC" },
688 nvc0_fifo_intr_pbdma(struct nvc0_fifo_priv *priv, int unit)
690 u32 stat = nv_rd32(priv, 0x040108 + (unit * 0x2000));
691 u32 addr = nv_rd32(priv, 0x0400c0 + (unit * 0x2000));
692 u32 data = nv_rd32(priv, 0x0400c4 + (unit * 0x2000));
693 u32 chid = nv_rd32(priv, 0x040120 + (unit * 0x2000)) & 0x7f;
694 u32 subc = (addr & 0x00070000) >> 16;
695 u32 mthd = (addr & 0x00003ffc);
698 if (stat & 0x00800000) {
699 if (!nvc0_fifo_swmthd(priv, chid, mthd, data))
704 nv_error(priv, "PBDMA%d:", unit);
705 nouveau_bitfield_print(nvc0_fifo_pbdma_intr, show);
708 "PBDMA%d: ch %d [%s] subc %d mthd 0x%04x data 0x%08x\n",
710 nouveau_client_name_for_fifo_chid(&priv->base, chid),
714 nv_wr32(priv, 0x0400c0 + (unit * 0x2000), 0x80600008);
715 nv_wr32(priv, 0x040108 + (unit * 0x2000), stat);
719 nvc0_fifo_intr_runlist(struct nvc0_fifo_priv *priv)
721 u32 intr = nv_rd32(priv, 0x002a00);
723 if (intr & 0x10000000) {
724 wake_up(&priv->runlist.wait);
725 nv_wr32(priv, 0x002a00, 0x10000000);
730 nv_error(priv, "RUNLIST 0x%08x\n", intr);
731 nv_wr32(priv, 0x002a00, intr);
736 nvc0_fifo_intr_engine_unit(struct nvc0_fifo_priv *priv, int engn)
738 u32 intr = nv_rd32(priv, 0x0025a8 + (engn * 0x04));
739 u32 inte = nv_rd32(priv, 0x002628);
742 nv_wr32(priv, 0x0025a8 + (engn * 0x04), intr);
744 for (unkn = 0; unkn < 8; unkn++) {
745 u32 ints = (intr >> (unkn * 0x04)) & inte;
747 nouveau_fifo_uevent(&priv->base);
751 nv_error(priv, "ENGINE %d %d %01x", engn, unkn, ints);
752 nv_mask(priv, 0x002628, ints, 0);
758 nvc0_fifo_intr_engine(struct nvc0_fifo_priv *priv)
760 u32 mask = nv_rd32(priv, 0x0025a4);
762 u32 unit = __ffs(mask);
763 nvc0_fifo_intr_engine_unit(priv, unit);
764 mask &= ~(1 << unit);
769 nvc0_fifo_intr(struct nouveau_subdev *subdev)
771 struct nvc0_fifo_priv *priv = (void *)subdev;
772 u32 mask = nv_rd32(priv, 0x002140);
773 u32 stat = nv_rd32(priv, 0x002100) & mask;
775 if (stat & 0x00000001) {
776 u32 intr = nv_rd32(priv, 0x00252c);
777 nv_warn(priv, "INTR 0x00000001: 0x%08x\n", intr);
778 nv_wr32(priv, 0x002100, 0x00000001);
782 if (stat & 0x00000100) {
783 nvc0_fifo_intr_sched(priv);
784 nv_wr32(priv, 0x002100, 0x00000100);
788 if (stat & 0x00010000) {
789 u32 intr = nv_rd32(priv, 0x00256c);
790 nv_warn(priv, "INTR 0x00010000: 0x%08x\n", intr);
791 nv_wr32(priv, 0x002100, 0x00010000);
795 if (stat & 0x01000000) {
796 u32 intr = nv_rd32(priv, 0x00258c);
797 nv_warn(priv, "INTR 0x01000000: 0x%08x\n", intr);
798 nv_wr32(priv, 0x002100, 0x01000000);
802 if (stat & 0x10000000) {
803 u32 mask = nv_rd32(priv, 0x00259c);
805 u32 unit = __ffs(mask);
806 nvc0_fifo_intr_fault(priv, unit);
807 nv_wr32(priv, 0x00259c, (1 << unit));
808 mask &= ~(1 << unit);
813 if (stat & 0x20000000) {
814 u32 mask = nv_rd32(priv, 0x0025a0);
816 u32 unit = __ffs(mask);
817 nvc0_fifo_intr_pbdma(priv, unit);
818 nv_wr32(priv, 0x0025a0, (1 << unit));
819 mask &= ~(1 << unit);
824 if (stat & 0x40000000) {
825 nvc0_fifo_intr_runlist(priv);
829 if (stat & 0x80000000) {
830 nvc0_fifo_intr_engine(priv);
835 nv_error(priv, "INTR 0x%08x\n", stat);
836 nv_mask(priv, 0x002140, stat, 0x00000000);
837 nv_wr32(priv, 0x002100, stat);
842 nvc0_fifo_uevent_init(struct nvkm_event *event, int type, int index)
844 struct nouveau_fifo *fifo = container_of(event, typeof(*fifo), uevent);
845 nv_mask(fifo, 0x002140, 0x80000000, 0x80000000);
849 nvc0_fifo_uevent_fini(struct nvkm_event *event, int type, int index)
851 struct nouveau_fifo *fifo = container_of(event, typeof(*fifo), uevent);
852 nv_mask(fifo, 0x002140, 0x80000000, 0x00000000);
855 static const struct nvkm_event_func
856 nvc0_fifo_uevent_func = {
857 .ctor = nouveau_fifo_uevent_ctor,
858 .init = nvc0_fifo_uevent_init,
859 .fini = nvc0_fifo_uevent_fini,
863 nvc0_fifo_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
864 struct nouveau_oclass *oclass, void *data, u32 size,
865 struct nouveau_object **pobject)
867 struct nvc0_fifo_priv *priv;
870 ret = nouveau_fifo_create(parent, engine, oclass, 0, 127, &priv);
871 *pobject = nv_object(priv);
875 INIT_WORK(&priv->fault, nvc0_fifo_recover_work);
877 ret = nouveau_gpuobj_new(nv_object(priv), NULL, 0x1000, 0x1000, 0,
878 &priv->runlist.mem[0]);
882 ret = nouveau_gpuobj_new(nv_object(priv), NULL, 0x1000, 0x1000, 0,
883 &priv->runlist.mem[1]);
887 init_waitqueue_head(&priv->runlist.wait);
889 ret = nouveau_gpuobj_new(nv_object(priv), NULL, 128 * 0x1000, 0x1000, 0,
894 ret = nouveau_gpuobj_map(priv->user.mem, NV_MEM_ACCESS_RW,
899 ret = nvkm_event_init(&nvc0_fifo_uevent_func, 1, 1, &priv->base.uevent);
903 nv_subdev(priv)->unit = 0x00000100;
904 nv_subdev(priv)->intr = nvc0_fifo_intr;
905 nv_engine(priv)->cclass = &nvc0_fifo_cclass;
906 nv_engine(priv)->sclass = nvc0_fifo_sclass;
911 nvc0_fifo_dtor(struct nouveau_object *object)
913 struct nvc0_fifo_priv *priv = (void *)object;
915 nouveau_gpuobj_unmap(&priv->user.bar);
916 nouveau_gpuobj_ref(NULL, &priv->user.mem);
917 nouveau_gpuobj_ref(NULL, &priv->runlist.mem[0]);
918 nouveau_gpuobj_ref(NULL, &priv->runlist.mem[1]);
920 nouveau_fifo_destroy(&priv->base);
924 nvc0_fifo_init(struct nouveau_object *object)
926 struct nvc0_fifo_priv *priv = (void *)object;
929 ret = nouveau_fifo_init(&priv->base);
933 nv_wr32(priv, 0x000204, 0xffffffff);
934 nv_wr32(priv, 0x002204, 0xffffffff);
936 priv->spoon_nr = hweight32(nv_rd32(priv, 0x002204));
937 nv_debug(priv, "%d PBDMA unit(s)\n", priv->spoon_nr);
939 /* assign engines to PBDMAs */
940 if (priv->spoon_nr >= 3) {
941 nv_wr32(priv, 0x002208, ~(1 << 0)); /* PGRAPH */
942 nv_wr32(priv, 0x00220c, ~(1 << 1)); /* PVP */
943 nv_wr32(priv, 0x002210, ~(1 << 1)); /* PPP */
944 nv_wr32(priv, 0x002214, ~(1 << 1)); /* PMSVLD */
945 nv_wr32(priv, 0x002218, ~(1 << 2)); /* PCE0 */
946 nv_wr32(priv, 0x00221c, ~(1 << 1)); /* PCE1 */
950 for (i = 0; i < priv->spoon_nr; i++) {
951 nv_mask(priv, 0x04013c + (i * 0x2000), 0x10000100, 0x00000000);
952 nv_wr32(priv, 0x040108 + (i * 0x2000), 0xffffffff); /* INTR */
953 nv_wr32(priv, 0x04010c + (i * 0x2000), 0xfffffeff); /* INTREN */
956 nv_mask(priv, 0x002200, 0x00000001, 0x00000001);
957 nv_wr32(priv, 0x002254, 0x10000000 | priv->user.bar.offset >> 12);
959 nv_wr32(priv, 0x002100, 0xffffffff);
960 nv_wr32(priv, 0x002140, 0x7fffffff);
961 nv_wr32(priv, 0x002628, 0x00000001); /* ENGINE_INTR_EN */
965 struct nouveau_oclass *
966 nvc0_fifo_oclass = &(struct nouveau_oclass) {
967 .handle = NV_ENGINE(FIFO, 0xc0),
968 .ofuncs = &(struct nouveau_ofuncs) {
969 .ctor = nvc0_fifo_ctor,
970 .dtor = nvc0_fifo_dtor,
971 .init = nvc0_fifo_init,
972 .fini = _nouveau_fifo_fini,