1 /*
2  * Copyright 2015 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  * Authors: Ben Skeggs <bskeggs@redhat.com>
23  */
24 #define nvkm_nvsw(p) container_of((p), struct nvkm_nvsw, object)
25 #include "nvsw.h"
26 #include "chan.h"
27 
28 #include <nvif/class.h>
29 
30 struct nvkm_nvsw {
31 	struct nvkm_object object;
32 	struct nvkm_sw_chan *chan;
33 };
34 
35 static int
36 nvkm_nvsw_ntfy(struct nvkm_object *base, u32 mthd, struct nvkm_event **pevent)
37 {
38 	struct nvkm_nvsw *nvsw = nvkm_nvsw(base);
39 	switch (mthd) {
40 	case NVSW_NTFY_UEVENT:
41 		*pevent = &nvsw->chan->event;
42 		return 0;
43 	default:
44 		break;
45 	}
46 	return -EINVAL;
47 }
48 
49 int
50 nvkm_nvsw_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
51 	       struct nvkm_oclass *oclass, void *data, u32 size,
52 	       struct nvkm_object **pobject)
53 {
54 	struct nvkm_sw_chan *chan = (void *)parent;
55 	struct nvkm_nvsw *nvsw;
56 	int ret;
57 
58 	ret = nvkm_object_create(parent, engine, oclass, 0, &nvsw);
59 	*pobject = &nvsw->object;
60 	if (ret)
61 		return ret;
62 
63 	nvsw->chan = chan;
64 	return 0;
65 }
66 
67 struct nvkm_ofuncs
68 nvkm_nvsw_ofuncs = {
69 	.ctor = nvkm_nvsw_ctor,
70 	.dtor = nvkm_object_destroy,
71 	.init = _nvkm_object_init,
72 	.fini = _nvkm_object_fini,
73 	.ntfy = nvkm_nvsw_ntfy,
74 };
75