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 "changf100.h"
26 #include <core/client.h>
27 #include <core/gpuobj.h>
28 #include <subdev/fb.h>
29 #include <subdev/timer.h>
31 #include <nvif/class.h>
32 #include <nvif/unpack.h>
35 gf100_fifo_gpfifo_engine_addr(struct nvkm_engine *engine)
37 switch (engine->subdev.index) {
38 case NVKM_ENGINE_SW : return 0;
39 case NVKM_ENGINE_GR : return 0x0210;
40 case NVKM_ENGINE_CE0 : return 0x0230;
41 case NVKM_ENGINE_CE1 : return 0x0240;
42 case NVKM_ENGINE_MSPDEC: return 0x0250;
43 case NVKM_ENGINE_MSPPP : return 0x0260;
44 case NVKM_ENGINE_MSVLD : return 0x0270;
52 gf100_fifo_gpfifo_engine_fini(struct nvkm_fifo_chan *base,
53 struct nvkm_engine *engine, bool suspend)
55 const u32 offset = gf100_fifo_gpfifo_engine_addr(engine);
56 struct gf100_fifo_chan *chan = gf100_fifo_chan(base);
57 struct nvkm_subdev *subdev = &chan->fifo->base.engine.subdev;
58 struct nvkm_device *device = subdev->device;
59 struct nvkm_gpuobj *inst = chan->base.inst;
62 mutex_lock(&subdev->mutex);
63 nvkm_wr32(device, 0x002634, chan->base.chid);
64 if (nvkm_msec(device, 2000,
65 if (nvkm_rd32(device, 0x002634) == chan->base.chid)
68 nvkm_error(subdev, "channel %d [%s] kick timeout\n",
69 chan->base.chid, chan->base.object.client->name);
72 mutex_unlock(&subdev->mutex);
79 nvkm_wo32(inst, offset + 0x00, 0x00000000);
80 nvkm_wo32(inst, offset + 0x04, 0x00000000);
88 gf100_fifo_gpfifo_engine_init(struct nvkm_fifo_chan *base,
89 struct nvkm_engine *engine)
91 const u32 offset = gf100_fifo_gpfifo_engine_addr(engine);
92 struct gf100_fifo_chan *chan = gf100_fifo_chan(base);
93 struct nvkm_gpuobj *inst = chan->base.inst;
96 u64 addr = chan->engn[engine->subdev.index].vma.offset;
98 nvkm_wo32(inst, offset + 0x00, lower_32_bits(addr) | 4);
99 nvkm_wo32(inst, offset + 0x04, upper_32_bits(addr));
107 gf100_fifo_gpfifo_engine_dtor(struct nvkm_fifo_chan *base,
108 struct nvkm_engine *engine)
110 struct gf100_fifo_chan *chan = gf100_fifo_chan(base);
111 nvkm_gpuobj_unmap(&chan->engn[engine->subdev.index].vma);
112 nvkm_gpuobj_del(&chan->engn[engine->subdev.index].inst);
116 gf100_fifo_gpfifo_engine_ctor(struct nvkm_fifo_chan *base,
117 struct nvkm_engine *engine,
118 struct nvkm_object *object)
120 struct gf100_fifo_chan *chan = gf100_fifo_chan(base);
121 int engn = engine->subdev.index;
124 if (!gf100_fifo_gpfifo_engine_addr(engine))
127 ret = nvkm_object_bind(object, NULL, 0, &chan->engn[engn].inst);
131 return nvkm_gpuobj_map(chan->engn[engn].inst, chan->vm,
132 NV_MEM_ACCESS_RW, &chan->engn[engn].vma);
136 gf100_fifo_gpfifo_fini(struct nvkm_fifo_chan *base)
138 struct gf100_fifo_chan *chan = gf100_fifo_chan(base);
139 struct gf100_fifo *fifo = chan->fifo;
140 struct nvkm_device *device = fifo->base.engine.subdev.device;
141 u32 coff = chan->base.chid * 8;
143 if (!list_empty(&chan->head) && !chan->killed) {
144 list_del_init(&chan->head);
145 nvkm_mask(device, 0x003004 + coff, 0x00000001, 0x00000000);
146 gf100_fifo_runlist_update(fifo);
149 gf100_fifo_intr_engine(fifo);
151 nvkm_wr32(device, 0x003000 + coff, 0x00000000);
155 gf100_fifo_gpfifo_init(struct nvkm_fifo_chan *base)
157 struct gf100_fifo_chan *chan = gf100_fifo_chan(base);
158 struct gf100_fifo *fifo = chan->fifo;
159 struct nvkm_device *device = fifo->base.engine.subdev.device;
160 u32 addr = chan->base.inst->addr >> 12;
161 u32 coff = chan->base.chid * 8;
163 nvkm_wr32(device, 0x003000 + coff, 0xc0000000 | addr);
165 if (list_empty(&chan->head) && !chan->killed) {
166 list_add_tail(&chan->head, &fifo->chan);
167 nvkm_wr32(device, 0x003004 + coff, 0x001f0001);
168 gf100_fifo_runlist_update(fifo);
173 gf100_fifo_gpfifo_dtor(struct nvkm_fifo_chan *base)
175 struct gf100_fifo_chan *chan = gf100_fifo_chan(base);
176 nvkm_vm_ref(NULL, &chan->vm, chan->pgd);
177 nvkm_gpuobj_del(&chan->pgd);
181 static const struct nvkm_fifo_chan_func
182 gf100_fifo_gpfifo_func = {
183 .dtor = gf100_fifo_gpfifo_dtor,
184 .init = gf100_fifo_gpfifo_init,
185 .fini = gf100_fifo_gpfifo_fini,
186 .ntfy = g84_fifo_chan_ntfy,
187 .engine_ctor = gf100_fifo_gpfifo_engine_ctor,
188 .engine_dtor = gf100_fifo_gpfifo_engine_dtor,
189 .engine_init = gf100_fifo_gpfifo_engine_init,
190 .engine_fini = gf100_fifo_gpfifo_engine_fini,
194 gf100_fifo_gpfifo_new(struct nvkm_fifo *base, const struct nvkm_oclass *oclass,
195 void *data, u32 size, struct nvkm_object **pobject)
198 struct fermi_channel_gpfifo_v0 v0;
200 struct gf100_fifo *fifo = gf100_fifo(base);
201 struct nvkm_device *device = fifo->base.engine.subdev.device;
202 struct nvkm_object *parent = oclass->parent;
203 struct gf100_fifo_chan *chan;
204 u64 usermem, ioffset, ilength;
207 nvif_ioctl(parent, "create channel gpfifo size %d\n", size);
208 if (nvif_unpack(args->v0, 0, 0, false)) {
209 nvif_ioctl(parent, "create channel gpfifo vers %d vm %llx "
210 "ioffset %016llx ilength %08x\n",
211 args->v0.version, args->v0.vm, args->v0.ioffset,
216 /* allocate channel */
217 if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL)))
219 *pobject = &chan->base.object;
221 INIT_LIST_HEAD(&chan->head);
223 ret = nvkm_fifo_chan_ctor(&gf100_fifo_gpfifo_func, &fifo->base,
224 0x1000, 0x1000, true, args->v0.vm, 0,
225 (1ULL << NVKM_ENGINE_CE0) |
226 (1ULL << NVKM_ENGINE_CE1) |
227 (1ULL << NVKM_ENGINE_GR) |
228 (1ULL << NVKM_ENGINE_MSPDEC) |
229 (1ULL << NVKM_ENGINE_MSPPP) |
230 (1ULL << NVKM_ENGINE_MSVLD) |
231 (1ULL << NVKM_ENGINE_SW),
232 1, fifo->user.bar.offset, 0x1000,
233 oclass, &chan->base);
237 args->v0.chid = chan->base.chid;
240 ret = nvkm_gpuobj_new(device, 0x10000, 0x1000, false, NULL, &chan->pgd);
244 nvkm_kmap(chan->base.inst);
245 nvkm_wo32(chan->base.inst, 0x0200, lower_32_bits(chan->pgd->addr));
246 nvkm_wo32(chan->base.inst, 0x0204, upper_32_bits(chan->pgd->addr));
247 nvkm_wo32(chan->base.inst, 0x0208, 0xffffffff);
248 nvkm_wo32(chan->base.inst, 0x020c, 0x000000ff);
249 nvkm_done(chan->base.inst);
251 ret = nvkm_vm_ref(chan->base.vm, &chan->vm, chan->pgd);
255 /* clear channel control registers */
257 usermem = chan->base.chid * 0x1000;
258 ioffset = args->v0.ioffset;
259 ilength = order_base_2(args->v0.ilength / 8);
261 nvkm_kmap(fifo->user.mem);
262 for (i = 0; i < 0x1000; i += 4)
263 nvkm_wo32(fifo->user.mem, usermem + i, 0x00000000);
264 nvkm_done(fifo->user.mem);
265 usermem = nvkm_memory_addr(fifo->user.mem) + usermem;
268 nvkm_kmap(chan->base.inst);
269 nvkm_wo32(chan->base.inst, 0x08, lower_32_bits(usermem));
270 nvkm_wo32(chan->base.inst, 0x0c, upper_32_bits(usermem));
271 nvkm_wo32(chan->base.inst, 0x10, 0x0000face);
272 nvkm_wo32(chan->base.inst, 0x30, 0xfffff902);
273 nvkm_wo32(chan->base.inst, 0x48, lower_32_bits(ioffset));
274 nvkm_wo32(chan->base.inst, 0x4c, upper_32_bits(ioffset) |
276 nvkm_wo32(chan->base.inst, 0x54, 0x00000002);
277 nvkm_wo32(chan->base.inst, 0x84, 0x20400000);
278 nvkm_wo32(chan->base.inst, 0x94, 0x30000001);
279 nvkm_wo32(chan->base.inst, 0x9c, 0x00000100);
280 nvkm_wo32(chan->base.inst, 0xa4, 0x1f1f1f1f);
281 nvkm_wo32(chan->base.inst, 0xa8, 0x1f1f1f1f);
282 nvkm_wo32(chan->base.inst, 0xac, 0x0000001f);
283 nvkm_wo32(chan->base.inst, 0xb8, 0xf8000000);
284 nvkm_wo32(chan->base.inst, 0xf8, 0x10003080); /* 0x002310 */
285 nvkm_wo32(chan->base.inst, 0xfc, 0x10000010); /* 0x002350 */
286 nvkm_done(chan->base.inst);
290 const struct nvkm_fifo_chan_oclass
291 gf100_fifo_gpfifo_oclass = {
292 .base.oclass = FERMI_CHANNEL_GPFIFO,
295 .ctor = gf100_fifo_gpfifo_new,