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.
27 #include <core/client.h>
28 #include <core/engctx.h>
29 #include <core/ramht.h>
30 #include <subdev/bar.h>
31 #include <subdev/mmu.h>
32 #include <subdev/timer.h>
34 #include <nvif/class.h>
35 #include <nvif/unpack.h>
37 /*******************************************************************************
38 * FIFO channel objects
39 ******************************************************************************/
42 g84_fifo_context_attach(struct nvkm_object *parent, struct nvkm_object *object)
44 struct nvkm_bar *bar = nvkm_bar(parent);
45 struct nv50_fifo_base *base = (void *)parent->parent;
46 struct nvkm_gpuobj *ectx = (void *)object;
47 u64 limit = ectx->addr + ectx->size - 1;
48 u64 start = ectx->addr;
51 switch (nv_engidx(object->engine)) {
52 case NVDEV_ENGINE_SW : return 0;
53 case NVDEV_ENGINE_GR : addr = 0x0020; break;
54 case NVDEV_ENGINE_VP :
55 case NVDEV_ENGINE_MSPDEC: addr = 0x0040; break;
56 case NVDEV_ENGINE_MSPPP :
57 case NVDEV_ENGINE_MPEG : addr = 0x0060; break;
58 case NVDEV_ENGINE_BSP :
59 case NVDEV_ENGINE_MSVLD : addr = 0x0080; break;
60 case NVDEV_ENGINE_CIPHER:
61 case NVDEV_ENGINE_SEC : addr = 0x00a0; break;
62 case NVDEV_ENGINE_CE0 : addr = 0x00c0; break;
67 nv_engctx(ectx)->addr = nv_gpuobj(base)->addr >> 12;
68 nv_wo32(base->eng, addr + 0x00, 0x00190000);
69 nv_wo32(base->eng, addr + 0x04, lower_32_bits(limit));
70 nv_wo32(base->eng, addr + 0x08, lower_32_bits(start));
71 nv_wo32(base->eng, addr + 0x0c, upper_32_bits(limit) << 24 |
72 upper_32_bits(start));
73 nv_wo32(base->eng, addr + 0x10, 0x00000000);
74 nv_wo32(base->eng, addr + 0x14, 0x00000000);
80 g84_fifo_context_detach(struct nvkm_object *parent, bool suspend,
81 struct nvkm_object *object)
83 struct nv50_fifo *fifo = (void *)parent->engine;
84 struct nv50_fifo_base *base = (void *)parent->parent;
85 struct nv50_fifo_chan *chan = (void *)parent;
86 struct nvkm_subdev *subdev = &fifo->base.engine.subdev;
87 struct nvkm_device *device = subdev->device;
88 struct nvkm_bar *bar = device->bar;
92 switch (nv_engidx(object->engine)) {
93 case NVDEV_ENGINE_SW : return 0;
94 case NVDEV_ENGINE_GR : engn = 0; addr = 0x0020; break;
95 case NVDEV_ENGINE_VP :
96 case NVDEV_ENGINE_MSPDEC: engn = 3; addr = 0x0040; break;
97 case NVDEV_ENGINE_MSPPP :
98 case NVDEV_ENGINE_MPEG : engn = 1; addr = 0x0060; break;
99 case NVDEV_ENGINE_BSP :
100 case NVDEV_ENGINE_MSVLD : engn = 5; addr = 0x0080; break;
101 case NVDEV_ENGINE_CIPHER:
102 case NVDEV_ENGINE_SEC : engn = 4; addr = 0x00a0; break;
103 case NVDEV_ENGINE_CE0 : engn = 2; addr = 0x00c0; break;
108 save = nvkm_mask(device, 0x002520, 0x0000003f, 1 << engn);
109 nvkm_wr32(device, 0x0032fc, nv_gpuobj(base)->addr >> 12);
110 done = nvkm_msec(device, 2000,
111 if (nvkm_rd32(device, 0x0032fc) != 0xffffffff)
114 nvkm_wr32(device, 0x002520, save);
116 nvkm_error(subdev, "channel %d [%s] unload timeout\n",
117 chan->base.chid, nvkm_client_name(chan));
122 nv_wo32(base->eng, addr + 0x00, 0x00000000);
123 nv_wo32(base->eng, addr + 0x04, 0x00000000);
124 nv_wo32(base->eng, addr + 0x08, 0x00000000);
125 nv_wo32(base->eng, addr + 0x0c, 0x00000000);
126 nv_wo32(base->eng, addr + 0x10, 0x00000000);
127 nv_wo32(base->eng, addr + 0x14, 0x00000000);
133 g84_fifo_object_attach(struct nvkm_object *parent,
134 struct nvkm_object *object, u32 handle)
136 struct nv50_fifo_chan *chan = (void *)parent;
139 if (nv_iclass(object, NV_GPUOBJ_CLASS))
140 context = nv_gpuobj(object)->node->offset >> 4;
142 context = 0x00000004; /* just non-zero */
144 switch (nv_engidx(object->engine)) {
145 case NVDEV_ENGINE_DMAOBJ:
146 case NVDEV_ENGINE_SW : context |= 0x00000000; break;
147 case NVDEV_ENGINE_GR : context |= 0x00100000; break;
148 case NVDEV_ENGINE_MPEG :
149 case NVDEV_ENGINE_MSPPP : context |= 0x00200000; break;
150 case NVDEV_ENGINE_ME :
151 case NVDEV_ENGINE_CE0 : context |= 0x00300000; break;
152 case NVDEV_ENGINE_VP :
153 case NVDEV_ENGINE_MSPDEC: context |= 0x00400000; break;
154 case NVDEV_ENGINE_CIPHER:
155 case NVDEV_ENGINE_SEC :
156 case NVDEV_ENGINE_VIC : context |= 0x00500000; break;
157 case NVDEV_ENGINE_BSP :
158 case NVDEV_ENGINE_MSVLD : context |= 0x00600000; break;
163 return nvkm_ramht_insert(chan->ramht, 0, handle, context);
167 g84_fifo_chan_ctor_dma(struct nvkm_object *parent, struct nvkm_object *engine,
168 struct nvkm_oclass *oclass, void *data, u32 size,
169 struct nvkm_object **pobject)
172 struct nv03_channel_dma_v0 v0;
174 struct nvkm_bar *bar = nvkm_bar(parent);
175 struct nv50_fifo_base *base = (void *)parent;
176 struct nv50_fifo_chan *chan;
179 nv_ioctl(parent, "create channel dma size %d\n", size);
180 if (nvif_unpack(args->v0, 0, 0, false)) {
181 nv_ioctl(parent, "create channel dma vers %d pushbuf %08x "
182 "offset %016llx\n", args->v0.version,
183 args->v0.pushbuf, args->v0.offset);
187 ret = nvkm_fifo_channel_create(parent, engine, oclass, 0, 0xc00000,
188 0x2000, args->v0.pushbuf,
189 (1ULL << NVDEV_ENGINE_DMAOBJ) |
190 (1ULL << NVDEV_ENGINE_SW) |
191 (1ULL << NVDEV_ENGINE_GR) |
192 (1ULL << NVDEV_ENGINE_MPEG) |
193 (1ULL << NVDEV_ENGINE_ME) |
194 (1ULL << NVDEV_ENGINE_VP) |
195 (1ULL << NVDEV_ENGINE_CIPHER) |
196 (1ULL << NVDEV_ENGINE_SEC) |
197 (1ULL << NVDEV_ENGINE_BSP) |
198 (1ULL << NVDEV_ENGINE_MSVLD) |
199 (1ULL << NVDEV_ENGINE_MSPDEC) |
200 (1ULL << NVDEV_ENGINE_MSPPP) |
201 (1ULL << NVDEV_ENGINE_CE0) |
202 (1ULL << NVDEV_ENGINE_VIC), &chan);
203 *pobject = nv_object(chan);
207 args->v0.chid = chan->base.chid;
209 ret = nvkm_ramht_new(nv_object(chan), nv_object(chan), 0x8000, 16,
214 nv_parent(chan)->context_attach = g84_fifo_context_attach;
215 nv_parent(chan)->context_detach = g84_fifo_context_detach;
216 nv_parent(chan)->object_attach = g84_fifo_object_attach;
217 nv_parent(chan)->object_detach = nv50_fifo_object_detach;
219 nv_wo32(base->ramfc, 0x08, lower_32_bits(args->v0.offset));
220 nv_wo32(base->ramfc, 0x0c, upper_32_bits(args->v0.offset));
221 nv_wo32(base->ramfc, 0x10, lower_32_bits(args->v0.offset));
222 nv_wo32(base->ramfc, 0x14, upper_32_bits(args->v0.offset));
223 nv_wo32(base->ramfc, 0x3c, 0x003f6078);
224 nv_wo32(base->ramfc, 0x44, 0x01003fff);
225 nv_wo32(base->ramfc, 0x48, chan->base.pushgpu->node->offset >> 4);
226 nv_wo32(base->ramfc, 0x4c, 0xffffffff);
227 nv_wo32(base->ramfc, 0x60, 0x7fffffff);
228 nv_wo32(base->ramfc, 0x78, 0x00000000);
229 nv_wo32(base->ramfc, 0x7c, 0x30000001);
230 nv_wo32(base->ramfc, 0x80, ((chan->ramht->bits - 9) << 27) |
231 (4 << 24) /* SEARCH_FULL */ |
232 (chan->ramht->gpuobj.node->offset >> 4));
233 nv_wo32(base->ramfc, 0x88, base->cache->addr >> 10);
234 nv_wo32(base->ramfc, 0x98, nv_gpuobj(base)->addr >> 12);
240 g84_fifo_chan_ctor_ind(struct nvkm_object *parent, struct nvkm_object *engine,
241 struct nvkm_oclass *oclass, void *data, u32 size,
242 struct nvkm_object **pobject)
245 struct nv50_channel_gpfifo_v0 v0;
247 struct nvkm_bar *bar = nvkm_bar(parent);
248 struct nv50_fifo_base *base = (void *)parent;
249 struct nv50_fifo_chan *chan;
250 u64 ioffset, ilength;
253 nv_ioctl(parent, "create channel gpfifo size %d\n", size);
254 if (nvif_unpack(args->v0, 0, 0, false)) {
255 nv_ioctl(parent, "create channel gpfifo vers %d pushbuf %08x "
256 "ioffset %016llx ilength %08x\n",
257 args->v0.version, args->v0.pushbuf, args->v0.ioffset,
262 ret = nvkm_fifo_channel_create(parent, engine, oclass, 0, 0xc00000,
263 0x2000, args->v0.pushbuf,
264 (1ULL << NVDEV_ENGINE_DMAOBJ) |
265 (1ULL << NVDEV_ENGINE_SW) |
266 (1ULL << NVDEV_ENGINE_GR) |
267 (1ULL << NVDEV_ENGINE_MPEG) |
268 (1ULL << NVDEV_ENGINE_ME) |
269 (1ULL << NVDEV_ENGINE_VP) |
270 (1ULL << NVDEV_ENGINE_CIPHER) |
271 (1ULL << NVDEV_ENGINE_SEC) |
272 (1ULL << NVDEV_ENGINE_BSP) |
273 (1ULL << NVDEV_ENGINE_MSVLD) |
274 (1ULL << NVDEV_ENGINE_MSPDEC) |
275 (1ULL << NVDEV_ENGINE_MSPPP) |
276 (1ULL << NVDEV_ENGINE_CE0) |
277 (1ULL << NVDEV_ENGINE_VIC), &chan);
278 *pobject = nv_object(chan);
282 args->v0.chid = chan->base.chid;
284 ret = nvkm_ramht_new(nv_object(chan), nv_object(chan), 0x8000, 16,
289 nv_parent(chan)->context_attach = g84_fifo_context_attach;
290 nv_parent(chan)->context_detach = g84_fifo_context_detach;
291 nv_parent(chan)->object_attach = g84_fifo_object_attach;
292 nv_parent(chan)->object_detach = nv50_fifo_object_detach;
294 ioffset = args->v0.ioffset;
295 ilength = order_base_2(args->v0.ilength / 8);
297 nv_wo32(base->ramfc, 0x3c, 0x403f6078);
298 nv_wo32(base->ramfc, 0x44, 0x01003fff);
299 nv_wo32(base->ramfc, 0x48, chan->base.pushgpu->node->offset >> 4);
300 nv_wo32(base->ramfc, 0x50, lower_32_bits(ioffset));
301 nv_wo32(base->ramfc, 0x54, upper_32_bits(ioffset) | (ilength << 16));
302 nv_wo32(base->ramfc, 0x60, 0x7fffffff);
303 nv_wo32(base->ramfc, 0x78, 0x00000000);
304 nv_wo32(base->ramfc, 0x7c, 0x30000001);
305 nv_wo32(base->ramfc, 0x80, ((chan->ramht->bits - 9) << 27) |
306 (4 << 24) /* SEARCH_FULL */ |
307 (chan->ramht->gpuobj.node->offset >> 4));
308 nv_wo32(base->ramfc, 0x88, base->cache->addr >> 10);
309 nv_wo32(base->ramfc, 0x98, nv_gpuobj(base)->addr >> 12);
315 g84_fifo_chan_init(struct nvkm_object *object)
317 struct nv50_fifo *fifo = (void *)object->engine;
318 struct nv50_fifo_base *base = (void *)object->parent;
319 struct nv50_fifo_chan *chan = (void *)object;
320 struct nvkm_gpuobj *ramfc = base->ramfc;
321 struct nvkm_device *device = fifo->base.engine.subdev.device;
322 u32 chid = chan->base.chid;
325 ret = nvkm_fifo_channel_init(&chan->base);
329 nvkm_wr32(device, 0x002600 + (chid * 4), 0x80000000 | ramfc->addr >> 8);
330 nv50_fifo_playlist_update(fifo);
334 static struct nvkm_ofuncs
335 g84_fifo_ofuncs_dma = {
336 .ctor = g84_fifo_chan_ctor_dma,
337 .dtor = nv50_fifo_chan_dtor,
338 .init = g84_fifo_chan_init,
339 .fini = nv50_fifo_chan_fini,
340 .map = _nvkm_fifo_channel_map,
341 .rd32 = _nvkm_fifo_channel_rd32,
342 .wr32 = _nvkm_fifo_channel_wr32,
343 .ntfy = _nvkm_fifo_channel_ntfy
346 static struct nvkm_ofuncs
347 g84_fifo_ofuncs_ind = {
348 .ctor = g84_fifo_chan_ctor_ind,
349 .dtor = nv50_fifo_chan_dtor,
350 .init = g84_fifo_chan_init,
351 .fini = nv50_fifo_chan_fini,
352 .map = _nvkm_fifo_channel_map,
353 .rd32 = _nvkm_fifo_channel_rd32,
354 .wr32 = _nvkm_fifo_channel_wr32,
355 .ntfy = _nvkm_fifo_channel_ntfy
358 static struct nvkm_oclass
359 g84_fifo_sclass[] = {
360 { G82_CHANNEL_DMA, &g84_fifo_ofuncs_dma },
361 { G82_CHANNEL_GPFIFO, &g84_fifo_ofuncs_ind },
365 /*******************************************************************************
366 * FIFO context - basically just the instmem reserved for the channel
367 ******************************************************************************/
370 g84_fifo_context_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
371 struct nvkm_oclass *oclass, void *data, u32 size,
372 struct nvkm_object **pobject)
374 struct nv50_fifo_base *base;
377 ret = nvkm_fifo_context_create(parent, engine, oclass, NULL, 0x10000,
378 0x1000, NVOBJ_FLAG_HEAP, &base);
379 *pobject = nv_object(base);
383 ret = nvkm_gpuobj_new(nv_object(base), nv_object(base), 0x0200, 0,
384 NVOBJ_FLAG_ZERO_ALLOC, &base->eng);
388 ret = nvkm_gpuobj_new(nv_object(base), nv_object(base), 0x4000, 0,
393 ret = nvkm_vm_ref(nvkm_client(parent)->vm, &base->vm, base->pgd);
397 ret = nvkm_gpuobj_new(nv_object(base), nv_object(base), 0x1000,
398 0x400, NVOBJ_FLAG_ZERO_ALLOC, &base->cache);
402 ret = nvkm_gpuobj_new(nv_object(base), nv_object(base), 0x0100,
403 0x100, NVOBJ_FLAG_ZERO_ALLOC, &base->ramfc);
410 static struct nvkm_oclass
412 .handle = NV_ENGCTX(FIFO, 0x84),
413 .ofuncs = &(struct nvkm_ofuncs) {
414 .ctor = g84_fifo_context_ctor,
415 .dtor = nv50_fifo_context_dtor,
416 .init = _nvkm_fifo_context_init,
417 .fini = _nvkm_fifo_context_fini,
418 .rd32 = _nvkm_fifo_context_rd32,
419 .wr32 = _nvkm_fifo_context_wr32,
423 /*******************************************************************************
425 ******************************************************************************/
428 g84_fifo_uevent_init(struct nvkm_event *event, int type, int index)
430 struct nvkm_fifo *fifo = container_of(event, typeof(*fifo), uevent);
431 struct nvkm_device *device = fifo->engine.subdev.device;
432 nvkm_mask(device, 0x002140, 0x40000000, 0x40000000);
436 g84_fifo_uevent_fini(struct nvkm_event *event, int type, int index)
438 struct nvkm_fifo *fifo = container_of(event, typeof(*fifo), uevent);
439 struct nvkm_device *device = fifo->engine.subdev.device;
440 nvkm_mask(device, 0x002140, 0x40000000, 0x00000000);
443 static const struct nvkm_event_func
444 g84_fifo_uevent_func = {
445 .ctor = nvkm_fifo_uevent_ctor,
446 .init = g84_fifo_uevent_init,
447 .fini = g84_fifo_uevent_fini,
451 g84_fifo_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
452 struct nvkm_oclass *oclass, void *data, u32 size,
453 struct nvkm_object **pobject)
455 struct nv50_fifo *fifo;
458 ret = nvkm_fifo_create(parent, engine, oclass, 1, 127, &fifo);
459 *pobject = nv_object(fifo);
463 ret = nvkm_gpuobj_new(nv_object(fifo), NULL, 128 * 4, 0x1000, 0,
468 ret = nvkm_gpuobj_new(nv_object(fifo), NULL, 128 * 4, 0x1000, 0,
473 ret = nvkm_event_init(&g84_fifo_uevent_func, 1, 1, &fifo->base.uevent);
477 nv_subdev(fifo)->unit = 0x00000100;
478 nv_subdev(fifo)->intr = nv04_fifo_intr;
479 nv_engine(fifo)->cclass = &g84_fifo_cclass;
480 nv_engine(fifo)->sclass = g84_fifo_sclass;
481 fifo->base.pause = nv04_fifo_pause;
482 fifo->base.start = nv04_fifo_start;
487 g84_fifo_oclass = &(struct nvkm_oclass) {
488 .handle = NV_ENGINE(FIFO, 0x84),
489 .ofuncs = &(struct nvkm_ofuncs) {
490 .ctor = g84_fifo_ctor,
491 .dtor = nv50_fifo_dtor,
492 .init = nv50_fifo_init,
493 .fini = _nvkm_fifo_fini,