blob: 4307dda086ca951dcbe7a0de1d49ba057a352a5e [file] [log] [blame]
Ben Skeggs4b223ee2010-08-03 10:00:56 +10001/*
Ben Skeggsebb945a2012-07-20 08:17:34 +10002 * Copyright 2012 Red Hat Inc.
Ben Skeggs4b223ee2010-08-03 10:00:56 +10003 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
22 * Authors: Ben Skeggs
23 */
24
Ben Skeggsebb945a2012-07-20 08:17:34 +100025#include <core/client.h>
26#include <core/handle.h>
27#include <core/namedb.h>
28#include <core/gpuobj.h>
29#include <core/engctx.h>
Ben Skeggs9bd2ddb2013-01-31 13:51:20 +100030#include <core/event.h>
Ben Skeggsebb945a2012-07-20 08:17:34 +100031#include <core/class.h>
Ben Skeggsebb945a2012-07-20 08:17:34 +100032#include <core/enum.h>
Ben Skeggs4b223ee2010-08-03 10:00:56 +100033
Ben Skeggsebb945a2012-07-20 08:17:34 +100034#include <subdev/timer.h>
35#include <subdev/bar.h>
Ben Skeggs52225552013-12-23 01:51:16 +100036#include <subdev/fb.h>
Ben Skeggsebb945a2012-07-20 08:17:34 +100037#include <subdev/vm.h>
38
39#include <engine/dmaobj.h>
Ben Skeggs02a841d2012-07-04 23:44:54 +100040#include <engine/fifo.h>
Ben Skeggsb2b09932010-11-24 10:47:15 +100041
42struct nvc0_fifo_priv {
Ben Skeggsebb945a2012-07-20 08:17:34 +100043 struct nouveau_fifo base;
Ben Skeggsa07d0e72014-02-22 00:28:47 +100044 struct {
45 struct nouveau_gpuobj *mem[2];
46 int active;
47 wait_queue_head_t wait;
48 } runlist;
Ben Skeggs9da226f2012-07-13 16:54:45 +100049 struct {
50 struct nouveau_gpuobj *mem;
51 struct nouveau_vma bar;
52 } user;
Ben Skeggsec9c0882010-12-31 12:10:49 +100053 int spoon_nr;
Ben Skeggsb2b09932010-11-24 10:47:15 +100054};
55
Ben Skeggsebb945a2012-07-20 08:17:34 +100056struct nvc0_fifo_base {
57 struct nouveau_fifo_base base;
58 struct nouveau_gpuobj *pgd;
59 struct nouveau_vm *vm;
60};
61
Ben Skeggsb2b09932010-11-24 10:47:15 +100062struct nvc0_fifo_chan {
Ben Skeggsc420b2d2012-05-01 20:48:08 +100063 struct nouveau_fifo_chan base;
Ben Skeggsb2b09932010-11-24 10:47:15 +100064};
65
Ben Skeggsebb945a2012-07-20 08:17:34 +100066/*******************************************************************************
67 * FIFO channel objects
68 ******************************************************************************/
69
Ben Skeggsb2b09932010-11-24 10:47:15 +100070static void
Ben Skeggs03574662014-01-28 11:47:46 +100071nvc0_fifo_runlist_update(struct nvc0_fifo_priv *priv)
Ben Skeggsb2b09932010-11-24 10:47:15 +100072{
Ben Skeggsebb945a2012-07-20 08:17:34 +100073 struct nouveau_bar *bar = nouveau_bar(priv);
Ben Skeggsb2b09932010-11-24 10:47:15 +100074 struct nouveau_gpuobj *cur;
75 int i, p;
76
Ben Skeggsfadb1712013-05-13 10:02:11 +100077 mutex_lock(&nv_subdev(priv)->mutex);
Ben Skeggsa07d0e72014-02-22 00:28:47 +100078 cur = priv->runlist.mem[priv->runlist.active];
79 priv->runlist.active = !priv->runlist.active;
Ben Skeggsb2b09932010-11-24 10:47:15 +100080
81 for (i = 0, p = 0; i < 128; i++) {
Ben Skeggsebb945a2012-07-20 08:17:34 +100082 if (!(nv_rd32(priv, 0x003004 + (i * 8)) & 1))
Ben Skeggsb2b09932010-11-24 10:47:15 +100083 continue;
84 nv_wo32(cur, p + 0, i);
85 nv_wo32(cur, p + 4, 0x00000004);
86 p += 8;
87 }
Ben Skeggsebb945a2012-07-20 08:17:34 +100088 bar->flush(bar);
Ben Skeggsb2b09932010-11-24 10:47:15 +100089
Ben Skeggsebb945a2012-07-20 08:17:34 +100090 nv_wr32(priv, 0x002270, cur->addr >> 12);
91 nv_wr32(priv, 0x002274, 0x01f00000 | (p >> 3));
92 if (!nv_wait(priv, 0x00227c, 0x00100000, 0x00000000))
Ben Skeggs03574662014-01-28 11:47:46 +100093 nv_error(priv, "runlist update failed\n");
Ben Skeggsfadb1712013-05-13 10:02:11 +100094 mutex_unlock(&nv_subdev(priv)->mutex);
Ben Skeggsb2b09932010-11-24 10:47:15 +100095}
Ben Skeggs4b223ee2010-08-03 10:00:56 +100096
Ben Skeggsc420b2d2012-05-01 20:48:08 +100097static int
Ben Skeggsebb945a2012-07-20 08:17:34 +100098nvc0_fifo_context_attach(struct nouveau_object *parent,
99 struct nouveau_object *object)
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000100{
Ben Skeggsebb945a2012-07-20 08:17:34 +1000101 struct nouveau_bar *bar = nouveau_bar(parent);
102 struct nvc0_fifo_base *base = (void *)parent->parent;
103 struct nouveau_engctx *ectx = (void *)object;
104 u32 addr;
105 int ret;
Ben Skeggsb2b09932010-11-24 10:47:15 +1000106
Ben Skeggsebb945a2012-07-20 08:17:34 +1000107 switch (nv_engidx(object->engine)) {
108 case NVDEV_ENGINE_SW : return 0;
109 case NVDEV_ENGINE_GR : addr = 0x0210; break;
110 case NVDEV_ENGINE_COPY0: addr = 0x0230; break;
111 case NVDEV_ENGINE_COPY1: addr = 0x0240; break;
Maarten Lankhorst23c14ed2012-11-23 11:08:23 +1000112 case NVDEV_ENGINE_BSP : addr = 0x0270; break;
113 case NVDEV_ENGINE_VP : addr = 0x0250; break;
114 case NVDEV_ENGINE_PPP : addr = 0x0260; break;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000115 default:
116 return -EINVAL;
Ben Skeggsb2b09932010-11-24 10:47:15 +1000117 }
118
Ben Skeggsebb945a2012-07-20 08:17:34 +1000119 if (!ectx->vma.node) {
120 ret = nouveau_gpuobj_map_vm(nv_gpuobj(ectx), base->vm,
121 NV_MEM_ACCESS_RW, &ectx->vma);
122 if (ret)
123 return ret;
Ben Skeggs4c2d4222012-08-10 15:10:34 +1000124
125 nv_engctx(ectx)->addr = nv_gpuobj(base)->addr >> 12;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000126 }
Ben Skeggsb2b09932010-11-24 10:47:15 +1000127
Ben Skeggsebb945a2012-07-20 08:17:34 +1000128 nv_wo32(base, addr + 0x00, lower_32_bits(ectx->vma.offset) | 4);
129 nv_wo32(base, addr + 0x04, upper_32_bits(ectx->vma.offset));
130 bar->flush(bar);
131 return 0;
132}
Ben Skeggsb2b09932010-11-24 10:47:15 +1000133
Ben Skeggsebb945a2012-07-20 08:17:34 +1000134static int
135nvc0_fifo_context_detach(struct nouveau_object *parent, bool suspend,
136 struct nouveau_object *object)
137{
138 struct nouveau_bar *bar = nouveau_bar(parent);
139 struct nvc0_fifo_priv *priv = (void *)parent->engine;
140 struct nvc0_fifo_base *base = (void *)parent->parent;
141 struct nvc0_fifo_chan *chan = (void *)parent;
142 u32 addr;
143
144 switch (nv_engidx(object->engine)) {
145 case NVDEV_ENGINE_SW : return 0;
146 case NVDEV_ENGINE_GR : addr = 0x0210; break;
147 case NVDEV_ENGINE_COPY0: addr = 0x0230; break;
148 case NVDEV_ENGINE_COPY1: addr = 0x0240; break;
Maarten Lankhorst23c14ed2012-11-23 11:08:23 +1000149 case NVDEV_ENGINE_BSP : addr = 0x0270; break;
150 case NVDEV_ENGINE_VP : addr = 0x0250; break;
151 case NVDEV_ENGINE_PPP : addr = 0x0260; break;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000152 default:
153 return -EINVAL;
154 }
155
Ben Skeggsebb945a2012-07-20 08:17:34 +1000156 nv_wr32(priv, 0x002634, chan->base.chid);
157 if (!nv_wait(priv, 0x002634, 0xffffffff, chan->base.chid)) {
Marcin Slusarz93260d32012-12-09 23:00:34 +0100158 nv_error(priv, "channel %d [%s] kick timeout\n",
159 chan->base.chid, nouveau_client_name(chan));
Ben Skeggsebb945a2012-07-20 08:17:34 +1000160 if (suspend)
161 return -EBUSY;
162 }
163
Ben Skeggsedc260d2012-11-27 11:05:36 +1000164 nv_wo32(base, addr + 0x00, 0x00000000);
165 nv_wo32(base, addr + 0x04, 0x00000000);
166 bar->flush(bar);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000167 return 0;
168}
169
170static int
171nvc0_fifo_chan_ctor(struct nouveau_object *parent,
172 struct nouveau_object *engine,
173 struct nouveau_oclass *oclass, void *data, u32 size,
174 struct nouveau_object **pobject)
175{
176 struct nouveau_bar *bar = nouveau_bar(parent);
177 struct nvc0_fifo_priv *priv = (void *)engine;
178 struct nvc0_fifo_base *base = (void *)parent;
179 struct nvc0_fifo_chan *chan;
Ben Skeggsdbff2de2012-08-06 18:16:37 +1000180 struct nv50_channel_ind_class *args = data;
Ben Skeggsebb945a2012-07-20 08:17:34 +1000181 u64 usermem, ioffset, ilength;
182 int ret, i;
183
184 if (size < sizeof(*args))
185 return -EINVAL;
186
187 ret = nouveau_fifo_channel_create(parent, engine, oclass, 1,
188 priv->user.bar.offset, 0x1000,
189 args->pushbuf,
Martin Peres507ceb12012-11-27 00:30:32 +0100190 (1ULL << NVDEV_ENGINE_SW) |
191 (1ULL << NVDEV_ENGINE_GR) |
192 (1ULL << NVDEV_ENGINE_COPY0) |
193 (1ULL << NVDEV_ENGINE_COPY1) |
194 (1ULL << NVDEV_ENGINE_BSP) |
195 (1ULL << NVDEV_ENGINE_VP) |
196 (1ULL << NVDEV_ENGINE_PPP), &chan);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000197 *pobject = nv_object(chan);
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000198 if (ret)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000199 return ret;
200
201 nv_parent(chan)->context_attach = nvc0_fifo_context_attach;
202 nv_parent(chan)->context_detach = nvc0_fifo_context_detach;
203
204 usermem = chan->base.chid * 0x1000;
205 ioffset = args->ioffset;
Ilia Mirkin57be0462013-07-27 00:27:00 -0400206 ilength = order_base_2(args->ilength / 8);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000207
208 for (i = 0; i < 0x1000; i += 4)
209 nv_wo32(priv->user.mem, usermem + i, 0x00000000);
210
211 nv_wo32(base, 0x08, lower_32_bits(priv->user.mem->addr + usermem));
212 nv_wo32(base, 0x0c, upper_32_bits(priv->user.mem->addr + usermem));
213 nv_wo32(base, 0x10, 0x0000face);
214 nv_wo32(base, 0x30, 0xfffff902);
215 nv_wo32(base, 0x48, lower_32_bits(ioffset));
216 nv_wo32(base, 0x4c, upper_32_bits(ioffset) | (ilength << 16));
217 nv_wo32(base, 0x54, 0x00000002);
218 nv_wo32(base, 0x84, 0x20400000);
219 nv_wo32(base, 0x94, 0x30000001);
220 nv_wo32(base, 0x9c, 0x00000100);
221 nv_wo32(base, 0xa4, 0x1f1f1f1f);
222 nv_wo32(base, 0xa8, 0x1f1f1f1f);
223 nv_wo32(base, 0xac, 0x0000001f);
224 nv_wo32(base, 0xb8, 0xf8000000);
225 nv_wo32(base, 0xf8, 0x10003080); /* 0x002310 */
226 nv_wo32(base, 0xfc, 0x10000010); /* 0x002350 */
227 bar->flush(bar);
228 return 0;
229}
230
231static int
232nvc0_fifo_chan_init(struct nouveau_object *object)
233{
234 struct nouveau_gpuobj *base = nv_gpuobj(object->parent);
235 struct nvc0_fifo_priv *priv = (void *)object->engine;
236 struct nvc0_fifo_chan *chan = (void *)object;
237 u32 chid = chan->base.chid;
238 int ret;
239
240 ret = nouveau_fifo_channel_init(&chan->base);
241 if (ret)
242 return ret;
243
244 nv_wr32(priv, 0x003000 + (chid * 8), 0xc0000000 | base->addr >> 12);
245 nv_wr32(priv, 0x003004 + (chid * 8), 0x001f0001);
Ben Skeggs03574662014-01-28 11:47:46 +1000246 nvc0_fifo_runlist_update(priv);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000247 return 0;
248}
249
Ben Skeggse99bf012014-02-22 00:18:17 +1000250static void nvc0_fifo_intr_engine(struct nvc0_fifo_priv *priv);
251
Ben Skeggsebb945a2012-07-20 08:17:34 +1000252static int
253nvc0_fifo_chan_fini(struct nouveau_object *object, bool suspend)
254{
255 struct nvc0_fifo_priv *priv = (void *)object->engine;
256 struct nvc0_fifo_chan *chan = (void *)object;
257 u32 chid = chan->base.chid;
258
259 nv_mask(priv, 0x003004 + (chid * 8), 0x00000001, 0x00000000);
Ben Skeggs03574662014-01-28 11:47:46 +1000260 nvc0_fifo_runlist_update(priv);
Ben Skeggse99bf012014-02-22 00:18:17 +1000261
262 nvc0_fifo_intr_engine(priv);
263
Ben Skeggsebb945a2012-07-20 08:17:34 +1000264 nv_wr32(priv, 0x003000 + (chid * 8), 0x00000000);
265
266 return nouveau_fifo_channel_fini(&chan->base, suspend);
267}
268
269static struct nouveau_ofuncs
270nvc0_fifo_ofuncs = {
271 .ctor = nvc0_fifo_chan_ctor,
272 .dtor = _nouveau_fifo_channel_dtor,
273 .init = nvc0_fifo_chan_init,
274 .fini = nvc0_fifo_chan_fini,
275 .rd32 = _nouveau_fifo_channel_rd32,
276 .wr32 = _nouveau_fifo_channel_wr32,
277};
278
279static struct nouveau_oclass
280nvc0_fifo_sclass[] = {
Ben Skeggsc97f8c92012-08-19 16:03:00 +1000281 { NVC0_CHANNEL_IND_CLASS, &nvc0_fifo_ofuncs },
Ben Skeggsebb945a2012-07-20 08:17:34 +1000282 {}
283};
284
285/*******************************************************************************
286 * FIFO context - instmem heap and vm setup
287 ******************************************************************************/
288
289static int
290nvc0_fifo_context_ctor(struct nouveau_object *parent,
291 struct nouveau_object *engine,
292 struct nouveau_oclass *oclass, void *data, u32 size,
293 struct nouveau_object **pobject)
294{
295 struct nvc0_fifo_base *base;
296 int ret;
297
298 ret = nouveau_fifo_context_create(parent, engine, oclass, NULL, 0x1000,
299 0x1000, NVOBJ_FLAG_ZERO_ALLOC |
300 NVOBJ_FLAG_HEAP, &base);
301 *pobject = nv_object(base);
302 if (ret)
303 return ret;
304
Ben Skeggsf50c8052013-04-24 18:02:35 +1000305 ret = nouveau_gpuobj_new(nv_object(base), NULL, 0x10000, 0x1000, 0,
306 &base->pgd);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000307 if (ret)
308 return ret;
309
310 nv_wo32(base, 0x0200, lower_32_bits(base->pgd->addr));
311 nv_wo32(base, 0x0204, upper_32_bits(base->pgd->addr));
312 nv_wo32(base, 0x0208, 0xffffffff);
313 nv_wo32(base, 0x020c, 0x000000ff);
314
315 ret = nouveau_vm_ref(nouveau_client(parent)->vm, &base->vm, base->pgd);
316 if (ret)
317 return ret;
318
319 return 0;
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000320}
321
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000322static void
Ben Skeggsebb945a2012-07-20 08:17:34 +1000323nvc0_fifo_context_dtor(struct nouveau_object *object)
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000324{
Ben Skeggsebb945a2012-07-20 08:17:34 +1000325 struct nvc0_fifo_base *base = (void *)object;
326 nouveau_vm_ref(NULL, &base->vm, base->pgd);
327 nouveau_gpuobj_ref(NULL, &base->pgd);
328 nouveau_fifo_context_destroy(&base->base);
Ben Skeggsb2b09932010-11-24 10:47:15 +1000329}
330
Ben Skeggsebb945a2012-07-20 08:17:34 +1000331static struct nouveau_oclass
332nvc0_fifo_cclass = {
333 .handle = NV_ENGCTX(FIFO, 0xc0),
334 .ofuncs = &(struct nouveau_ofuncs) {
335 .ctor = nvc0_fifo_context_ctor,
336 .dtor = nvc0_fifo_context_dtor,
337 .init = _nouveau_fifo_context_init,
338 .fini = _nouveau_fifo_context_fini,
339 .rd32 = _nouveau_fifo_context_rd32,
340 .wr32 = _nouveau_fifo_context_wr32,
341 },
342};
Ben Skeggsb2b09932010-11-24 10:47:15 +1000343
Ben Skeggsebb945a2012-07-20 08:17:34 +1000344/*******************************************************************************
345 * PFIFO engine
346 ******************************************************************************/
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000347
Ben Skeggs083c2142014-02-22 00:31:29 +1000348static int
349nvc0_fifo_swmthd(struct nvc0_fifo_priv *priv, u32 chid, u32 mthd, u32 data)
350{
351 struct nvc0_fifo_chan *chan = NULL;
352 struct nouveau_handle *bind;
353 unsigned long flags;
354 int ret = -EINVAL;
355
356 spin_lock_irqsave(&priv->base.lock, flags);
357 if (likely(chid >= priv->base.min && chid <= priv->base.max))
358 chan = (void *)priv->base.channel[chid];
359 if (unlikely(!chan))
360 goto out;
361
362 bind = nouveau_namedb_get_class(nv_namedb(chan), 0x906e);
363 if (likely(bind)) {
364 if (!mthd || !nv_call(bind->object, mthd, data))
365 ret = 0;
366 nouveau_namedb_put(bind);
367 }
368
369out:
370 spin_unlock_irqrestore(&priv->base.lock, flags);
371 return ret;
372}
373
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000374static const struct nouveau_enum
Ben Skeggs40476532014-02-22 01:18:46 +1000375nvc0_fifo_sched_reason[] = {
376 { 0x0a, "CTXSW_TIMEOUT" },
377 {}
378};
379
380static void
381nvc0_fifo_intr_sched(struct nvc0_fifo_priv *priv)
382{
383 u32 intr = nv_rd32(priv, 0x00254c);
384 u32 code = intr & 0x000000ff;
385 const struct nouveau_enum *en;
386 char enunk[6] = "";
387
388 en = nouveau_enum_find(nvc0_fifo_sched_reason, code);
389 if (!en)
390 snprintf(enunk, sizeof(enunk), "UNK%02x", code);
391
392 nv_error(priv, "SCHED_ERROR [ %s ]\n", en ? en->name : enunk);
393}
394
395static const struct nouveau_enum
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000396nvc0_fifo_fault_engine[] = {
Marcin Slusarz93260d32012-12-09 23:00:34 +0100397 { 0x00, "PGRAPH", NULL, NVDEV_ENGINE_GR },
Ben Skeggs7a313472011-03-29 00:52:59 +1000398 { 0x03, "PEEPHOLE" },
399 { 0x04, "BAR1" },
400 { 0x05, "BAR3" },
Marcin Slusarz93260d32012-12-09 23:00:34 +0100401 { 0x07, "PFIFO", NULL, NVDEV_ENGINE_FIFO },
402 { 0x10, "PBSP", NULL, NVDEV_ENGINE_BSP },
403 { 0x11, "PPPP", NULL, NVDEV_ENGINE_PPP },
Ben Skeggs7a313472011-03-29 00:52:59 +1000404 { 0x13, "PCOUNTER" },
Marcin Slusarz93260d32012-12-09 23:00:34 +0100405 { 0x14, "PVP", NULL, NVDEV_ENGINE_VP },
406 { 0x15, "PCOPY0", NULL, NVDEV_ENGINE_COPY0 },
407 { 0x16, "PCOPY1", NULL, NVDEV_ENGINE_COPY1 },
Ben Skeggs7a313472011-03-29 00:52:59 +1000408 { 0x17, "PDAEMON" },
Ben Skeggsb2b09932010-11-24 10:47:15 +1000409 {}
410};
411
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000412static const struct nouveau_enum
413nvc0_fifo_fault_reason[] = {
Ben Skeggse2966632011-03-29 08:57:34 +1000414 { 0x00, "PT_NOT_PRESENT" },
415 { 0x01, "PT_TOO_SHORT" },
416 { 0x02, "PAGE_NOT_PRESENT" },
417 { 0x03, "VM_LIMIT_EXCEEDED" },
418 { 0x04, "NO_CHANNEL" },
419 { 0x05, "PAGE_SYSTEM_ONLY" },
420 { 0x06, "PAGE_READ_ONLY" },
421 { 0x0a, "COMPRESSED_SYSRAM" },
422 { 0x0c, "INVALID_STORAGE_TYPE" },
Ben Skeggsb2b09932010-11-24 10:47:15 +1000423 {}
424};
425
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000426static const struct nouveau_enum
427nvc0_fifo_fault_hubclient[] = {
Ben Skeggs7795bee2011-03-29 09:28:24 +1000428 { 0x01, "PCOPY0" },
429 { 0x02, "PCOPY1" },
430 { 0x04, "DISPATCH" },
431 { 0x05, "CTXCTL" },
432 { 0x06, "PFIFO" },
433 { 0x07, "BAR_READ" },
434 { 0x08, "BAR_WRITE" },
435 { 0x0b, "PVP" },
436 { 0x0c, "PPPP" },
437 { 0x0d, "PBSP" },
438 { 0x11, "PCOUNTER" },
439 { 0x12, "PDAEMON" },
440 { 0x14, "CCACHE" },
441 { 0x15, "CCACHE_POST" },
442 {}
443};
444
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000445static const struct nouveau_enum
446nvc0_fifo_fault_gpcclient[] = {
Ben Skeggs7795bee2011-03-29 09:28:24 +1000447 { 0x01, "TEX" },
448 { 0x0c, "ESETUP" },
449 { 0x0e, "CTXCTL" },
450 { 0x0f, "PROP" },
451 {}
452};
453
Ben Skeggsb2b09932010-11-24 10:47:15 +1000454static void
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000455nvc0_fifo_intr_fault(struct nvc0_fifo_priv *priv, int unit)
Ben Skeggsb2b09932010-11-24 10:47:15 +1000456{
Ben Skeggsb3ccd342012-09-06 20:26:38 -0400457 u32 inst = nv_rd32(priv, 0x002800 + (unit * 0x10));
458 u32 valo = nv_rd32(priv, 0x002804 + (unit * 0x10));
459 u32 vahi = nv_rd32(priv, 0x002808 + (unit * 0x10));
460 u32 stat = nv_rd32(priv, 0x00280c + (unit * 0x10));
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000461 u32 gpc = (stat & 0x1f000000) >> 24;
Ben Skeggs7795bee2011-03-29 09:28:24 +1000462 u32 client = (stat & 0x00001f00) >> 8;
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000463 u32 write = (stat & 0x00000080);
464 u32 hub = (stat & 0x00000040);
465 u32 reason = (stat & 0x0000000f);
Marcin Slusarz93260d32012-12-09 23:00:34 +0100466 struct nouveau_object *engctx = NULL;
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000467 struct nouveau_engine *engine;
468 const struct nouveau_enum *er, *eu, *ec;
469 char erunk[6] = "";
470 char euunk[6] = "";
471 char ecunk[6] = "";
472 char gpcid[3] = "";
Ben Skeggsb2b09932010-11-24 10:47:15 +1000473
Ben Skeggsb3ccd342012-09-06 20:26:38 -0400474 switch (unit) {
475 case 3: /* PEEPHOLE */
476 nv_mask(priv, 0x001718, 0x00000000, 0x00000000);
477 break;
478 case 4: /* BAR1 */
479 nv_mask(priv, 0x001704, 0x00000000, 0x00000000);
480 break;
481 case 5: /* BAR3 */
482 nv_mask(priv, 0x001714, 0x00000000, 0x00000000);
483 break;
484 default:
485 break;
486 }
487
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000488 er = nouveau_enum_find(nvc0_fifo_fault_reason, reason);
489 if (!er)
490 snprintf(erunk, sizeof(erunk), "UNK%02X", reason);
491
492 eu = nouveau_enum_find(nvc0_fifo_fault_engine, unit);
493 if (eu) {
494 if (eu->data2) {
495 engine = nouveau_engine(priv, eu->data2);
496 if (engine)
497 engctx = nouveau_engctx_get(engine, inst);
498 }
Ben Skeggs7795bee2011-03-29 09:28:24 +1000499 } else {
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000500 snprintf(euunk, sizeof(euunk), "UNK%02x", unit);
Ben Skeggs7795bee2011-03-29 09:28:24 +1000501 }
Marcin Slusarz93260d32012-12-09 23:00:34 +0100502
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000503 if (hub) {
504 ec = nouveau_enum_find(nvc0_fifo_fault_hubclient, client);
505 } else {
506 ec = nouveau_enum_find(nvc0_fifo_fault_gpcclient, client);
507 snprintf(gpcid, sizeof(gpcid), "%d", gpc);
Marcin Slusarz93260d32012-12-09 23:00:34 +0100508 }
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000509
510 if (!ec)
511 snprintf(ecunk, sizeof(ecunk), "UNK%02x", client);
512
513 nv_error(priv, "%s fault at 0x%010llx [%s] from %s/%s%s%s%s on "
514 "channel 0x%010llx [%s]\n", write ? "write" : "read",
515 (u64)vahi << 32 | valo, er ? er->name : erunk,
516 eu ? eu->name : euunk, hub ? "" : "GPC", gpcid, hub ? "" : "/",
517 ec ? ec->name : ecunk, (u64)inst << 12,
518 nouveau_client_name(engctx));
Marcin Slusarz93260d32012-12-09 23:00:34 +0100519
520 nouveau_engctx_put(engctx);
Ben Skeggsb2b09932010-11-24 10:47:15 +1000521}
522
Ben Skeggs083c2142014-02-22 00:31:29 +1000523static const struct nouveau_bitfield
524nvc0_fifo_pbdma_intr[] = {
525/* { 0x00008000, "" } seen with null ib push */
526 { 0x00200000, "ILLEGAL_MTHD" },
527 { 0x00800000, "EMPTY_SUBC" },
528 {}
529};
Ben Skeggsd5316e22012-03-21 13:53:49 +1000530
Ben Skeggsb2b09932010-11-24 10:47:15 +1000531static void
Ben Skeggs083c2142014-02-22 00:31:29 +1000532nvc0_fifo_intr_pbdma(struct nvc0_fifo_priv *priv, int unit)
Ben Skeggsb2b09932010-11-24 10:47:15 +1000533{
Ben Skeggsebb945a2012-07-20 08:17:34 +1000534 u32 stat = nv_rd32(priv, 0x040108 + (unit * 0x2000));
535 u32 addr = nv_rd32(priv, 0x0400c0 + (unit * 0x2000));
536 u32 data = nv_rd32(priv, 0x0400c4 + (unit * 0x2000));
537 u32 chid = nv_rd32(priv, 0x040120 + (unit * 0x2000)) & 0x7f;
538 u32 subc = (addr & 0x00070000) >> 16;
Ben Skeggsb2b09932010-11-24 10:47:15 +1000539 u32 mthd = (addr & 0x00003ffc);
Ben Skeggsd5316e22012-03-21 13:53:49 +1000540 u32 show = stat;
Ben Skeggsb2b09932010-11-24 10:47:15 +1000541
Ben Skeggsebb945a2012-07-20 08:17:34 +1000542 if (stat & 0x00800000) {
543 if (!nvc0_fifo_swmthd(priv, chid, mthd, data))
544 show &= ~0x00800000;
Ben Skeggsd5316e22012-03-21 13:53:49 +1000545 }
Ben Skeggsb2b09932010-11-24 10:47:15 +1000546
Ben Skeggsebb945a2012-07-20 08:17:34 +1000547 if (show) {
Ben Skeggs03574662014-01-28 11:47:46 +1000548 nv_error(priv, "PBDMA%d:", unit);
549 nouveau_bitfield_print(nvc0_fifo_pbdma_intr, show);
Marcin Slusarzf533da12012-12-09 15:45:20 +0100550 pr_cont("\n");
Marcin Slusarz93260d32012-12-09 23:00:34 +0100551 nv_error(priv,
Ben Skeggs03574662014-01-28 11:47:46 +1000552 "PBDMA%d: ch %d [%s] subc %d mthd 0x%04x data 0x%08x\n",
Marcin Slusarz93260d32012-12-09 23:00:34 +0100553 unit, chid,
554 nouveau_client_name_for_fifo_chid(&priv->base, chid),
555 subc, mthd, data);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000556 }
557
558 nv_wr32(priv, 0x0400c0 + (unit * 0x2000), 0x80600008);
559 nv_wr32(priv, 0x040108 + (unit * 0x2000), stat);
Ben Skeggsb2b09932010-11-24 10:47:15 +1000560}
561
562static void
Ben Skeggsa07d0e72014-02-22 00:28:47 +1000563nvc0_fifo_intr_runlist(struct nvc0_fifo_priv *priv)
564{
565 u32 intr = nv_rd32(priv, 0x002a00);
566
567 if (intr & 0x10000000) {
568 wake_up(&priv->runlist.wait);
569 nv_wr32(priv, 0x002a00, 0x10000000);
570 intr &= ~0x10000000;
571 }
572
573 if (intr) {
574 nv_error(priv, "RUNLIST 0x%08x\n", intr);
575 nv_wr32(priv, 0x002a00, intr);
576 }
577}
578
579static void
Ben Skeggse99bf012014-02-22 00:18:17 +1000580nvc0_fifo_intr_engine_unit(struct nvc0_fifo_priv *priv, int engn)
581{
582 u32 intr = nv_rd32(priv, 0x0025a8 + (engn * 0x04));
583 u32 inte = nv_rd32(priv, 0x002628);
584 u32 unkn;
585
586 for (unkn = 0; unkn < 8; unkn++) {
587 u32 ints = (intr >> (unkn * 0x04)) & inte;
588 if (ints & 0x1) {
589 nouveau_event_trigger(priv->base.uevent, 0);
590 ints &= ~1;
591 }
592 if (ints) {
593 nv_error(priv, "ENGINE %d %d %01x", engn, unkn, ints);
594 nv_mask(priv, 0x002628, ints, 0);
595 }
596 }
597
598 nv_wr32(priv, 0x0025a8 + (engn * 0x04), intr);
599}
600
601static void
602nvc0_fifo_intr_engine(struct nvc0_fifo_priv *priv)
603{
604 u32 mask = nv_rd32(priv, 0x0025a4);
605 while (mask) {
606 u32 unit = __ffs(mask);
607 nvc0_fifo_intr_engine_unit(priv, unit);
608 mask &= ~(1 << unit);
609 }
610}
611
612static void
Ben Skeggsebb945a2012-07-20 08:17:34 +1000613nvc0_fifo_intr(struct nouveau_subdev *subdev)
Ben Skeggsb2b09932010-11-24 10:47:15 +1000614{
Ben Skeggsebb945a2012-07-20 08:17:34 +1000615 struct nvc0_fifo_priv *priv = (void *)subdev;
616 u32 mask = nv_rd32(priv, 0x002140);
617 u32 stat = nv_rd32(priv, 0x002100) & mask;
Ben Skeggsb2b09932010-11-24 10:47:15 +1000618
Ben Skeggs32256c82013-01-31 19:49:33 -0500619 if (stat & 0x00000001) {
620 u32 intr = nv_rd32(priv, 0x00252c);
621 nv_warn(priv, "INTR 0x00000001: 0x%08x\n", intr);
622 nv_wr32(priv, 0x002100, 0x00000001);
623 stat &= ~0x00000001;
624 }
625
Ben Skeggscc8cd642011-01-28 13:42:16 +1000626 if (stat & 0x00000100) {
Ben Skeggs40476532014-02-22 01:18:46 +1000627 nvc0_fifo_intr_sched(priv);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000628 nv_wr32(priv, 0x002100, 0x00000100);
Ben Skeggscc8cd642011-01-28 13:42:16 +1000629 stat &= ~0x00000100;
630 }
631
Ben Skeggs32256c82013-01-31 19:49:33 -0500632 if (stat & 0x00010000) {
633 u32 intr = nv_rd32(priv, 0x00256c);
634 nv_warn(priv, "INTR 0x00010000: 0x%08x\n", intr);
635 nv_wr32(priv, 0x002100, 0x00010000);
636 stat &= ~0x00010000;
637 }
638
639 if (stat & 0x01000000) {
640 u32 intr = nv_rd32(priv, 0x00258c);
641 nv_warn(priv, "INTR 0x01000000: 0x%08x\n", intr);
642 nv_wr32(priv, 0x002100, 0x01000000);
643 stat &= ~0x01000000;
644 }
645
Ben Skeggsb2b09932010-11-24 10:47:15 +1000646 if (stat & 0x10000000) {
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000647 u32 mask = nv_rd32(priv, 0x00259c);
648 while (mask) {
649 u32 unit = __ffs(mask);
650 nvc0_fifo_intr_fault(priv, unit);
651 nv_wr32(priv, 0x00259c, (1 << unit));
652 mask &= ~(1 << unit);
Ben Skeggsb2b09932010-11-24 10:47:15 +1000653 }
Ben Skeggsb2b09932010-11-24 10:47:15 +1000654 stat &= ~0x10000000;
655 }
656
657 if (stat & 0x20000000) {
Ben Skeggs083c2142014-02-22 00:31:29 +1000658 u32 mask = nv_rd32(priv, 0x0025a0);
659 while (mask) {
660 u32 unit = __ffs(mask);
661 nvc0_fifo_intr_pbdma(priv, unit);
662 nv_wr32(priv, 0x0025a0, (1 << unit));
663 mask &= ~(1 << unit);
Ben Skeggsb2b09932010-11-24 10:47:15 +1000664 }
Ben Skeggsb2b09932010-11-24 10:47:15 +1000665 stat &= ~0x20000000;
666 }
667
Ben Skeggscc8cd642011-01-28 13:42:16 +1000668 if (stat & 0x40000000) {
Ben Skeggsa07d0e72014-02-22 00:28:47 +1000669 nvc0_fifo_intr_runlist(priv);
Ben Skeggscc8cd642011-01-28 13:42:16 +1000670 stat &= ~0x40000000;
671 }
672
Ben Skeggs32256c82013-01-31 19:49:33 -0500673 if (stat & 0x80000000) {
Ben Skeggse99bf012014-02-22 00:18:17 +1000674 nvc0_fifo_intr_engine(priv);
Ben Skeggs32256c82013-01-31 19:49:33 -0500675 stat &= ~0x80000000;
676 }
677
Ben Skeggsb2b09932010-11-24 10:47:15 +1000678 if (stat) {
Ben Skeggs22a7a272014-02-22 00:19:19 +1000679 nv_error(priv, "INTR 0x%08x\n", stat);
680 nv_mask(priv, 0x002140, stat, 0x00000000);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000681 nv_wr32(priv, 0x002100, stat);
Ben Skeggsb2b09932010-11-24 10:47:15 +1000682 }
Ben Skeggsb2b09932010-11-24 10:47:15 +1000683}
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000684
Ben Skeggs9bd2ddb2013-01-31 13:51:20 +1000685static void
686nvc0_fifo_uevent_enable(struct nouveau_event *event, int index)
687{
688 struct nvc0_fifo_priv *priv = event->priv;
689 nv_mask(priv, 0x002140, 0x80000000, 0x80000000);
690}
691
692static void
693nvc0_fifo_uevent_disable(struct nouveau_event *event, int index)
694{
695 struct nvc0_fifo_priv *priv = event->priv;
696 nv_mask(priv, 0x002140, 0x80000000, 0x00000000);
697}
698
Ben Skeggsebb945a2012-07-20 08:17:34 +1000699static int
700nvc0_fifo_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
701 struct nouveau_oclass *oclass, void *data, u32 size,
702 struct nouveau_object **pobject)
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000703{
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000704 struct nvc0_fifo_priv *priv;
705 int ret;
706
Ben Skeggsebb945a2012-07-20 08:17:34 +1000707 ret = nouveau_fifo_create(parent, engine, oclass, 0, 127, &priv);
708 *pobject = nv_object(priv);
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000709 if (ret)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000710 return ret;
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000711
Ben Skeggsf50c8052013-04-24 18:02:35 +1000712 ret = nouveau_gpuobj_new(nv_object(priv), NULL, 0x1000, 0x1000, 0,
Ben Skeggsa07d0e72014-02-22 00:28:47 +1000713 &priv->runlist.mem[0]);
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000714 if (ret)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000715 return ret;
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000716
Ben Skeggsf50c8052013-04-24 18:02:35 +1000717 ret = nouveau_gpuobj_new(nv_object(priv), NULL, 0x1000, 0x1000, 0,
Ben Skeggsa07d0e72014-02-22 00:28:47 +1000718 &priv->runlist.mem[1]);
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000719 if (ret)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000720 return ret;
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000721
Ben Skeggsa07d0e72014-02-22 00:28:47 +1000722 init_waitqueue_head(&priv->runlist.wait);
723
Ben Skeggsf50c8052013-04-24 18:02:35 +1000724 ret = nouveau_gpuobj_new(nv_object(priv), NULL, 128 * 0x1000, 0x1000, 0,
Ben Skeggsebb945a2012-07-20 08:17:34 +1000725 &priv->user.mem);
Ben Skeggs9da226f2012-07-13 16:54:45 +1000726 if (ret)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000727 return ret;
Ben Skeggs9da226f2012-07-13 16:54:45 +1000728
Ben Skeggsebb945a2012-07-20 08:17:34 +1000729 ret = nouveau_gpuobj_map(priv->user.mem, NV_MEM_ACCESS_RW,
730 &priv->user.bar);
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000731 if (ret)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000732 return ret;
733
Ben Skeggs9bd2ddb2013-01-31 13:51:20 +1000734 priv->base.uevent->enable = nvc0_fifo_uevent_enable;
735 priv->base.uevent->disable = nvc0_fifo_uevent_disable;
736 priv->base.uevent->priv = priv;
737
Ben Skeggsebb945a2012-07-20 08:17:34 +1000738 nv_subdev(priv)->unit = 0x00000100;
739 nv_subdev(priv)->intr = nvc0_fifo_intr;
740 nv_engine(priv)->cclass = &nvc0_fifo_cclass;
741 nv_engine(priv)->sclass = nvc0_fifo_sclass;
742 return 0;
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000743}
Ben Skeggsebb945a2012-07-20 08:17:34 +1000744
745static void
746nvc0_fifo_dtor(struct nouveau_object *object)
747{
748 struct nvc0_fifo_priv *priv = (void *)object;
749
750 nouveau_gpuobj_unmap(&priv->user.bar);
751 nouveau_gpuobj_ref(NULL, &priv->user.mem);
Ben Skeggsa07d0e72014-02-22 00:28:47 +1000752 nouveau_gpuobj_ref(NULL, &priv->runlist.mem[0]);
753 nouveau_gpuobj_ref(NULL, &priv->runlist.mem[1]);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000754
755 nouveau_fifo_destroy(&priv->base);
756}
757
758static int
759nvc0_fifo_init(struct nouveau_object *object)
760{
761 struct nvc0_fifo_priv *priv = (void *)object;
762 int ret, i;
763
764 ret = nouveau_fifo_init(&priv->base);
765 if (ret)
766 return ret;
767
768 nv_wr32(priv, 0x000204, 0xffffffff);
769 nv_wr32(priv, 0x002204, 0xffffffff);
770
771 priv->spoon_nr = hweight32(nv_rd32(priv, 0x002204));
Ben Skeggs03574662014-01-28 11:47:46 +1000772 nv_debug(priv, "%d PBDMA unit(s)\n", priv->spoon_nr);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000773
Ben Skeggs03574662014-01-28 11:47:46 +1000774 /* assign engines to PBDMAs */
Ben Skeggsebb945a2012-07-20 08:17:34 +1000775 if (priv->spoon_nr >= 3) {
776 nv_wr32(priv, 0x002208, ~(1 << 0)); /* PGRAPH */
777 nv_wr32(priv, 0x00220c, ~(1 << 1)); /* PVP */
778 nv_wr32(priv, 0x002210, ~(1 << 1)); /* PPP */
779 nv_wr32(priv, 0x002214, ~(1 << 1)); /* PBSP */
780 nv_wr32(priv, 0x002218, ~(1 << 2)); /* PCE0 */
781 nv_wr32(priv, 0x00221c, ~(1 << 1)); /* PCE1 */
782 }
783
Ben Skeggs03574662014-01-28 11:47:46 +1000784 /* PBDMA[n] */
Ben Skeggsebb945a2012-07-20 08:17:34 +1000785 for (i = 0; i < priv->spoon_nr; i++) {
786 nv_mask(priv, 0x04013c + (i * 0x2000), 0x10000100, 0x00000000);
787 nv_wr32(priv, 0x040108 + (i * 0x2000), 0xffffffff); /* INTR */
788 nv_wr32(priv, 0x04010c + (i * 0x2000), 0xfffffeff); /* INTREN */
789 }
790
791 nv_mask(priv, 0x002200, 0x00000001, 0x00000001);
792 nv_wr32(priv, 0x002254, 0x10000000 | priv->user.bar.offset >> 12);
793
Ben Skeggsebb945a2012-07-20 08:17:34 +1000794 nv_wr32(priv, 0x002100, 0xffffffff);
Ben Skeggsa07d0e72014-02-22 00:28:47 +1000795 nv_wr32(priv, 0x002140, 0x7fffffff);
Ben Skeggse99bf012014-02-22 00:18:17 +1000796 nv_wr32(priv, 0x002628, 0x00000001); /* ENGINE_INTR_EN */
Ben Skeggsebb945a2012-07-20 08:17:34 +1000797 return 0;
798}
799
Ben Skeggs16c4f222013-11-05 14:26:58 +1000800struct nouveau_oclass *
801nvc0_fifo_oclass = &(struct nouveau_oclass) {
Ben Skeggsebb945a2012-07-20 08:17:34 +1000802 .handle = NV_ENGINE(FIFO, 0xc0),
803 .ofuncs = &(struct nouveau_ofuncs) {
804 .ctor = nvc0_fifo_ctor,
805 .dtor = nvc0_fifo_dtor,
806 .init = nvc0_fifo_init,
807 .fini = _nouveau_fifo_fini,
808 },
809};