blob: 3150536b8f75881d1fd235575d0b970086486566 [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
375nvc0_fifo_fault_engine[] = {
Marcin Slusarz93260d32012-12-09 23:00:34 +0100376 { 0x00, "PGRAPH", NULL, NVDEV_ENGINE_GR },
Ben Skeggs7a313472011-03-29 00:52:59 +1000377 { 0x03, "PEEPHOLE" },
378 { 0x04, "BAR1" },
379 { 0x05, "BAR3" },
Marcin Slusarz93260d32012-12-09 23:00:34 +0100380 { 0x07, "PFIFO", NULL, NVDEV_ENGINE_FIFO },
381 { 0x10, "PBSP", NULL, NVDEV_ENGINE_BSP },
382 { 0x11, "PPPP", NULL, NVDEV_ENGINE_PPP },
Ben Skeggs7a313472011-03-29 00:52:59 +1000383 { 0x13, "PCOUNTER" },
Marcin Slusarz93260d32012-12-09 23:00:34 +0100384 { 0x14, "PVP", NULL, NVDEV_ENGINE_VP },
385 { 0x15, "PCOPY0", NULL, NVDEV_ENGINE_COPY0 },
386 { 0x16, "PCOPY1", NULL, NVDEV_ENGINE_COPY1 },
Ben Skeggs7a313472011-03-29 00:52:59 +1000387 { 0x17, "PDAEMON" },
Ben Skeggsb2b09932010-11-24 10:47:15 +1000388 {}
389};
390
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000391static const struct nouveau_enum
392nvc0_fifo_fault_reason[] = {
Ben Skeggse2966632011-03-29 08:57:34 +1000393 { 0x00, "PT_NOT_PRESENT" },
394 { 0x01, "PT_TOO_SHORT" },
395 { 0x02, "PAGE_NOT_PRESENT" },
396 { 0x03, "VM_LIMIT_EXCEEDED" },
397 { 0x04, "NO_CHANNEL" },
398 { 0x05, "PAGE_SYSTEM_ONLY" },
399 { 0x06, "PAGE_READ_ONLY" },
400 { 0x0a, "COMPRESSED_SYSRAM" },
401 { 0x0c, "INVALID_STORAGE_TYPE" },
Ben Skeggsb2b09932010-11-24 10:47:15 +1000402 {}
403};
404
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000405static const struct nouveau_enum
406nvc0_fifo_fault_hubclient[] = {
Ben Skeggs7795bee2011-03-29 09:28:24 +1000407 { 0x01, "PCOPY0" },
408 { 0x02, "PCOPY1" },
409 { 0x04, "DISPATCH" },
410 { 0x05, "CTXCTL" },
411 { 0x06, "PFIFO" },
412 { 0x07, "BAR_READ" },
413 { 0x08, "BAR_WRITE" },
414 { 0x0b, "PVP" },
415 { 0x0c, "PPPP" },
416 { 0x0d, "PBSP" },
417 { 0x11, "PCOUNTER" },
418 { 0x12, "PDAEMON" },
419 { 0x14, "CCACHE" },
420 { 0x15, "CCACHE_POST" },
421 {}
422};
423
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000424static const struct nouveau_enum
425nvc0_fifo_fault_gpcclient[] = {
Ben Skeggs7795bee2011-03-29 09:28:24 +1000426 { 0x01, "TEX" },
427 { 0x0c, "ESETUP" },
428 { 0x0e, "CTXCTL" },
429 { 0x0f, "PROP" },
430 {}
431};
432
Ben Skeggsb2b09932010-11-24 10:47:15 +1000433static void
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000434nvc0_fifo_intr_fault(struct nvc0_fifo_priv *priv, int unit)
Ben Skeggsb2b09932010-11-24 10:47:15 +1000435{
Ben Skeggsb3ccd342012-09-06 20:26:38 -0400436 u32 inst = nv_rd32(priv, 0x002800 + (unit * 0x10));
437 u32 valo = nv_rd32(priv, 0x002804 + (unit * 0x10));
438 u32 vahi = nv_rd32(priv, 0x002808 + (unit * 0x10));
439 u32 stat = nv_rd32(priv, 0x00280c + (unit * 0x10));
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000440 u32 gpc = (stat & 0x1f000000) >> 24;
Ben Skeggs7795bee2011-03-29 09:28:24 +1000441 u32 client = (stat & 0x00001f00) >> 8;
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000442 u32 write = (stat & 0x00000080);
443 u32 hub = (stat & 0x00000040);
444 u32 reason = (stat & 0x0000000f);
Marcin Slusarz93260d32012-12-09 23:00:34 +0100445 struct nouveau_object *engctx = NULL;
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000446 struct nouveau_engine *engine;
447 const struct nouveau_enum *er, *eu, *ec;
448 char erunk[6] = "";
449 char euunk[6] = "";
450 char ecunk[6] = "";
451 char gpcid[3] = "";
Ben Skeggsb2b09932010-11-24 10:47:15 +1000452
Ben Skeggsb3ccd342012-09-06 20:26:38 -0400453 switch (unit) {
454 case 3: /* PEEPHOLE */
455 nv_mask(priv, 0x001718, 0x00000000, 0x00000000);
456 break;
457 case 4: /* BAR1 */
458 nv_mask(priv, 0x001704, 0x00000000, 0x00000000);
459 break;
460 case 5: /* BAR3 */
461 nv_mask(priv, 0x001714, 0x00000000, 0x00000000);
462 break;
463 default:
464 break;
465 }
466
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000467 er = nouveau_enum_find(nvc0_fifo_fault_reason, reason);
468 if (!er)
469 snprintf(erunk, sizeof(erunk), "UNK%02X", reason);
470
471 eu = nouveau_enum_find(nvc0_fifo_fault_engine, unit);
472 if (eu) {
473 if (eu->data2) {
474 engine = nouveau_engine(priv, eu->data2);
475 if (engine)
476 engctx = nouveau_engctx_get(engine, inst);
477 }
Ben Skeggs7795bee2011-03-29 09:28:24 +1000478 } else {
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000479 snprintf(euunk, sizeof(euunk), "UNK%02x", unit);
Ben Skeggs7795bee2011-03-29 09:28:24 +1000480 }
Marcin Slusarz93260d32012-12-09 23:00:34 +0100481
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000482 if (hub) {
483 ec = nouveau_enum_find(nvc0_fifo_fault_hubclient, client);
484 } else {
485 ec = nouveau_enum_find(nvc0_fifo_fault_gpcclient, client);
486 snprintf(gpcid, sizeof(gpcid), "%d", gpc);
Marcin Slusarz93260d32012-12-09 23:00:34 +0100487 }
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000488
489 if (!ec)
490 snprintf(ecunk, sizeof(ecunk), "UNK%02x", client);
491
492 nv_error(priv, "%s fault at 0x%010llx [%s] from %s/%s%s%s%s on "
493 "channel 0x%010llx [%s]\n", write ? "write" : "read",
494 (u64)vahi << 32 | valo, er ? er->name : erunk,
495 eu ? eu->name : euunk, hub ? "" : "GPC", gpcid, hub ? "" : "/",
496 ec ? ec->name : ecunk, (u64)inst << 12,
497 nouveau_client_name(engctx));
Marcin Slusarz93260d32012-12-09 23:00:34 +0100498
499 nouveau_engctx_put(engctx);
Ben Skeggsb2b09932010-11-24 10:47:15 +1000500}
501
Ben Skeggs083c2142014-02-22 00:31:29 +1000502static const struct nouveau_bitfield
503nvc0_fifo_pbdma_intr[] = {
504/* { 0x00008000, "" } seen with null ib push */
505 { 0x00200000, "ILLEGAL_MTHD" },
506 { 0x00800000, "EMPTY_SUBC" },
507 {}
508};
Ben Skeggsd5316e22012-03-21 13:53:49 +1000509
Ben Skeggsb2b09932010-11-24 10:47:15 +1000510static void
Ben Skeggs083c2142014-02-22 00:31:29 +1000511nvc0_fifo_intr_pbdma(struct nvc0_fifo_priv *priv, int unit)
Ben Skeggsb2b09932010-11-24 10:47:15 +1000512{
Ben Skeggsebb945a2012-07-20 08:17:34 +1000513 u32 stat = nv_rd32(priv, 0x040108 + (unit * 0x2000));
514 u32 addr = nv_rd32(priv, 0x0400c0 + (unit * 0x2000));
515 u32 data = nv_rd32(priv, 0x0400c4 + (unit * 0x2000));
516 u32 chid = nv_rd32(priv, 0x040120 + (unit * 0x2000)) & 0x7f;
517 u32 subc = (addr & 0x00070000) >> 16;
Ben Skeggsb2b09932010-11-24 10:47:15 +1000518 u32 mthd = (addr & 0x00003ffc);
Ben Skeggsd5316e22012-03-21 13:53:49 +1000519 u32 show = stat;
Ben Skeggsb2b09932010-11-24 10:47:15 +1000520
Ben Skeggsebb945a2012-07-20 08:17:34 +1000521 if (stat & 0x00800000) {
522 if (!nvc0_fifo_swmthd(priv, chid, mthd, data))
523 show &= ~0x00800000;
Ben Skeggsd5316e22012-03-21 13:53:49 +1000524 }
Ben Skeggsb2b09932010-11-24 10:47:15 +1000525
Ben Skeggsebb945a2012-07-20 08:17:34 +1000526 if (show) {
Ben Skeggs03574662014-01-28 11:47:46 +1000527 nv_error(priv, "PBDMA%d:", unit);
528 nouveau_bitfield_print(nvc0_fifo_pbdma_intr, show);
Marcin Slusarzf533da12012-12-09 15:45:20 +0100529 pr_cont("\n");
Marcin Slusarz93260d32012-12-09 23:00:34 +0100530 nv_error(priv,
Ben Skeggs03574662014-01-28 11:47:46 +1000531 "PBDMA%d: ch %d [%s] subc %d mthd 0x%04x data 0x%08x\n",
Marcin Slusarz93260d32012-12-09 23:00:34 +0100532 unit, chid,
533 nouveau_client_name_for_fifo_chid(&priv->base, chid),
534 subc, mthd, data);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000535 }
536
537 nv_wr32(priv, 0x0400c0 + (unit * 0x2000), 0x80600008);
538 nv_wr32(priv, 0x040108 + (unit * 0x2000), stat);
Ben Skeggsb2b09932010-11-24 10:47:15 +1000539}
540
541static void
Ben Skeggsa07d0e72014-02-22 00:28:47 +1000542nvc0_fifo_intr_runlist(struct nvc0_fifo_priv *priv)
543{
544 u32 intr = nv_rd32(priv, 0x002a00);
545
546 if (intr & 0x10000000) {
547 wake_up(&priv->runlist.wait);
548 nv_wr32(priv, 0x002a00, 0x10000000);
549 intr &= ~0x10000000;
550 }
551
552 if (intr) {
553 nv_error(priv, "RUNLIST 0x%08x\n", intr);
554 nv_wr32(priv, 0x002a00, intr);
555 }
556}
557
558static void
Ben Skeggse99bf012014-02-22 00:18:17 +1000559nvc0_fifo_intr_engine_unit(struct nvc0_fifo_priv *priv, int engn)
560{
561 u32 intr = nv_rd32(priv, 0x0025a8 + (engn * 0x04));
562 u32 inte = nv_rd32(priv, 0x002628);
563 u32 unkn;
564
565 for (unkn = 0; unkn < 8; unkn++) {
566 u32 ints = (intr >> (unkn * 0x04)) & inte;
567 if (ints & 0x1) {
568 nouveau_event_trigger(priv->base.uevent, 0);
569 ints &= ~1;
570 }
571 if (ints) {
572 nv_error(priv, "ENGINE %d %d %01x", engn, unkn, ints);
573 nv_mask(priv, 0x002628, ints, 0);
574 }
575 }
576
577 nv_wr32(priv, 0x0025a8 + (engn * 0x04), intr);
578}
579
580static void
581nvc0_fifo_intr_engine(struct nvc0_fifo_priv *priv)
582{
583 u32 mask = nv_rd32(priv, 0x0025a4);
584 while (mask) {
585 u32 unit = __ffs(mask);
586 nvc0_fifo_intr_engine_unit(priv, unit);
587 mask &= ~(1 << unit);
588 }
589}
590
591static void
Ben Skeggsebb945a2012-07-20 08:17:34 +1000592nvc0_fifo_intr(struct nouveau_subdev *subdev)
Ben Skeggsb2b09932010-11-24 10:47:15 +1000593{
Ben Skeggsebb945a2012-07-20 08:17:34 +1000594 struct nvc0_fifo_priv *priv = (void *)subdev;
595 u32 mask = nv_rd32(priv, 0x002140);
596 u32 stat = nv_rd32(priv, 0x002100) & mask;
Ben Skeggsb2b09932010-11-24 10:47:15 +1000597
Ben Skeggs32256c82013-01-31 19:49:33 -0500598 if (stat & 0x00000001) {
599 u32 intr = nv_rd32(priv, 0x00252c);
600 nv_warn(priv, "INTR 0x00000001: 0x%08x\n", intr);
601 nv_wr32(priv, 0x002100, 0x00000001);
602 stat &= ~0x00000001;
603 }
604
Ben Skeggscc8cd642011-01-28 13:42:16 +1000605 if (stat & 0x00000100) {
Ben Skeggs32256c82013-01-31 19:49:33 -0500606 u32 intr = nv_rd32(priv, 0x00254c);
607 nv_warn(priv, "INTR 0x00000100: 0x%08x\n", intr);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000608 nv_wr32(priv, 0x002100, 0x00000100);
Ben Skeggscc8cd642011-01-28 13:42:16 +1000609 stat &= ~0x00000100;
610 }
611
Ben Skeggs32256c82013-01-31 19:49:33 -0500612 if (stat & 0x00010000) {
613 u32 intr = nv_rd32(priv, 0x00256c);
614 nv_warn(priv, "INTR 0x00010000: 0x%08x\n", intr);
615 nv_wr32(priv, 0x002100, 0x00010000);
616 stat &= ~0x00010000;
617 }
618
619 if (stat & 0x01000000) {
620 u32 intr = nv_rd32(priv, 0x00258c);
621 nv_warn(priv, "INTR 0x01000000: 0x%08x\n", intr);
622 nv_wr32(priv, 0x002100, 0x01000000);
623 stat &= ~0x01000000;
624 }
625
Ben Skeggsb2b09932010-11-24 10:47:15 +1000626 if (stat & 0x10000000) {
Ben Skeggsd439a5a2014-02-22 00:39:36 +1000627 u32 mask = nv_rd32(priv, 0x00259c);
628 while (mask) {
629 u32 unit = __ffs(mask);
630 nvc0_fifo_intr_fault(priv, unit);
631 nv_wr32(priv, 0x00259c, (1 << unit));
632 mask &= ~(1 << unit);
Ben Skeggsb2b09932010-11-24 10:47:15 +1000633 }
Ben Skeggsb2b09932010-11-24 10:47:15 +1000634 stat &= ~0x10000000;
635 }
636
637 if (stat & 0x20000000) {
Ben Skeggs083c2142014-02-22 00:31:29 +1000638 u32 mask = nv_rd32(priv, 0x0025a0);
639 while (mask) {
640 u32 unit = __ffs(mask);
641 nvc0_fifo_intr_pbdma(priv, unit);
642 nv_wr32(priv, 0x0025a0, (1 << unit));
643 mask &= ~(1 << unit);
Ben Skeggsb2b09932010-11-24 10:47:15 +1000644 }
Ben Skeggsb2b09932010-11-24 10:47:15 +1000645 stat &= ~0x20000000;
646 }
647
Ben Skeggscc8cd642011-01-28 13:42:16 +1000648 if (stat & 0x40000000) {
Ben Skeggsa07d0e72014-02-22 00:28:47 +1000649 nvc0_fifo_intr_runlist(priv);
Ben Skeggscc8cd642011-01-28 13:42:16 +1000650 stat &= ~0x40000000;
651 }
652
Ben Skeggs32256c82013-01-31 19:49:33 -0500653 if (stat & 0x80000000) {
Ben Skeggse99bf012014-02-22 00:18:17 +1000654 nvc0_fifo_intr_engine(priv);
Ben Skeggs32256c82013-01-31 19:49:33 -0500655 stat &= ~0x80000000;
656 }
657
Ben Skeggsb2b09932010-11-24 10:47:15 +1000658 if (stat) {
Ben Skeggs22a7a272014-02-22 00:19:19 +1000659 nv_error(priv, "INTR 0x%08x\n", stat);
660 nv_mask(priv, 0x002140, stat, 0x00000000);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000661 nv_wr32(priv, 0x002100, stat);
Ben Skeggsb2b09932010-11-24 10:47:15 +1000662 }
Ben Skeggsb2b09932010-11-24 10:47:15 +1000663}
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000664
Ben Skeggs9bd2ddb2013-01-31 13:51:20 +1000665static void
666nvc0_fifo_uevent_enable(struct nouveau_event *event, int index)
667{
668 struct nvc0_fifo_priv *priv = event->priv;
669 nv_mask(priv, 0x002140, 0x80000000, 0x80000000);
670}
671
672static void
673nvc0_fifo_uevent_disable(struct nouveau_event *event, int index)
674{
675 struct nvc0_fifo_priv *priv = event->priv;
676 nv_mask(priv, 0x002140, 0x80000000, 0x00000000);
677}
678
Ben Skeggsebb945a2012-07-20 08:17:34 +1000679static int
680nvc0_fifo_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
681 struct nouveau_oclass *oclass, void *data, u32 size,
682 struct nouveau_object **pobject)
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000683{
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000684 struct nvc0_fifo_priv *priv;
685 int ret;
686
Ben Skeggsebb945a2012-07-20 08:17:34 +1000687 ret = nouveau_fifo_create(parent, engine, oclass, 0, 127, &priv);
688 *pobject = nv_object(priv);
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000689 if (ret)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000690 return ret;
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000691
Ben Skeggsf50c8052013-04-24 18:02:35 +1000692 ret = nouveau_gpuobj_new(nv_object(priv), NULL, 0x1000, 0x1000, 0,
Ben Skeggsa07d0e72014-02-22 00:28:47 +1000693 &priv->runlist.mem[0]);
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000694 if (ret)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000695 return ret;
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000696
Ben Skeggsf50c8052013-04-24 18:02:35 +1000697 ret = nouveau_gpuobj_new(nv_object(priv), NULL, 0x1000, 0x1000, 0,
Ben Skeggsa07d0e72014-02-22 00:28:47 +1000698 &priv->runlist.mem[1]);
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000699 if (ret)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000700 return ret;
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000701
Ben Skeggsa07d0e72014-02-22 00:28:47 +1000702 init_waitqueue_head(&priv->runlist.wait);
703
Ben Skeggsf50c8052013-04-24 18:02:35 +1000704 ret = nouveau_gpuobj_new(nv_object(priv), NULL, 128 * 0x1000, 0x1000, 0,
Ben Skeggsebb945a2012-07-20 08:17:34 +1000705 &priv->user.mem);
Ben Skeggs9da226f2012-07-13 16:54:45 +1000706 if (ret)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000707 return ret;
Ben Skeggs9da226f2012-07-13 16:54:45 +1000708
Ben Skeggsebb945a2012-07-20 08:17:34 +1000709 ret = nouveau_gpuobj_map(priv->user.mem, NV_MEM_ACCESS_RW,
710 &priv->user.bar);
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000711 if (ret)
Ben Skeggsebb945a2012-07-20 08:17:34 +1000712 return ret;
713
Ben Skeggs9bd2ddb2013-01-31 13:51:20 +1000714 priv->base.uevent->enable = nvc0_fifo_uevent_enable;
715 priv->base.uevent->disable = nvc0_fifo_uevent_disable;
716 priv->base.uevent->priv = priv;
717
Ben Skeggsebb945a2012-07-20 08:17:34 +1000718 nv_subdev(priv)->unit = 0x00000100;
719 nv_subdev(priv)->intr = nvc0_fifo_intr;
720 nv_engine(priv)->cclass = &nvc0_fifo_cclass;
721 nv_engine(priv)->sclass = nvc0_fifo_sclass;
722 return 0;
Ben Skeggsc420b2d2012-05-01 20:48:08 +1000723}
Ben Skeggsebb945a2012-07-20 08:17:34 +1000724
725static void
726nvc0_fifo_dtor(struct nouveau_object *object)
727{
728 struct nvc0_fifo_priv *priv = (void *)object;
729
730 nouveau_gpuobj_unmap(&priv->user.bar);
731 nouveau_gpuobj_ref(NULL, &priv->user.mem);
Ben Skeggsa07d0e72014-02-22 00:28:47 +1000732 nouveau_gpuobj_ref(NULL, &priv->runlist.mem[0]);
733 nouveau_gpuobj_ref(NULL, &priv->runlist.mem[1]);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000734
735 nouveau_fifo_destroy(&priv->base);
736}
737
738static int
739nvc0_fifo_init(struct nouveau_object *object)
740{
741 struct nvc0_fifo_priv *priv = (void *)object;
742 int ret, i;
743
744 ret = nouveau_fifo_init(&priv->base);
745 if (ret)
746 return ret;
747
748 nv_wr32(priv, 0x000204, 0xffffffff);
749 nv_wr32(priv, 0x002204, 0xffffffff);
750
751 priv->spoon_nr = hweight32(nv_rd32(priv, 0x002204));
Ben Skeggs03574662014-01-28 11:47:46 +1000752 nv_debug(priv, "%d PBDMA unit(s)\n", priv->spoon_nr);
Ben Skeggsebb945a2012-07-20 08:17:34 +1000753
Ben Skeggs03574662014-01-28 11:47:46 +1000754 /* assign engines to PBDMAs */
Ben Skeggsebb945a2012-07-20 08:17:34 +1000755 if (priv->spoon_nr >= 3) {
756 nv_wr32(priv, 0x002208, ~(1 << 0)); /* PGRAPH */
757 nv_wr32(priv, 0x00220c, ~(1 << 1)); /* PVP */
758 nv_wr32(priv, 0x002210, ~(1 << 1)); /* PPP */
759 nv_wr32(priv, 0x002214, ~(1 << 1)); /* PBSP */
760 nv_wr32(priv, 0x002218, ~(1 << 2)); /* PCE0 */
761 nv_wr32(priv, 0x00221c, ~(1 << 1)); /* PCE1 */
762 }
763
Ben Skeggs03574662014-01-28 11:47:46 +1000764 /* PBDMA[n] */
Ben Skeggsebb945a2012-07-20 08:17:34 +1000765 for (i = 0; i < priv->spoon_nr; i++) {
766 nv_mask(priv, 0x04013c + (i * 0x2000), 0x10000100, 0x00000000);
767 nv_wr32(priv, 0x040108 + (i * 0x2000), 0xffffffff); /* INTR */
768 nv_wr32(priv, 0x04010c + (i * 0x2000), 0xfffffeff); /* INTREN */
769 }
770
771 nv_mask(priv, 0x002200, 0x00000001, 0x00000001);
772 nv_wr32(priv, 0x002254, 0x10000000 | priv->user.bar.offset >> 12);
773
Ben Skeggsebb945a2012-07-20 08:17:34 +1000774 nv_wr32(priv, 0x002100, 0xffffffff);
Ben Skeggsa07d0e72014-02-22 00:28:47 +1000775 nv_wr32(priv, 0x002140, 0x7fffffff);
Ben Skeggse99bf012014-02-22 00:18:17 +1000776 nv_wr32(priv, 0x002628, 0x00000001); /* ENGINE_INTR_EN */
Ben Skeggsebb945a2012-07-20 08:17:34 +1000777 return 0;
778}
779
Ben Skeggs16c4f222013-11-05 14:26:58 +1000780struct nouveau_oclass *
781nvc0_fifo_oclass = &(struct nouveau_oclass) {
Ben Skeggsebb945a2012-07-20 08:17:34 +1000782 .handle = NV_ENGINE(FIFO, 0xc0),
783 .ofuncs = &(struct nouveau_ofuncs) {
784 .ctor = nvc0_fifo_ctor,
785 .dtor = nvc0_fifo_dtor,
786 .init = nvc0_fifo_init,
787 .fini = _nouveau_fifo_fini,
788 },
789};