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.
24 #include "changk104.h"
26 #include <core/client.h>
27 #include <core/gpuobj.h>
28 #include <subdev/fb.h>
29 #include <subdev/mmu.h>
30 #include <subdev/timer.h>
32 #include <nvif/class.h>
33 #include <nvif/unpack.h>
36 gk104_fifo_gpfifo_kick(struct gk104_fifo_chan *chan)
38 struct gk104_fifo *fifo = chan->fifo;
39 struct nvkm_subdev *subdev = &fifo->base.engine.subdev;
40 struct nvkm_device *device = subdev->device;
41 struct nvkm_client *client = chan->base.object.client;
44 mutex_lock(&subdev->mutex);
45 nvkm_wr32(device, 0x002634, chan->base.chid);
46 if (nvkm_msec(device, 2000,
47 if (!(nvkm_rd32(device, 0x002634) & 0x00100000))
50 nvkm_error(subdev, "channel %d [%s] kick timeout\n",
51 chan->base.chid, client->name);
54 mutex_unlock(&subdev->mutex);
59 gk104_fifo_gpfifo_engine_addr(struct nvkm_engine *engine)
61 switch (engine->subdev.index) {
63 case NVKM_ENGINE_CE0 :
64 case NVKM_ENGINE_CE1 :
65 case NVKM_ENGINE_CE2 : return 0x0000;
66 case NVKM_ENGINE_GR : return 0x0210;
67 case NVKM_ENGINE_MSPDEC: return 0x0250;
68 case NVKM_ENGINE_MSPPP : return 0x0260;
69 case NVKM_ENGINE_MSVLD : return 0x0270;
77 gk104_fifo_gpfifo_engine_fini(struct nvkm_fifo_chan *base,
78 struct nvkm_engine *engine, bool suspend)
80 const u32 offset = gk104_fifo_gpfifo_engine_addr(engine);
81 struct gk104_fifo_chan *chan = gk104_fifo_chan(base);
82 struct nvkm_gpuobj *inst = chan->base.inst;
85 ret = gk104_fifo_gpfifo_kick(chan);
91 nvkm_wo32(inst, offset + 0x00, 0x00000000);
92 nvkm_wo32(inst, offset + 0x04, 0x00000000);
100 gk104_fifo_gpfifo_engine_init(struct nvkm_fifo_chan *base,
101 struct nvkm_engine *engine)
103 const u32 offset = gk104_fifo_gpfifo_engine_addr(engine);
104 struct gk104_fifo_chan *chan = gk104_fifo_chan(base);
105 struct nvkm_gpuobj *inst = chan->base.inst;
108 u64 addr = chan->engn[engine->subdev.index].vma.offset;
110 nvkm_wo32(inst, offset + 0x00, lower_32_bits(addr) | 4);
111 nvkm_wo32(inst, offset + 0x04, upper_32_bits(addr));
119 gk104_fifo_gpfifo_engine_dtor(struct nvkm_fifo_chan *base,
120 struct nvkm_engine *engine)
122 struct gk104_fifo_chan *chan = gk104_fifo_chan(base);
123 nvkm_gpuobj_unmap(&chan->engn[engine->subdev.index].vma);
124 nvkm_gpuobj_del(&chan->engn[engine->subdev.index].inst);
128 gk104_fifo_gpfifo_engine_ctor(struct nvkm_fifo_chan *base,
129 struct nvkm_engine *engine,
130 struct nvkm_object *object)
132 struct gk104_fifo_chan *chan = gk104_fifo_chan(base);
133 int engn = engine->subdev.index;
136 if (!gk104_fifo_gpfifo_engine_addr(engine))
139 ret = nvkm_object_bind(object, NULL, 0, &chan->engn[engn].inst);
143 return nvkm_gpuobj_map(chan->engn[engn].inst, chan->vm,
144 NV_MEM_ACCESS_RW, &chan->engn[engn].vma);
148 gk104_fifo_gpfifo_fini(struct nvkm_fifo_chan *base)
150 struct gk104_fifo_chan *chan = gk104_fifo_chan(base);
151 struct gk104_fifo *fifo = chan->fifo;
152 struct nvkm_device *device = fifo->base.engine.subdev.device;
153 u32 coff = chan->base.chid * 8;
155 if (!list_empty(&chan->head)) {
156 list_del_init(&chan->head);
157 nvkm_mask(device, 0x800004 + coff, 0x00000800, 0x00000800);
158 gk104_fifo_runlist_update(fifo, chan->engine);
161 nvkm_wr32(device, 0x800000 + coff, 0x00000000);
165 gk104_fifo_gpfifo_init(struct nvkm_fifo_chan *base)
167 struct gk104_fifo_chan *chan = gk104_fifo_chan(base);
168 struct gk104_fifo *fifo = chan->fifo;
169 struct nvkm_device *device = fifo->base.engine.subdev.device;
170 u32 addr = chan->base.inst->addr >> 12;
171 u32 coff = chan->base.chid * 8;
173 nvkm_mask(device, 0x800004 + coff, 0x000f0000, chan->engine << 16);
174 nvkm_wr32(device, 0x800000 + coff, 0x80000000 | addr);
176 if (list_empty(&chan->head) && !chan->killed) {
177 list_add_tail(&chan->head, &fifo->engine[chan->engine].chan);
178 nvkm_mask(device, 0x800004 + coff, 0x00000400, 0x00000400);
179 gk104_fifo_runlist_update(fifo, chan->engine);
180 nvkm_mask(device, 0x800004 + coff, 0x00000400, 0x00000400);
185 gk104_fifo_gpfifo_dtor(struct nvkm_fifo_chan *base)
187 struct gk104_fifo_chan *chan = gk104_fifo_chan(base);
188 nvkm_vm_ref(NULL, &chan->vm, chan->pgd);
189 nvkm_gpuobj_del(&chan->pgd);
193 static const struct nvkm_fifo_chan_func
194 gk104_fifo_gpfifo_func = {
195 .dtor = gk104_fifo_gpfifo_dtor,
196 .init = gk104_fifo_gpfifo_init,
197 .fini = gk104_fifo_gpfifo_fini,
198 .ntfy = g84_fifo_chan_ntfy,
199 .engine_ctor = gk104_fifo_gpfifo_engine_ctor,
200 .engine_dtor = gk104_fifo_gpfifo_engine_dtor,
201 .engine_init = gk104_fifo_gpfifo_engine_init,
202 .engine_fini = gk104_fifo_gpfifo_engine_fini,
206 gk104_fifo_gpfifo_new(struct nvkm_fifo *base, const struct nvkm_oclass *oclass,
207 void *data, u32 size, struct nvkm_object **pobject)
210 struct kepler_channel_gpfifo_a_v0 v0;
212 struct gk104_fifo *fifo = gk104_fifo(base);
213 struct nvkm_device *device = fifo->base.engine.subdev.device;
214 struct nvkm_object *parent = oclass->parent;
215 struct gk104_fifo_chan *chan;
216 u64 usermem, ioffset, ilength;
220 nvif_ioctl(parent, "create channel gpfifo size %d\n", size);
221 if (nvif_unpack(args->v0, 0, 0, false)) {
222 nvif_ioctl(parent, "create channel gpfifo vers %d vm %llx "
223 "ioffset %016llx ilength %08x engine %08x\n",
224 args->v0.version, args->v0.vm, args->v0.ioffset,
225 args->v0.ilength, args->v0.engine);
229 /* determine which downstream engines are present */
230 for (i = 0, engines = 0; i < ARRAY_SIZE(fifo->engine); i++) {
231 u64 subdevs = gk104_fifo_engine_subdev(i);
232 if (!nvkm_device_engine(device, __ffs64(subdevs)))
237 /* if this is an engine mask query, we're done */
238 if (!args->v0.engine) {
239 args->v0.engine = engines;
240 return nvkm_object_new(oclass, NULL, 0, pobject);
243 /* check that we support a requested engine - note that the user
244 * argument is a mask in order to allow the user to request (for
245 * example) *any* copy engine, but doesn't matter which.
247 args->v0.engine &= engines;
248 if (!args->v0.engine) {
249 nvif_ioctl(parent, "no supported engine\n");
253 /* allocate the channel */
254 if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL)))
256 *pobject = &chan->base.object;
258 chan->engine = __ffs(args->v0.engine);
259 INIT_LIST_HEAD(&chan->head);
261 ret = nvkm_fifo_chan_ctor(&gk104_fifo_gpfifo_func, &fifo->base,
262 0x1000, 0x1000, true, args->v0.vm, 0,
263 gk104_fifo_engine_subdev(chan->engine),
264 1, fifo->user.bar.offset, 0x200,
265 oclass, &chan->base);
269 args->v0.chid = chan->base.chid;
272 ret = nvkm_gpuobj_new(device, 0x10000, 0x1000, false, NULL, &chan->pgd);
276 nvkm_kmap(chan->base.inst);
277 nvkm_wo32(chan->base.inst, 0x0200, lower_32_bits(chan->pgd->addr));
278 nvkm_wo32(chan->base.inst, 0x0204, upper_32_bits(chan->pgd->addr));
279 nvkm_wo32(chan->base.inst, 0x0208, 0xffffffff);
280 nvkm_wo32(chan->base.inst, 0x020c, 0x000000ff);
281 nvkm_done(chan->base.inst);
283 ret = nvkm_vm_ref(chan->base.vm, &chan->vm, chan->pgd);
287 /* clear channel control registers */
288 usermem = chan->base.chid * 0x200;
289 ioffset = args->v0.ioffset;
290 ilength = order_base_2(args->v0.ilength / 8);
292 nvkm_kmap(fifo->user.mem);
293 for (i = 0; i < 0x200; i += 4)
294 nvkm_wo32(fifo->user.mem, usermem + i, 0x00000000);
295 nvkm_done(fifo->user.mem);
296 usermem = nvkm_memory_addr(fifo->user.mem) + usermem;
299 nvkm_kmap(chan->base.inst);
300 nvkm_wo32(chan->base.inst, 0x08, lower_32_bits(usermem));
301 nvkm_wo32(chan->base.inst, 0x0c, upper_32_bits(usermem));
302 nvkm_wo32(chan->base.inst, 0x10, 0x0000face);
303 nvkm_wo32(chan->base.inst, 0x30, 0xfffff902);
304 nvkm_wo32(chan->base.inst, 0x48, lower_32_bits(ioffset));
305 nvkm_wo32(chan->base.inst, 0x4c, upper_32_bits(ioffset) |
307 nvkm_wo32(chan->base.inst, 0x84, 0x20400000);
308 nvkm_wo32(chan->base.inst, 0x94, 0x30000001);
309 nvkm_wo32(chan->base.inst, 0x9c, 0x00000100);
310 nvkm_wo32(chan->base.inst, 0xac, 0x0000001f);
311 nvkm_wo32(chan->base.inst, 0xe8, chan->base.chid);
312 nvkm_wo32(chan->base.inst, 0xb8, 0xf8000000);
313 nvkm_wo32(chan->base.inst, 0xf8, 0x10003080); /* 0x002310 */
314 nvkm_wo32(chan->base.inst, 0xfc, 0x10000010); /* 0x002350 */
315 nvkm_done(chan->base.inst);
319 const struct nvkm_fifo_chan_oclass
320 gk104_fifo_gpfifo_oclass = {
321 .base.oclass = KEPLER_CHANNEL_GPFIFO_A,
324 .ctor = gk104_fifo_gpfifo_new,