xref: /openbmc/linux/drivers/gpu/drm/nouveau/nvkm/engine/fifo/nv50.c (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
1c39f472eSBen Skeggs /*
2c39f472eSBen Skeggs  * Copyright 2012 Red Hat Inc.
3c39f472eSBen Skeggs  *
4c39f472eSBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
5c39f472eSBen Skeggs  * copy of this software and associated documentation files (the "Software"),
6c39f472eSBen Skeggs  * to deal in the Software without restriction, including without limitation
7c39f472eSBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8c39f472eSBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
9c39f472eSBen Skeggs  * Software is furnished to do so, subject to the following conditions:
10c39f472eSBen Skeggs  *
11c39f472eSBen Skeggs  * The above copyright notice and this permission notice shall be included in
12c39f472eSBen Skeggs  * all copies or substantial portions of the Software.
13c39f472eSBen Skeggs  *
14c39f472eSBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15c39f472eSBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16c39f472eSBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17c39f472eSBen Skeggs  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18c39f472eSBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19c39f472eSBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20c39f472eSBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
21c39f472eSBen Skeggs  *
22c39f472eSBen Skeggs  * Authors: Ben Skeggs
23c39f472eSBen Skeggs  */
24*06db7fdeSBen Skeggs #include "priv.h"
2562742b5eSBen Skeggs #include "cgrp.h"
26f5e45689SBen Skeggs #include "chan.h"
27800ac1f8SBen Skeggs #include "chid.h"
28d94470e9SBen Skeggs #include "runl.h"
29f5e45689SBen Skeggs 
303647c53bSBen Skeggs #include <core/ramht.h>
314a492fd5SBen Skeggs #include <subdev/timer.h>
324a492fd5SBen Skeggs 
33f5e45689SBen Skeggs #include <nvif/class.h>
34f5e45689SBen Skeggs 
3562742b5eSBen Skeggs void
nv50_eobj_ramht_del(struct nvkm_chan * chan,int hash)367ac29332SBen Skeggs nv50_eobj_ramht_del(struct nvkm_chan *chan, int hash)
377ac29332SBen Skeggs {
387ac29332SBen Skeggs 	nvkm_ramht_remove(chan->ramht, hash);
397ac29332SBen Skeggs }
407ac29332SBen Skeggs 
417ac29332SBen Skeggs int
nv50_eobj_ramht_add(struct nvkm_engn * engn,struct nvkm_object * eobj,struct nvkm_chan * chan)427ac29332SBen Skeggs nv50_eobj_ramht_add(struct nvkm_engn *engn, struct nvkm_object *eobj, struct nvkm_chan *chan)
437ac29332SBen Skeggs {
447ac29332SBen Skeggs 	return nvkm_ramht_insert(chan->ramht, eobj, 0, 4, eobj->handle, engn->id << 20);
457ac29332SBen Skeggs }
467ac29332SBen Skeggs 
477ac29332SBen Skeggs void
nv50_chan_stop(struct nvkm_chan * chan)4867059b9fSBen Skeggs nv50_chan_stop(struct nvkm_chan *chan)
4967059b9fSBen Skeggs {
5067059b9fSBen Skeggs 	struct nvkm_device *device = chan->cgrp->runl->fifo->engine.subdev.device;
5167059b9fSBen Skeggs 
5267059b9fSBen Skeggs 	nvkm_mask(device, 0x002600 + (chan->id * 4), 0x80000000, 0x00000000);
5367059b9fSBen Skeggs }
5467059b9fSBen Skeggs 
5567059b9fSBen Skeggs void
nv50_chan_start(struct nvkm_chan * chan)5667059b9fSBen Skeggs nv50_chan_start(struct nvkm_chan *chan)
5767059b9fSBen Skeggs {
5867059b9fSBen Skeggs 	struct nvkm_device *device = chan->cgrp->runl->fifo->engine.subdev.device;
5967059b9fSBen Skeggs 
6067059b9fSBen Skeggs 	nvkm_mask(device, 0x002600 + (chan->id * 4), 0x80000000, 0x80000000);
6167059b9fSBen Skeggs }
6267059b9fSBen Skeggs 
6367059b9fSBen Skeggs void
nv50_chan_unbind(struct nvkm_chan * chan)6462742b5eSBen Skeggs nv50_chan_unbind(struct nvkm_chan *chan)
6562742b5eSBen Skeggs {
6662742b5eSBen Skeggs 	struct nvkm_device *device = chan->cgrp->runl->fifo->engine.subdev.device;
6762742b5eSBen Skeggs 
6862742b5eSBen Skeggs 	nvkm_wr32(device, 0x002600 + (chan->id * 4), 0x00000000);
6962742b5eSBen Skeggs }
7062742b5eSBen Skeggs 
7162742b5eSBen Skeggs static void
nv50_chan_bind(struct nvkm_chan * chan)7262742b5eSBen Skeggs nv50_chan_bind(struct nvkm_chan *chan)
7362742b5eSBen Skeggs {
7462742b5eSBen Skeggs 	struct nvkm_device *device = chan->cgrp->runl->fifo->engine.subdev.device;
7562742b5eSBen Skeggs 
763647c53bSBen Skeggs 	nvkm_wr32(device, 0x002600 + (chan->id * 4), chan->ramfc->addr >> 12);
7762742b5eSBen Skeggs }
7862742b5eSBen Skeggs 
793647c53bSBen Skeggs static int
nv50_chan_ramfc_write(struct nvkm_chan * chan,u64 offset,u64 length,u32 devm,bool priv)803647c53bSBen Skeggs nv50_chan_ramfc_write(struct nvkm_chan *chan, u64 offset, u64 length, u32 devm, bool priv)
813647c53bSBen Skeggs {
823647c53bSBen Skeggs 	struct nvkm_device *device = chan->cgrp->runl->fifo->engine.subdev.device;
833647c53bSBen Skeggs 	const u32 limit2 = ilog2(length / 8);
843647c53bSBen Skeggs 	int ret;
853647c53bSBen Skeggs 
863647c53bSBen Skeggs 	ret = nvkm_gpuobj_new(device, 0x0200, 0x1000, true, chan->inst, &chan->ramfc);
873647c53bSBen Skeggs 	if (ret)
883647c53bSBen Skeggs 		return ret;
893647c53bSBen Skeggs 
903647c53bSBen Skeggs 	ret = nvkm_gpuobj_new(device, 0x1200, 0, true, chan->inst, &chan->eng);
913647c53bSBen Skeggs 	if (ret)
923647c53bSBen Skeggs 		return ret;
933647c53bSBen Skeggs 
943647c53bSBen Skeggs 	ret = nvkm_gpuobj_new(device, 0x4000, 0, false, chan->inst, &chan->pgd);
953647c53bSBen Skeggs 	if (ret)
963647c53bSBen Skeggs 		return ret;
973647c53bSBen Skeggs 
983647c53bSBen Skeggs 	ret = nvkm_ramht_new(device, 0x8000, 16, chan->inst, &chan->ramht);
993647c53bSBen Skeggs 	if (ret)
1003647c53bSBen Skeggs 		return ret;
1013647c53bSBen Skeggs 
1023647c53bSBen Skeggs 	nvkm_kmap(chan->ramfc);
1033647c53bSBen Skeggs 	nvkm_wo32(chan->ramfc, 0x3c, 0x403f6078);
1043647c53bSBen Skeggs 	nvkm_wo32(chan->ramfc, 0x44, 0x01003fff);
1053647c53bSBen Skeggs 	nvkm_wo32(chan->ramfc, 0x48, chan->push->node->offset >> 4);
1063647c53bSBen Skeggs 	nvkm_wo32(chan->ramfc, 0x50, lower_32_bits(offset));
1073647c53bSBen Skeggs 	nvkm_wo32(chan->ramfc, 0x54, upper_32_bits(offset) | (limit2 << 16));
1083647c53bSBen Skeggs 	nvkm_wo32(chan->ramfc, 0x60, 0x7fffffff);
1093647c53bSBen Skeggs 	nvkm_wo32(chan->ramfc, 0x78, 0x00000000);
1103647c53bSBen Skeggs 	nvkm_wo32(chan->ramfc, 0x7c, 0x30000000 | devm);
1113647c53bSBen Skeggs 	nvkm_wo32(chan->ramfc, 0x80, ((chan->ramht->bits - 9) << 27) |
1123647c53bSBen Skeggs 				     (4 << 24) /* SEARCH_FULL */ |
1133647c53bSBen Skeggs 				     (chan->ramht->gpuobj->node->offset >> 4));
1143647c53bSBen Skeggs 	nvkm_done(chan->ramfc);
1153647c53bSBen Skeggs 	return 0;
1163647c53bSBen Skeggs }
1173647c53bSBen Skeggs 
1183647c53bSBen Skeggs static const struct nvkm_chan_func_ramfc
1193647c53bSBen Skeggs nv50_chan_ramfc = {
1203647c53bSBen Skeggs 	.write = nv50_chan_ramfc_write,
1213647c53bSBen Skeggs 	.ctxdma = true,
1223647c53bSBen Skeggs 	.devm = 0xfff,
1233647c53bSBen Skeggs };
1243647c53bSBen Skeggs 
125fbe9f433SBen Skeggs const struct nvkm_chan_func_userd
126fbe9f433SBen Skeggs nv50_chan_userd = {
127fbe9f433SBen Skeggs 	.bar = 0,
128fbe9f433SBen Skeggs 	.base = 0xc00000,
129fbe9f433SBen Skeggs 	.size = 0x002000,
130fbe9f433SBen Skeggs };
131fbe9f433SBen Skeggs 
132d3e7a439SBen Skeggs const struct nvkm_chan_func_inst
133d3e7a439SBen Skeggs nv50_chan_inst = {
134d3e7a439SBen Skeggs 	.size = 0x10000,
135d3e7a439SBen Skeggs 	.vmm = true,
136d3e7a439SBen Skeggs };
137d3e7a439SBen Skeggs 
138f5e45689SBen Skeggs static const struct nvkm_chan_func
139f5e45689SBen Skeggs nv50_chan = {
140d3e7a439SBen Skeggs 	.inst = &nv50_chan_inst,
141fbe9f433SBen Skeggs 	.userd = &nv50_chan_userd,
1423647c53bSBen Skeggs 	.ramfc = &nv50_chan_ramfc,
14362742b5eSBen Skeggs 	.bind = nv50_chan_bind,
14462742b5eSBen Skeggs 	.unbind = nv50_chan_unbind,
14567059b9fSBen Skeggs 	.start = nv50_chan_start,
14667059b9fSBen Skeggs 	.stop = nv50_chan_stop,
147f5e45689SBen Skeggs };
148f5e45689SBen Skeggs 
1498ab849d6SBen Skeggs static void
nv50_ectx_bind(struct nvkm_engn * engn,struct nvkm_cctx * cctx,struct nvkm_chan * chan)1508ab849d6SBen Skeggs nv50_ectx_bind(struct nvkm_engn *engn, struct nvkm_cctx *cctx, struct nvkm_chan *chan)
1518ab849d6SBen Skeggs {
1528ab849d6SBen Skeggs 	struct nvkm_subdev *subdev = &chan->cgrp->runl->fifo->engine.subdev;
1538ab849d6SBen Skeggs 	struct nvkm_device *device = subdev->device;
1548ab849d6SBen Skeggs 	u64 start = 0, limit = 0;
1558ab849d6SBen Skeggs 	u32 flags = 0, ptr0, save;
1568ab849d6SBen Skeggs 
1578ab849d6SBen Skeggs 	switch (engn->engine->subdev.type) {
1588ab849d6SBen Skeggs 	case NVKM_ENGINE_GR    : ptr0 = 0x0000; break;
1598ab849d6SBen Skeggs 	case NVKM_ENGINE_MPEG  : ptr0 = 0x0060; break;
1608ab849d6SBen Skeggs 	default:
1618ab849d6SBen Skeggs 		WARN_ON(1);
1628ab849d6SBen Skeggs 		return;
1638ab849d6SBen Skeggs 	}
1648ab849d6SBen Skeggs 
1658ab849d6SBen Skeggs 	if (!cctx) {
1668ab849d6SBen Skeggs 		/* HW bug workaround:
1678ab849d6SBen Skeggs 		 *
1688ab849d6SBen Skeggs 		 * PFIFO will hang forever if the connected engines don't report
1698ab849d6SBen Skeggs 		 * that they've processed the context switch request.
1708ab849d6SBen Skeggs 		 *
1718ab849d6SBen Skeggs 		 * In order for the kickoff to work, we need to ensure all the
1728ab849d6SBen Skeggs 		 * connected engines are in a state where they can answer.
1738ab849d6SBen Skeggs 		 *
1748ab849d6SBen Skeggs 		 * Newer chipsets don't seem to suffer from this issue, and well,
1758ab849d6SBen Skeggs 		 * there's also a "ignore these engines" bitmask reg we can use
1768ab849d6SBen Skeggs 		 * if we hit the issue there..
1778ab849d6SBen Skeggs 		 */
1788ab849d6SBen Skeggs 		save = nvkm_mask(device, 0x00b860, 0x00000001, 0x00000001);
1798ab849d6SBen Skeggs 
1808ab849d6SBen Skeggs 		/* Tell engines to save out contexts. */
1818ab849d6SBen Skeggs 		nvkm_wr32(device, 0x0032fc, chan->inst->addr >> 12);
1828ab849d6SBen Skeggs 		nvkm_msec(device, 2000,
1838ab849d6SBen Skeggs 			if (nvkm_rd32(device, 0x0032fc) != 0xffffffff)
1848ab849d6SBen Skeggs 				break;
1858ab849d6SBen Skeggs 		);
1868ab849d6SBen Skeggs 		nvkm_wr32(device, 0x00b860, save);
1878ab849d6SBen Skeggs 	} else {
1888ab849d6SBen Skeggs 		flags = 0x00190000;
1898ab849d6SBen Skeggs 		start = cctx->vctx->inst->addr;
1908ab849d6SBen Skeggs 		limit = start + cctx->vctx->inst->size - 1;
1918ab849d6SBen Skeggs 	}
1928ab849d6SBen Skeggs 
1938ab849d6SBen Skeggs 	nvkm_kmap(chan->eng);
1948ab849d6SBen Skeggs 	nvkm_wo32(chan->eng, ptr0 + 0x00, flags);
1958ab849d6SBen Skeggs 	nvkm_wo32(chan->eng, ptr0 + 0x04, lower_32_bits(limit));
1968ab849d6SBen Skeggs 	nvkm_wo32(chan->eng, ptr0 + 0x08, lower_32_bits(start));
1978ab849d6SBen Skeggs 	nvkm_wo32(chan->eng, ptr0 + 0x0c, upper_32_bits(limit) << 24 |
1988ab849d6SBen Skeggs 					  lower_32_bits(start));
1998ab849d6SBen Skeggs 	nvkm_wo32(chan->eng, ptr0 + 0x10, 0x00000000);
2008ab849d6SBen Skeggs 	nvkm_wo32(chan->eng, ptr0 + 0x14, 0x00000000);
2018ab849d6SBen Skeggs 	nvkm_done(chan->eng);
2028ab849d6SBen Skeggs }
2038ab849d6SBen Skeggs 
204d94470e9SBen Skeggs static const struct nvkm_engn_func
205d94470e9SBen Skeggs nv50_engn = {
2068ab849d6SBen Skeggs 	.bind = nv50_ectx_bind,
2077ac29332SBen Skeggs 	.ramht_add = nv50_eobj_ramht_add,
2087ac29332SBen Skeggs 	.ramht_del = nv50_eobj_ramht_del,
209d94470e9SBen Skeggs };
210d94470e9SBen Skeggs 
211d94470e9SBen Skeggs const struct nvkm_engn_func
212d94470e9SBen Skeggs nv50_engn_sw = {
2137ac29332SBen Skeggs 	.ramht_add = nv50_eobj_ramht_add,
2147ac29332SBen Skeggs 	.ramht_del = nv50_eobj_ramht_del,
215d94470e9SBen Skeggs };
216d94470e9SBen Skeggs 
2174a492fd5SBen Skeggs static bool
nv50_runl_pending(struct nvkm_runl * runl)2184a492fd5SBen Skeggs nv50_runl_pending(struct nvkm_runl *runl)
2194a492fd5SBen Skeggs {
2204a492fd5SBen Skeggs 	return nvkm_rd32(runl->fifo->engine.subdev.device, 0x0032ec) & 0x00000100;
2214a492fd5SBen Skeggs }
2224a492fd5SBen Skeggs 
2234a492fd5SBen Skeggs int
nv50_runl_wait(struct nvkm_runl * runl)2244a492fd5SBen Skeggs nv50_runl_wait(struct nvkm_runl *runl)
2254a492fd5SBen Skeggs {
2264a492fd5SBen Skeggs 	struct nvkm_fifo *fifo = runl->fifo;
2274a492fd5SBen Skeggs 
2284a492fd5SBen Skeggs 	nvkm_msec(fifo->engine.subdev.device, fifo->timeout.chan_msec,
2294a492fd5SBen Skeggs 		if (!nvkm_runl_update_pending(runl))
2304a492fd5SBen Skeggs 			return 0;
2314a492fd5SBen Skeggs 		usleep_range(1, 2);
2324a492fd5SBen Skeggs 	);
2334a492fd5SBen Skeggs 
2344a492fd5SBen Skeggs 	return -ETIMEDOUT;
2354a492fd5SBen Skeggs }
2364a492fd5SBen Skeggs 
237b084fff2SBen Skeggs static void
nv50_runl_commit(struct nvkm_runl * runl,struct nvkm_memory * memory,u32 start,int count)238b084fff2SBen Skeggs nv50_runl_commit(struct nvkm_runl *runl, struct nvkm_memory *memory, u32 start, int count)
239b084fff2SBen Skeggs {
240b084fff2SBen Skeggs 	struct nvkm_device *device = runl->fifo->engine.subdev.device;
241b084fff2SBen Skeggs 	u64 addr = nvkm_memory_addr(memory) + start;
242b084fff2SBen Skeggs 
243b084fff2SBen Skeggs 	nvkm_wr32(device, 0x0032f4, addr >> 12);
244b084fff2SBen Skeggs 	nvkm_wr32(device, 0x0032ec, count);
245b084fff2SBen Skeggs }
246b084fff2SBen Skeggs 
247b084fff2SBen Skeggs static void
nv50_runl_insert_chan(struct nvkm_chan * chan,struct nvkm_memory * memory,u64 offset)248b084fff2SBen Skeggs nv50_runl_insert_chan(struct nvkm_chan *chan, struct nvkm_memory *memory, u64 offset)
249b084fff2SBen Skeggs {
250b084fff2SBen Skeggs 	nvkm_wo32(memory, offset, chan->id);
251b084fff2SBen Skeggs }
252b084fff2SBen Skeggs 
253b084fff2SBen Skeggs static struct nvkm_memory *
nv50_runl_alloc(struct nvkm_runl * runl,u32 * offset)254b084fff2SBen Skeggs nv50_runl_alloc(struct nvkm_runl *runl, u32 *offset)
255b084fff2SBen Skeggs {
256b084fff2SBen Skeggs 	const u32 segment = ALIGN((runl->cgrp_nr + runl->chan_nr) * runl->func->size, 0x1000);
257b084fff2SBen Skeggs 	const u32 maxsize = (runl->cgid ? runl->cgid->nr : 0) + runl->chid->nr;
258b084fff2SBen Skeggs 	int ret;
259b084fff2SBen Skeggs 
260b084fff2SBen Skeggs 	if (unlikely(!runl->mem)) {
261b084fff2SBen Skeggs 		ret = nvkm_memory_new(runl->fifo->engine.subdev.device, NVKM_MEM_TARGET_INST,
262b084fff2SBen Skeggs 				      maxsize * 2 * runl->func->size, 0, false, &runl->mem);
263b084fff2SBen Skeggs 		if (ret) {
264b084fff2SBen Skeggs 			RUNL_ERROR(runl, "alloc %d\n", ret);
265b084fff2SBen Skeggs 			return ERR_PTR(ret);
266b084fff2SBen Skeggs 		}
267b084fff2SBen Skeggs 	} else {
268b084fff2SBen Skeggs 		if (runl->offset + segment >= nvkm_memory_size(runl->mem)) {
269b084fff2SBen Skeggs 			ret = runl->func->wait(runl);
270b084fff2SBen Skeggs 			if (ret) {
271b084fff2SBen Skeggs 				RUNL_DEBUG(runl, "rewind timeout");
272b084fff2SBen Skeggs 				return ERR_PTR(ret);
273b084fff2SBen Skeggs 			}
274b084fff2SBen Skeggs 
275b084fff2SBen Skeggs 			runl->offset = 0;
276b084fff2SBen Skeggs 		}
277b084fff2SBen Skeggs 	}
278b084fff2SBen Skeggs 
279b084fff2SBen Skeggs 	*offset = runl->offset;
280b084fff2SBen Skeggs 	runl->offset += segment;
281b084fff2SBen Skeggs 	return runl->mem;
282b084fff2SBen Skeggs }
283b084fff2SBen Skeggs 
284b084fff2SBen Skeggs int
nv50_runl_update(struct nvkm_runl * runl)285b084fff2SBen Skeggs nv50_runl_update(struct nvkm_runl *runl)
286b084fff2SBen Skeggs {
287b084fff2SBen Skeggs 	struct nvkm_memory *memory;
288b084fff2SBen Skeggs 	struct nvkm_cgrp *cgrp;
289b084fff2SBen Skeggs 	struct nvkm_chan *chan;
290b084fff2SBen Skeggs 	u32 start, offset, count;
291b084fff2SBen Skeggs 
292b084fff2SBen Skeggs 	/*TODO: prio, interleaving. */
293b084fff2SBen Skeggs 
294b084fff2SBen Skeggs 	RUNL_TRACE(runl, "RAMRL: update cgrps:%d chans:%d", runl->cgrp_nr, runl->chan_nr);
295b084fff2SBen Skeggs 	memory = nv50_runl_alloc(runl, &start);
296b084fff2SBen Skeggs 	if (IS_ERR(memory))
297b084fff2SBen Skeggs 		return PTR_ERR(memory);
298b084fff2SBen Skeggs 
299b084fff2SBen Skeggs 	RUNL_TRACE(runl, "RAMRL: update start:%08x", start);
300b084fff2SBen Skeggs 	offset = start;
301b084fff2SBen Skeggs 
302b084fff2SBen Skeggs 	nvkm_kmap(memory);
303b084fff2SBen Skeggs 	nvkm_runl_foreach_cgrp(cgrp, runl) {
304b084fff2SBen Skeggs 		if (cgrp->hw) {
305b084fff2SBen Skeggs 			CGRP_TRACE(cgrp, "     RAMRL+%08x: chans:%d", offset, cgrp->chan_nr);
306b084fff2SBen Skeggs 			runl->func->insert_cgrp(cgrp, memory, offset);
307b084fff2SBen Skeggs 			offset += runl->func->size;
308b084fff2SBen Skeggs 		}
309b084fff2SBen Skeggs 
310b084fff2SBen Skeggs 		nvkm_cgrp_foreach_chan(chan, cgrp) {
311b084fff2SBen Skeggs 			CHAN_TRACE(chan, "RAMRL+%08x: [%s]", offset, chan->name);
312b084fff2SBen Skeggs 			runl->func->insert_chan(chan, memory, offset);
313b084fff2SBen Skeggs 			offset += runl->func->size;
314b084fff2SBen Skeggs 		}
315b084fff2SBen Skeggs 	}
316b084fff2SBen Skeggs 	nvkm_done(memory);
317b084fff2SBen Skeggs 
318b084fff2SBen Skeggs 	/*TODO: look into using features on newer HW to guarantee forward progress. */
319b084fff2SBen Skeggs 	list_rotate_left(&runl->cgrps);
320b084fff2SBen Skeggs 
321b084fff2SBen Skeggs 	count = (offset - start) / runl->func->size;
322b084fff2SBen Skeggs 	RUNL_TRACE(runl, "RAMRL: commit start:%08x count:%d", start, count);
323b084fff2SBen Skeggs 
324b084fff2SBen Skeggs 	runl->func->commit(runl, memory, start, count);
325b084fff2SBen Skeggs 	return 0;
326b084fff2SBen Skeggs }
327b084fff2SBen Skeggs 
328d94470e9SBen Skeggs const struct nvkm_runl_func
329d94470e9SBen Skeggs nv50_runl = {
330b084fff2SBen Skeggs 	.size = 4,
331b084fff2SBen Skeggs 	.update = nv50_runl_update,
332b084fff2SBen Skeggs 	.insert_chan = nv50_runl_insert_chan,
333b084fff2SBen Skeggs 	.commit = nv50_runl_commit,
3344a492fd5SBen Skeggs 	.wait = nv50_runl_wait,
3354a492fd5SBen Skeggs 	.pending = nv50_runl_pending,
336d94470e9SBen Skeggs };
337d94470e9SBen Skeggs 
33813de7f46SBen Skeggs void
nv50_fifo_init(struct nvkm_fifo * fifo)339b084fff2SBen Skeggs nv50_fifo_init(struct nvkm_fifo *fifo)
34013de7f46SBen Skeggs {
341b084fff2SBen Skeggs 	struct nvkm_runl *runl = nvkm_runl_first(fifo);
342b084fff2SBen Skeggs 	struct nvkm_device *device = fifo->engine.subdev.device;
34313de7f46SBen Skeggs 	int i;
34413de7f46SBen Skeggs 
34587744403SBen Skeggs 	nvkm_mask(device, 0x000200, 0x00000100, 0x00000000);
34687744403SBen Skeggs 	nvkm_mask(device, 0x000200, 0x00000100, 0x00000100);
34787744403SBen Skeggs 	nvkm_wr32(device, 0x00250c, 0x6f3cfc34);
34887744403SBen Skeggs 	nvkm_wr32(device, 0x002044, 0x01003fff);
349c39f472eSBen Skeggs 
35087744403SBen Skeggs 	nvkm_wr32(device, 0x002100, 0xffffffff);
35187744403SBen Skeggs 	nvkm_wr32(device, 0x002140, 0xbfffffff);
352c39f472eSBen Skeggs 
353c39f472eSBen Skeggs 	for (i = 0; i < 128; i++)
35487744403SBen Skeggs 		nvkm_wr32(device, 0x002600 + (i * 4), 0x00000000);
355b084fff2SBen Skeggs 
356b084fff2SBen Skeggs 	atomic_set(&runl->changed, 1);
357b084fff2SBen Skeggs 	runl->func->update(runl);
358c39f472eSBen Skeggs 
35987744403SBen Skeggs 	nvkm_wr32(device, 0x003200, 0x00000001);
36087744403SBen Skeggs 	nvkm_wr32(device, 0x003250, 0x00000001);
36187744403SBen Skeggs 	nvkm_wr32(device, 0x002500, 0x00000001);
36213de7f46SBen Skeggs }
36313de7f46SBen Skeggs 
3648c18138cSBen Skeggs int
nv50_fifo_chid_ctor(struct nvkm_fifo * fifo,int nr)365800ac1f8SBen Skeggs nv50_fifo_chid_ctor(struct nvkm_fifo *fifo, int nr)
366800ac1f8SBen Skeggs {
367800ac1f8SBen Skeggs 	/* CHID 0 is unusable (some kind of PIO channel?), 127 is "channel invalid". */
368800ac1f8SBen Skeggs 	return nvkm_chid_new(&nvkm_chan_event, &fifo->engine.subdev, nr, 1, nr - 2, &fifo->chid);
369800ac1f8SBen Skeggs }
370800ac1f8SBen Skeggs 
371800ac1f8SBen Skeggs int
nv50_fifo_chid_nr(struct nvkm_fifo * fifo)3728c18138cSBen Skeggs nv50_fifo_chid_nr(struct nvkm_fifo *fifo)
3738c18138cSBen Skeggs {
3748c18138cSBen Skeggs 	return 128;
3758c18138cSBen Skeggs }
3768c18138cSBen Skeggs 
3778f0649b5SBen Skeggs static const struct nvkm_fifo_func
37813de7f46SBen Skeggs nv50_fifo = {
3798c18138cSBen Skeggs 	.chid_nr = nv50_fifo_chid_nr,
380800ac1f8SBen Skeggs 	.chid_ctor = nv50_fifo_chid_ctor,
381d94470e9SBen Skeggs 	.runl_ctor = nv04_fifo_runl_ctor,
38213de7f46SBen Skeggs 	.init = nv50_fifo_init,
38313de7f46SBen Skeggs 	.intr = nv04_fifo_intr,
38413de7f46SBen Skeggs 	.pause = nv04_fifo_pause,
38513de7f46SBen Skeggs 	.start = nv04_fifo_start,
386d94470e9SBen Skeggs 	.runl = &nv50_runl,
387d94470e9SBen Skeggs 	.engn = &nv50_engn,
388d94470e9SBen Skeggs 	.engn_sw = &nv50_engn_sw,
389f5e45689SBen Skeggs 	.cgrp = {{                           }, &nv04_cgrp },
390*06db7fdeSBen Skeggs 	.chan = {{ 0, 0, NV50_CHANNEL_GPFIFO }, &nv50_chan },
3918f0649b5SBen Skeggs };
3928f0649b5SBen Skeggs 
39313de7f46SBen Skeggs int
nv50_fifo_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_fifo ** pfifo)394ab0db2bdSBen Skeggs nv50_fifo_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
395ab0db2bdSBen Skeggs 	      struct nvkm_fifo **pfifo)
3969a65a38cSBen Skeggs {
397*06db7fdeSBen Skeggs 	return nvkm_fifo_new_(&nv50_fifo, device, type, inst, pfifo);
3989a65a38cSBen Skeggs }
399