xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/engine/fifo/nouveau_nvkm_engine_fifo_gpfifotu102.c (revision 7649e88fcfe6a7c92de68bd5e592dec3e35224fb)
1 /*	$NetBSD: nouveau_nvkm_engine_fifo_gpfifotu102.c,v 1.3 2021/12/19 10:51:57 riastradh Exp $	*/
2 
3 /*
4  * Copyright 2018 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 #include <sys/cdefs.h>
25 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_engine_fifo_gpfifotu102.c,v 1.3 2021/12/19 10:51:57 riastradh Exp $");
26 
27 #include "changk104.h"
28 #include "cgrp.h"
29 
30 #include <core/client.h>
31 #include <core/gpuobj.h>
32 
33 #include <nvif/clc36f.h>
34 #include <nvif/unpack.h>
35 
36 static u32
tu102_fifo_gpfifo_submit_token(struct nvkm_fifo_chan * base)37 tu102_fifo_gpfifo_submit_token(struct nvkm_fifo_chan *base)
38 {
39 	struct gk104_fifo_chan *chan = gk104_fifo_chan(base);
40 	return (chan->runl << 16) | chan->base.chid;
41 }
42 
43 static const struct nvkm_fifo_chan_func
44 tu102_fifo_gpfifo = {
45 	.dtor = gk104_fifo_gpfifo_dtor,
46 	.init = gk104_fifo_gpfifo_init,
47 	.fini = gk104_fifo_gpfifo_fini,
48 	.ntfy = gf100_fifo_chan_ntfy,
49 	.engine_ctor = gk104_fifo_gpfifo_engine_ctor,
50 	.engine_dtor = gk104_fifo_gpfifo_engine_dtor,
51 	.engine_init = gv100_fifo_gpfifo_engine_init,
52 	.engine_fini = gv100_fifo_gpfifo_engine_fini,
53 	.submit_token = tu102_fifo_gpfifo_submit_token,
54 };
55 
56 int
tu102_fifo_gpfifo_new(struct gk104_fifo * fifo,const struct nvkm_oclass * oclass,void * data,u32 size,struct nvkm_object ** pobject)57 tu102_fifo_gpfifo_new(struct gk104_fifo *fifo, const struct nvkm_oclass *oclass,
58 		      void *data, u32 size, struct nvkm_object **pobject)
59 {
60 	struct nvkm_object *parent = oclass->parent;
61 	union {
62 		struct volta_channel_gpfifo_a_v0 v0;
63 	} *args = data;
64 	int ret = -ENOSYS;
65 
66 	nvif_ioctl(parent, "create channel gpfifo size %d\n", size);
67 	if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
68 		nvif_ioctl(parent, "create channel gpfifo vers %d vmm %"PRIx64" "
69 				   "ioffset %016"PRIx64" ilength %08x "
70 				   "runlist %016"PRIx64" priv %d\n",
71 			   args->v0.version, args->v0.vmm, args->v0.ioffset,
72 			   args->v0.ilength, args->v0.runlist, args->v0.priv);
73 		if (args->v0.priv && !oclass->client->super)
74 			return -EINVAL;
75 		return gv100_fifo_gpfifo_new_(&tu102_fifo_gpfifo, fifo,
76 					      &args->v0.runlist,
77 					      &args->v0.chid,
78 					       args->v0.vmm,
79 					       args->v0.ioffset,
80 					       args->v0.ilength,
81 					      &args->v0.inst,
82 					       args->v0.priv,
83 					      &args->v0.token,
84 					      oclass, pobject);
85 	}
86 
87 	return ret;
88 }
89