1 /*
2  * Copyright 2012 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
23  */
24 #include <engine/sw.h>
25 #include <engine/fifo.h>
26 
27 /*******************************************************************************
28  * software object classes
29  ******************************************************************************/
30 
31 static int
32 nv04_sw_set_ref(struct nvkm_object *object, u32 mthd, void *data, u32 size)
33 {
34 	struct nvkm_object *channel = (void *)nv_engctx(object->parent);
35 	struct nvkm_fifo_chan *fifo = (void *)channel->parent;
36 	atomic_set(&fifo->refcnt, *(u32*)data);
37 	return 0;
38 }
39 
40 static int
41 nv04_sw_flip(struct nvkm_object *object, u32 mthd, void *args, u32 size)
42 {
43 	struct nvkm_sw_chan *chan = (void *)nv_engctx(object->parent);
44 	if (chan->flip)
45 		return chan->flip(chan->flip_data);
46 	return -EINVAL;
47 }
48 
49 static struct nvkm_omthds
50 nv04_sw_omthds[] = {
51 	{ 0x0150, 0x0150, nv04_sw_set_ref },
52 	{ 0x0500, 0x0500, nv04_sw_flip },
53 	{}
54 };
55 
56 static struct nvkm_oclass
57 nv04_sw_sclass[] = {
58 	{ 0x006e, &nvkm_object_ofuncs, nv04_sw_omthds },
59 	{}
60 };
61 
62 /*******************************************************************************
63  * software context
64  ******************************************************************************/
65 
66 static int
67 nv04_sw_context_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
68 		     struct nvkm_oclass *oclass, void *data, u32 size,
69 		     struct nvkm_object **pobject)
70 {
71 	struct nvkm_sw_chan *chan;
72 	int ret;
73 
74 	ret = nvkm_sw_context_create(parent, engine, oclass, &chan);
75 	*pobject = nv_object(chan);
76 	if (ret)
77 		return ret;
78 
79 	return 0;
80 }
81 
82 static struct nvkm_oclass
83 nv04_sw_cclass = {
84 	.handle = NV_ENGCTX(SW, 0x04),
85 	.ofuncs = &(struct nvkm_ofuncs) {
86 		.ctor = nv04_sw_context_ctor,
87 		.dtor = _nvkm_sw_context_dtor,
88 		.init = _nvkm_sw_context_init,
89 		.fini = _nvkm_sw_context_fini,
90 	},
91 };
92 
93 /*******************************************************************************
94  * software engine/subdev functions
95  ******************************************************************************/
96 
97 void
98 nv04_sw_intr(struct nvkm_subdev *subdev)
99 {
100 	nv_mask(subdev, 0x000100, 0x80000000, 0x00000000);
101 }
102 
103 static int
104 nv04_sw_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
105 	     struct nvkm_oclass *oclass, void *data, u32 size,
106 	     struct nvkm_object **pobject)
107 {
108 	struct nvkm_sw *sw;
109 	int ret;
110 
111 	ret = nvkm_sw_create(parent, engine, oclass, &sw);
112 	*pobject = nv_object(sw);
113 	if (ret)
114 		return ret;
115 
116 	nv_engine(sw)->cclass = &nv04_sw_cclass;
117 	nv_engine(sw)->sclass = nv04_sw_sclass;
118 	nv_subdev(sw)->intr = nv04_sw_intr;
119 	return 0;
120 }
121 
122 struct nvkm_oclass *
123 nv04_sw_oclass = &(struct nvkm_oclass) {
124 	.handle = NV_ENGINE(SW, 0x04),
125 	.ofuncs = &(struct nvkm_ofuncs) {
126 		.ctor = nv04_sw_ctor,
127 		.dtor = _nvkm_sw_dtor,
128 		.init = _nvkm_sw_init,
129 		.fini = _nvkm_sw_fini,
130 	},
131 };
132