xref: /linux/drivers/gpu/drm/nouveau/nvkm/engine/mpeg/nv50.c (revision 4de93a086eb0315f0bd8e1d6da40186842670b57)
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/mpeg.h>
25 
26 #include <subdev/bar.h>
27 #include <subdev/timer.h>
28 
29 struct nv50_mpeg_chan {
30 	struct nvkm_mpeg_chan base;
31 };
32 
33 /*******************************************************************************
34  * MPEG object classes
35  ******************************************************************************/
36 
37 static int
38 nv50_mpeg_object_ctor(struct nvkm_object *parent,
39 		      struct nvkm_object *engine,
40 		      struct nvkm_oclass *oclass, void *data, u32 size,
41 		      struct nvkm_object **pobject)
42 {
43 	struct nvkm_gpuobj *obj;
44 	int ret;
45 
46 	ret = nvkm_gpuobj_create(parent, engine, oclass, 0, parent,
47 				 16, 16, 0, &obj);
48 	*pobject = nv_object(obj);
49 	if (ret)
50 		return ret;
51 
52 	nv_wo32(obj, 0x00, nv_mclass(obj));
53 	nv_wo32(obj, 0x04, 0x00000000);
54 	nv_wo32(obj, 0x08, 0x00000000);
55 	nv_wo32(obj, 0x0c, 0x00000000);
56 	return 0;
57 }
58 
59 struct nvkm_ofuncs
60 nv50_mpeg_ofuncs = {
61 	.ctor = nv50_mpeg_object_ctor,
62 	.dtor = _nvkm_gpuobj_dtor,
63 	.init = _nvkm_gpuobj_init,
64 	.fini = _nvkm_gpuobj_fini,
65 	.rd32 = _nvkm_gpuobj_rd32,
66 	.wr32 = _nvkm_gpuobj_wr32,
67 };
68 
69 static struct nvkm_oclass
70 nv50_mpeg_sclass[] = {
71 	{ 0x3174, &nv50_mpeg_ofuncs },
72 	{}
73 };
74 
75 /*******************************************************************************
76  * PMPEG context
77  ******************************************************************************/
78 
79 int
80 nv50_mpeg_context_ctor(struct nvkm_object *parent,
81 		       struct nvkm_object *engine,
82 		       struct nvkm_oclass *oclass, void *data, u32 size,
83 		       struct nvkm_object **pobject)
84 {
85 	struct nvkm_bar *bar = nvkm_bar(parent);
86 	struct nv50_mpeg_chan *chan;
87 	int ret;
88 
89 	ret = nvkm_mpeg_context_create(parent, engine, oclass, NULL, 128 * 4,
90 				       0, NVOBJ_FLAG_ZERO_ALLOC, &chan);
91 	*pobject = nv_object(chan);
92 	if (ret)
93 		return ret;
94 
95 	nv_wo32(chan, 0x0070, 0x00801ec1);
96 	nv_wo32(chan, 0x007c, 0x0000037c);
97 	bar->flush(bar);
98 	return 0;
99 }
100 
101 static struct nvkm_oclass
102 nv50_mpeg_cclass = {
103 	.handle = NV_ENGCTX(MPEG, 0x50),
104 	.ofuncs = &(struct nvkm_ofuncs) {
105 		.ctor = nv50_mpeg_context_ctor,
106 		.dtor = _nvkm_mpeg_context_dtor,
107 		.init = _nvkm_mpeg_context_init,
108 		.fini = _nvkm_mpeg_context_fini,
109 		.rd32 = _nvkm_mpeg_context_rd32,
110 		.wr32 = _nvkm_mpeg_context_wr32,
111 	},
112 };
113 
114 /*******************************************************************************
115  * PMPEG engine/subdev functions
116  ******************************************************************************/
117 
118 void
119 nv50_mpeg_intr(struct nvkm_subdev *subdev)
120 {
121 	struct nvkm_mpeg *mpeg = (void *)subdev;
122 	u32 stat = nv_rd32(mpeg, 0x00b100);
123 	u32 type = nv_rd32(mpeg, 0x00b230);
124 	u32 mthd = nv_rd32(mpeg, 0x00b234);
125 	u32 data = nv_rd32(mpeg, 0x00b238);
126 	u32 show = stat;
127 
128 	if (stat & 0x01000000) {
129 		/* happens on initial binding of the object */
130 		if (type == 0x00000020 && mthd == 0x0000) {
131 			nv_wr32(mpeg, 0x00b308, 0x00000100);
132 			show &= ~0x01000000;
133 		}
134 	}
135 
136 	if (show) {
137 		nv_info(mpeg, "0x%08x 0x%08x 0x%08x 0x%08x\n",
138 			stat, type, mthd, data);
139 	}
140 
141 	nv_wr32(mpeg, 0x00b100, stat);
142 	nv_wr32(mpeg, 0x00b230, 0x00000001);
143 }
144 
145 static void
146 nv50_vpe_intr(struct nvkm_subdev *subdev)
147 {
148 	struct nvkm_mpeg *mpeg = (void *)subdev;
149 
150 	if (nv_rd32(mpeg, 0x00b100))
151 		nv50_mpeg_intr(subdev);
152 
153 	if (nv_rd32(mpeg, 0x00b800)) {
154 		u32 stat = nv_rd32(mpeg, 0x00b800);
155 		nv_info(mpeg, "PMSRCH: 0x%08x\n", stat);
156 		nv_wr32(mpeg, 0xb800, stat);
157 	}
158 }
159 
160 static int
161 nv50_mpeg_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
162 	       struct nvkm_oclass *oclass, void *data, u32 size,
163 	       struct nvkm_object **pobject)
164 {
165 	struct nvkm_mpeg *mpeg;
166 	int ret;
167 
168 	ret = nvkm_mpeg_create(parent, engine, oclass, &mpeg);
169 	*pobject = nv_object(mpeg);
170 	if (ret)
171 		return ret;
172 
173 	nv_subdev(mpeg)->unit = 0x00400002;
174 	nv_subdev(mpeg)->intr = nv50_vpe_intr;
175 	nv_engine(mpeg)->cclass = &nv50_mpeg_cclass;
176 	nv_engine(mpeg)->sclass = nv50_mpeg_sclass;
177 	return 0;
178 }
179 
180 int
181 nv50_mpeg_init(struct nvkm_object *object)
182 {
183 	struct nvkm_mpeg *mpeg = (void *)object;
184 	int ret;
185 
186 	ret = nvkm_mpeg_init(mpeg);
187 	if (ret)
188 		return ret;
189 
190 	nv_wr32(mpeg, 0x00b32c, 0x00000000);
191 	nv_wr32(mpeg, 0x00b314, 0x00000100);
192 	nv_wr32(mpeg, 0x00b0e0, 0x0000001a);
193 
194 	nv_wr32(mpeg, 0x00b220, 0x00000044);
195 	nv_wr32(mpeg, 0x00b300, 0x00801ec1);
196 	nv_wr32(mpeg, 0x00b390, 0x00000000);
197 	nv_wr32(mpeg, 0x00b394, 0x00000000);
198 	nv_wr32(mpeg, 0x00b398, 0x00000000);
199 	nv_mask(mpeg, 0x00b32c, 0x00000001, 0x00000001);
200 
201 	nv_wr32(mpeg, 0x00b100, 0xffffffff);
202 	nv_wr32(mpeg, 0x00b140, 0xffffffff);
203 
204 	if (!nv_wait(mpeg, 0x00b200, 0x00000001, 0x00000000)) {
205 		nv_error(mpeg, "timeout 0x%08x\n", nv_rd32(mpeg, 0x00b200));
206 		return -EBUSY;
207 	}
208 
209 	return 0;
210 }
211 
212 struct nvkm_oclass
213 nv50_mpeg_oclass = {
214 	.handle = NV_ENGINE(MPEG, 0x50),
215 	.ofuncs = &(struct nvkm_ofuncs) {
216 		.ctor = nv50_mpeg_ctor,
217 		.dtor = _nvkm_mpeg_dtor,
218 		.init = nv50_mpeg_init,
219 		.fini = _nvkm_mpeg_fini,
220 	},
221 };
222