xref: /linux/drivers/gpu/drm/nouveau/nvkm/engine/ce/r535.c (revision ab1c247094e323177a578b38f0325bf79f0317ac)
1 /*
2  * Copyright 2023 Red Hat Inc.
3  *
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:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
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.
21  */
22 #include "priv.h"
23 
24 #include <core/object.h>
25 #include <subdev/gsp.h>
26 #include <engine/fifo.h>
27 
28 #include <nvrm/nvtypes.h>
29 #include <nvrm/535.113.01/common/sdk/nvidia/inc/class/cl2080_notification.h>
30 #include <nvrm/535.113.01/common/sdk/nvidia/inc/class/clc0b5sw.h>
31 
32 struct r535_ce_obj {
33 	struct nvkm_object object;
34 	struct nvkm_gsp_object rm;
35 };
36 
37 static void *
38 r535_ce_obj_dtor(struct nvkm_object *object)
39 {
40 	struct r535_ce_obj *obj = container_of(object, typeof(*obj), object);
41 
42 	nvkm_gsp_rm_free(&obj->rm);
43 	return obj;
44 }
45 
46 static const struct nvkm_object_func
47 r535_ce_obj = {
48 	.dtor = r535_ce_obj_dtor,
49 };
50 
51 static int
52 r535_ce_obj_ctor(const struct nvkm_oclass *oclass, void *argv, u32 argc,
53 		 struct nvkm_object **pobject)
54 {
55 	struct nvkm_chan *chan = nvkm_uchan_chan(oclass->parent);
56 	struct r535_ce_obj *obj;
57 	NVC0B5_ALLOCATION_PARAMETERS *args;
58 
59 	if (!(obj = kzalloc(sizeof(*obj), GFP_KERNEL)))
60 		return -ENOMEM;
61 
62 	nvkm_object_ctor(&r535_ce_obj, oclass, &obj->object);
63 	*pobject = &obj->object;
64 
65 	args = nvkm_gsp_rm_alloc_get(&chan->rm.object, oclass->handle, oclass->base.oclass,
66 				     sizeof(*args), &obj->rm);
67 	if (WARN_ON(IS_ERR(args)))
68 		return PTR_ERR(args);
69 
70 	args->version = 1;
71 	args->engineType = NV2080_ENGINE_TYPE_COPY0 + oclass->engine->subdev.inst;
72 
73 	return nvkm_gsp_rm_alloc_wr(&obj->rm, args);
74 }
75 
76 static void *
77 r535_ce_dtor(struct nvkm_engine *engine)
78 {
79 	kfree(engine->func);
80 	return engine;
81 }
82 
83 int
84 r535_ce_new(const struct nvkm_engine_func *hw, struct nvkm_device *device,
85 	    enum nvkm_subdev_type type, int inst, struct nvkm_engine **pengine)
86 {
87 	struct nvkm_engine_func *rm;
88 	int nclass, ret;
89 
90 	for (nclass = 0; hw->sclass[nclass].oclass; nclass++);
91 
92 	if (!(rm = kzalloc(sizeof(*rm) + (nclass + 1) * sizeof(rm->sclass[0]), GFP_KERNEL)))
93 		return -ENOMEM;
94 
95 	rm->dtor = r535_ce_dtor;
96 	for (int i = 0; i < nclass; i++) {
97 		rm->sclass[i].minver = hw->sclass[i].minver;
98 		rm->sclass[i].maxver = hw->sclass[i].maxver;
99 		rm->sclass[i].oclass = hw->sclass[i].oclass;
100 		rm->sclass[i].ctor = r535_ce_obj_ctor;
101 	}
102 
103 	ret = nvkm_engine_new_(rm, device, type, inst, true, pengine);
104 	if (ret)
105 		kfree(rm);
106 
107 	return ret;
108 }
109