1 /*
2  * Copyright 2018 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/gpuobj.h>
25 #include <core/object.h>
26 
27 #include <nvif/class.h>
28 
29 static int
30 gv100_ce_cclass_bind(struct nvkm_object *object, struct nvkm_gpuobj *parent, int align,
31 		     struct nvkm_gpuobj **pgpuobj)
32 {
33 	struct nvkm_device *device = object->engine->subdev.device;
34 	u32 size;
35 
36 	/* Allocate fault method buffer (magics come from nvgpu). */
37 	size = nvkm_rd32(device, 0x104028); /* NV_PCE_PCE_MAP */
38 	size = 27 * 5 * (((9 + 1 + 3) * hweight32(size)) + 2);
39 	size = roundup(size, PAGE_SIZE);
40 
41 	return nvkm_gpuobj_new(device, size, align, true, parent, pgpuobj);
42 }
43 
44 const struct nvkm_object_func
45 gv100_ce_cclass = {
46 	.bind = gv100_ce_cclass_bind,
47 };
48 
49 static const struct nvkm_engine_func
50 gv100_ce = {
51 	.intr = gp100_ce_intr,
52 	.cclass = &gv100_ce_cclass,
53 	.sclass = {
54 		{ -1, -1, VOLTA_DMA_COPY_A },
55 		{}
56 	}
57 };
58 
59 int
60 gv100_ce_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
61 	     struct nvkm_engine **pengine)
62 {
63 	return nvkm_engine_new_(&gv100_ce, device, type, inst, true, pengine);
64 }
65