1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <core/client.h>
26#include <core/os.h>
27#include <core/engctx.h>
28#include <core/handle.h>
29
30#include <subdev/fb.h>
31#include <subdev/timer.h>
32#include <subdev/instmem.h>
33
34#include <engine/fifo.h>
35#include <engine/mpeg.h>
36#include <engine/mpeg/nv31.h>
37
38
39
40
41
42static int
43nv31_mpeg_object_ctor(struct nouveau_object *parent,
44 struct nouveau_object *engine,
45 struct nouveau_oclass *oclass, void *data, u32 size,
46 struct nouveau_object **pobject)
47{
48 struct nouveau_gpuobj *obj;
49 int ret;
50
51 ret = nouveau_gpuobj_create(parent, engine, oclass, 0, parent,
52 20, 16, 0, &obj);
53 *pobject = nv_object(obj);
54 if (ret)
55 return ret;
56
57 nv_wo32(obj, 0x00, nv_mclass(obj));
58 nv_wo32(obj, 0x04, 0x00000000);
59 nv_wo32(obj, 0x08, 0x00000000);
60 nv_wo32(obj, 0x0c, 0x00000000);
61 return 0;
62}
63
64static int
65nv31_mpeg_mthd_dma(struct nouveau_object *object, u32 mthd, void *arg, u32 len)
66{
67 struct nouveau_instmem *imem = nouveau_instmem(object);
68 struct nv31_mpeg_priv *priv = (void *)object->engine;
69 u32 inst = *(u32 *)arg << 4;
70 u32 dma0 = nv_ro32(imem, inst + 0);
71 u32 dma1 = nv_ro32(imem, inst + 4);
72 u32 dma2 = nv_ro32(imem, inst + 8);
73 u32 base = (dma2 & 0xfffff000) | (dma0 >> 20);
74 u32 size = dma1 + 1;
75
76
77 if (!(dma0 & 0x00002000))
78 return -EINVAL;
79
80 if (mthd == 0x0190) {
81
82 nv_mask(priv, 0x00b300, 0x00010000, (dma0 & 0x00030000) ? 0x00010000 : 0);
83 nv_wr32(priv, 0x00b334, base);
84 nv_wr32(priv, 0x00b324, size);
85 } else
86 if (mthd == 0x01a0) {
87
88 nv_mask(priv, 0x00b300, 0x00020000, (dma0 & 0x00030000) ? 0x00020000 : 0);
89 nv_wr32(priv, 0x00b360, base);
90 nv_wr32(priv, 0x00b364, size);
91 } else {
92
93 if (dma0 & 0x00030000)
94 return -EINVAL;
95
96 nv_wr32(priv, 0x00b370, base);
97 nv_wr32(priv, 0x00b374, size);
98 }
99
100 return 0;
101}
102
103struct nouveau_ofuncs
104nv31_mpeg_ofuncs = {
105 .ctor = nv31_mpeg_object_ctor,
106 .dtor = _nouveau_gpuobj_dtor,
107 .init = _nouveau_gpuobj_init,
108 .fini = _nouveau_gpuobj_fini,
109 .rd32 = _nouveau_gpuobj_rd32,
110 .wr32 = _nouveau_gpuobj_wr32,
111};
112
113static struct nouveau_omthds
114nv31_mpeg_omthds[] = {
115 { 0x0190, 0x0190, nv31_mpeg_mthd_dma },
116 { 0x01a0, 0x01a0, nv31_mpeg_mthd_dma },
117 { 0x01b0, 0x01b0, nv31_mpeg_mthd_dma },
118 {}
119};
120
121struct nouveau_oclass
122nv31_mpeg_sclass[] = {
123 { 0x3174, &nv31_mpeg_ofuncs, nv31_mpeg_omthds },
124 {}
125};
126
127
128
129
130
131static int
132nv31_mpeg_context_ctor(struct nouveau_object *parent,
133 struct nouveau_object *engine,
134 struct nouveau_oclass *oclass, void *data, u32 size,
135 struct nouveau_object **pobject)
136{
137 struct nv31_mpeg_priv *priv = (void *)engine;
138 struct nv31_mpeg_chan *chan;
139 unsigned long flags;
140 int ret;
141
142 ret = nouveau_object_create(parent, engine, oclass, 0, &chan);
143 *pobject = nv_object(chan);
144 if (ret)
145 return ret;
146
147 spin_lock_irqsave(&nv_engine(priv)->lock, flags);
148 if (priv->chan) {
149 spin_unlock_irqrestore(&nv_engine(priv)->lock, flags);
150 nouveau_object_destroy(&chan->base);
151 *pobject = NULL;
152 return -EBUSY;
153 }
154 priv->chan = chan;
155 spin_unlock_irqrestore(&nv_engine(priv)->lock, flags);
156 return 0;
157}
158
159static void
160nv31_mpeg_context_dtor(struct nouveau_object *object)
161{
162 struct nv31_mpeg_priv *priv = (void *)object->engine;
163 struct nv31_mpeg_chan *chan = (void *)object;
164 unsigned long flags;
165
166 spin_lock_irqsave(&nv_engine(priv)->lock, flags);
167 priv->chan = NULL;
168 spin_unlock_irqrestore(&nv_engine(priv)->lock, flags);
169 nouveau_object_destroy(&chan->base);
170}
171
172struct nouveau_oclass
173nv31_mpeg_cclass = {
174 .handle = NV_ENGCTX(MPEG, 0x31),
175 .ofuncs = &(struct nouveau_ofuncs) {
176 .ctor = nv31_mpeg_context_ctor,
177 .dtor = nv31_mpeg_context_dtor,
178 .init = nouveau_object_init,
179 .fini = nouveau_object_fini,
180 },
181};
182
183
184
185
186
187void
188nv31_mpeg_tile_prog(struct nouveau_engine *engine, int i)
189{
190 struct nouveau_fb_tile *tile = &nouveau_fb(engine)->tile.region[i];
191 struct nv31_mpeg_priv *priv = (void *)engine;
192
193 nv_wr32(priv, 0x00b008 + (i * 0x10), tile->pitch);
194 nv_wr32(priv, 0x00b004 + (i * 0x10), tile->limit);
195 nv_wr32(priv, 0x00b000 + (i * 0x10), tile->addr);
196}
197
198void
199nv31_mpeg_intr(struct nouveau_subdev *subdev)
200{
201 struct nv31_mpeg_priv *priv = (void *)subdev;
202 struct nouveau_fifo *pfifo = nouveau_fifo(subdev);
203 struct nouveau_handle *handle;
204 struct nouveau_object *engctx;
205 u32 stat = nv_rd32(priv, 0x00b100);
206 u32 type = nv_rd32(priv, 0x00b230);
207 u32 mthd = nv_rd32(priv, 0x00b234);
208 u32 data = nv_rd32(priv, 0x00b238);
209 u32 show = stat;
210 unsigned long flags;
211
212 spin_lock_irqsave(&nv_engine(priv)->lock, flags);
213 engctx = nv_object(priv->chan);
214
215 if (stat & 0x01000000) {
216
217 if (type == 0x00000020 && mthd == 0x0000) {
218 nv_mask(priv, 0x00b308, 0x00000000, 0x00000000);
219 show &= ~0x01000000;
220 }
221
222 if (type == 0x00000010 && engctx) {
223 handle = nouveau_handle_get_class(engctx, 0x3174);
224 if (handle && !nv_call(handle->object, mthd, data))
225 show &= ~0x01000000;
226 nouveau_handle_put(handle);
227 }
228 }
229
230 nv_wr32(priv, 0x00b100, stat);
231 nv_wr32(priv, 0x00b230, 0x00000001);
232
233 if (show) {
234 nv_error(priv, "ch %d [%s] 0x%08x 0x%08x 0x%08x 0x%08x\n",
235 pfifo->chid(pfifo, engctx),
236 nouveau_client_name(engctx), stat, type, mthd, data);
237 }
238
239 spin_unlock_irqrestore(&nv_engine(priv)->lock, flags);
240}
241
242static int
243nv31_mpeg_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
244 struct nouveau_oclass *oclass, void *data, u32 size,
245 struct nouveau_object **pobject)
246{
247 struct nv31_mpeg_priv *priv;
248 int ret;
249
250 ret = nouveau_mpeg_create(parent, engine, oclass, &priv);
251 *pobject = nv_object(priv);
252 if (ret)
253 return ret;
254
255 nv_subdev(priv)->unit = 0x00000002;
256 nv_subdev(priv)->intr = nv31_mpeg_intr;
257 nv_engine(priv)->cclass = &nv31_mpeg_cclass;
258 nv_engine(priv)->sclass = nv31_mpeg_sclass;
259 nv_engine(priv)->tile_prog = nv31_mpeg_tile_prog;
260 return 0;
261}
262
263int
264nv31_mpeg_init(struct nouveau_object *object)
265{
266 struct nouveau_engine *engine = nv_engine(object);
267 struct nv31_mpeg_priv *priv = (void *)object;
268 struct nouveau_fb *pfb = nouveau_fb(object);
269 int ret, i;
270
271 ret = nouveau_mpeg_init(&priv->base);
272 if (ret)
273 return ret;
274
275
276 nv_wr32(priv, 0x00b0e0, 0x00000020);
277 nv_wr32(priv, 0x00b0e8, 0x00000020);
278
279 for (i = 0; i < pfb->tile.regions; i++)
280 engine->tile_prog(engine, i);
281
282
283 nv_wr32(priv, 0x00b32c, 0x00000000);
284 nv_wr32(priv, 0x00b314, 0x00000100);
285 nv_wr32(priv, 0x00b220, 0x00000031);
286 nv_wr32(priv, 0x00b300, 0x02001ec1);
287 nv_mask(priv, 0x00b32c, 0x00000001, 0x00000001);
288
289 nv_wr32(priv, 0x00b100, 0xffffffff);
290 nv_wr32(priv, 0x00b140, 0xffffffff);
291
292 if (!nv_wait(priv, 0x00b200, 0x00000001, 0x00000000)) {
293 nv_error(priv, "timeout 0x%08x\n", nv_rd32(priv, 0x00b200));
294 return -EBUSY;
295 }
296
297 return 0;
298}
299
300struct nouveau_oclass
301nv31_mpeg_oclass = {
302 .handle = NV_ENGINE(MPEG, 0x31),
303 .ofuncs = &(struct nouveau_ofuncs) {
304 .ctor = nv31_mpeg_ctor,
305 .dtor = _nouveau_mpeg_dtor,
306 .init = nv31_mpeg_init,
307 .fini = _nouveau_mpeg_fini,
308 },
309};
310