1/* $NetBSD: nouveau_nvkm_engine_fifo_gpfifog84.c,v 1.3 2021/12/18 23:45:35 riastradh Exp $ */ 2 3/* 4 * Copyright 2012 Red Hat Inc. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE. 23 * 24 * Authors: Ben Skeggs 25 */ 26#include <sys/cdefs.h> 27__KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_engine_fifo_gpfifog84.c,v 1.3 2021/12/18 23:45:35 riastradh Exp $"); 28 29#include "channv50.h" 30 31#include <core/client.h> 32#include <core/ramht.h> 33 34#include <nvif/class.h> 35#include <nvif/cl826f.h> 36#include <nvif/unpack.h> 37 38static int 39g84_fifo_gpfifo_new(struct nvkm_fifo *base, const struct nvkm_oclass *oclass, 40 void *data, u32 size, struct nvkm_object **pobject) 41{ 42 struct nvkm_object *parent = oclass->parent; 43 union { 44 struct g82_channel_gpfifo_v0 v0; 45 } *args = data; 46 struct nv50_fifo *fifo = nv50_fifo(base); 47 struct nv50_fifo_chan *chan; 48 u64 ioffset, ilength; 49 int ret = -ENOSYS; 50 51 nvif_ioctl(parent, "create channel gpfifo size %d\n", size); 52 if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) { 53 nvif_ioctl(parent, "create channel gpfifo vers %d vmm %"PRIx64" " 54 "pushbuf %"PRIx64" ioffset %016"PRIx64" " 55 "ilength %08x\n", 56 args->v0.version, args->v0.vmm, args->v0.pushbuf, 57 args->v0.ioffset, args->v0.ilength); 58 if (!args->v0.pushbuf) 59 return -EINVAL; 60 } else 61 return ret; 62 63 if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL))) 64 return -ENOMEM; 65 *pobject = &chan->base.object; 66 67 ret = g84_fifo_chan_ctor(fifo, args->v0.vmm, args->v0.pushbuf, 68 oclass, chan); 69 if (ret) 70 return ret; 71 72 args->v0.chid = chan->base.chid; 73 ioffset = args->v0.ioffset; 74 ilength = order_base_2(args->v0.ilength / 8); 75 76 nvkm_kmap(chan->ramfc); 77 nvkm_wo32(chan->ramfc, 0x3c, 0x403f6078); 78 nvkm_wo32(chan->ramfc, 0x44, 0x01003fff); 79 nvkm_wo32(chan->ramfc, 0x48, chan->base.push->node->offset >> 4); 80 nvkm_wo32(chan->ramfc, 0x50, lower_32_bits(ioffset)); 81 nvkm_wo32(chan->ramfc, 0x54, upper_32_bits(ioffset) | (ilength << 16)); 82 nvkm_wo32(chan->ramfc, 0x60, 0x7fffffff); 83 nvkm_wo32(chan->ramfc, 0x78, 0x00000000); 84 nvkm_wo32(chan->ramfc, 0x7c, 0x30000001); 85 nvkm_wo32(chan->ramfc, 0x80, ((chan->ramht->bits - 9) << 27) | 86 (4 << 24) /* SEARCH_FULL */ | 87 (chan->ramht->gpuobj->node->offset >> 4)); 88 nvkm_wo32(chan->ramfc, 0x88, chan->cache->addr >> 10); 89 nvkm_wo32(chan->ramfc, 0x98, chan->base.inst->addr >> 12); 90 nvkm_done(chan->ramfc); 91 return 0; 92} 93 94const struct nvkm_fifo_chan_oclass 95g84_fifo_gpfifo_oclass = { 96 .base.oclass = G82_CHANNEL_GPFIFO, 97 .base.minver = 0, 98 .base.maxver = 0, 99 .ctor = g84_fifo_gpfifo_new, 100}; 101