Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nv31.c
Go to the documentation of this file.
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 
25 #include <core/os.h>
26 #include <core/class.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/graph/nv40.h>
37 
41 };
42 
45 };
46 
47 /*******************************************************************************
48  * MPEG object classes
49  ******************************************************************************/
50 
51 static int
52 nv31_mpeg_object_ctor(struct nouveau_object *parent,
53  struct nouveau_object *engine,
54  struct nouveau_oclass *oclass, void *data, u32 size,
55  struct nouveau_object **pobject)
56 {
57  struct nouveau_gpuobj *obj;
58  int ret;
59 
60  ret = nouveau_gpuobj_create(parent, engine, oclass, 0, parent,
61  20, 16, 0, &obj);
62  *pobject = nv_object(obj);
63  if (ret)
64  return ret;
65 
66  nv_wo32(obj, 0x00, nv_mclass(obj));
67  nv_wo32(obj, 0x04, 0x00000000);
68  nv_wo32(obj, 0x08, 0x00000000);
69  nv_wo32(obj, 0x0c, 0x00000000);
70  return 0;
71 }
72 
73 static int
74 nv31_mpeg_mthd_dma(struct nouveau_object *object, u32 mthd, void *arg, u32 len)
75 {
76  struct nouveau_instmem *imem = nouveau_instmem(object);
77  struct nv31_mpeg_priv *priv = (void *)object->engine;
78  u32 inst = *(u32 *)arg << 4;
79  u32 dma0 = nv_ro32(imem, inst + 0);
80  u32 dma1 = nv_ro32(imem, inst + 4);
81  u32 dma2 = nv_ro32(imem, inst + 8);
82  u32 base = (dma2 & 0xfffff000) | (dma0 >> 20);
83  u32 size = dma1 + 1;
84 
85  /* only allow linear DMA objects */
86  if (!(dma0 & 0x00002000))
87  return -EINVAL;
88 
89  if (mthd == 0x0190) {
90  /* DMA_CMD */
91  nv_mask(priv, 0x00b300, 0x00030000, (dma0 & 0x00030000));
92  nv_wr32(priv, 0x00b334, base);
93  nv_wr32(priv, 0x00b324, size);
94  } else
95  if (mthd == 0x01a0) {
96  /* DMA_DATA */
97  nv_mask(priv, 0x00b300, 0x000c0000, (dma0 & 0x00030000) << 2);
98  nv_wr32(priv, 0x00b360, base);
99  nv_wr32(priv, 0x00b364, size);
100  } else {
101  /* DMA_IMAGE, VRAM only */
102  if (dma0 & 0x000c0000)
103  return -EINVAL;
104 
105  nv_wr32(priv, 0x00b370, base);
106  nv_wr32(priv, 0x00b374, size);
107  }
108 
109  return 0;
110 }
111 
112 static struct nouveau_ofuncs
113 nv31_mpeg_ofuncs = {
114  .ctor = nv31_mpeg_object_ctor,
115  .dtor = _nouveau_gpuobj_dtor,
116  .init = _nouveau_gpuobj_init,
117  .fini = _nouveau_gpuobj_fini,
118  .rd32 = _nouveau_gpuobj_rd32,
119  .wr32 = _nouveau_gpuobj_wr32,
120 };
121 
122 static struct nouveau_omthds
123 nv31_mpeg_omthds[] = {
124  { 0x0190, nv31_mpeg_mthd_dma },
125  { 0x01a0, nv31_mpeg_mthd_dma },
126  { 0x01b0, nv31_mpeg_mthd_dma },
127  {}
128 };
129 
130 struct nouveau_oclass
132  { 0x3174, &nv31_mpeg_ofuncs, nv31_mpeg_omthds },
133  {}
134 };
135 
136 /*******************************************************************************
137  * PMPEG context
138  ******************************************************************************/
139 
140 static int
141 nv31_mpeg_context_ctor(struct nouveau_object *parent,
142  struct nouveau_object *engine,
143  struct nouveau_oclass *oclass, void *data, u32 size,
144  struct nouveau_object **pobject)
145 {
146  struct nv31_mpeg_priv *priv = (void *)engine;
147  struct nv31_mpeg_chan *chan;
148  int ret;
149 
150  if (!atomic_add_unless(&priv->refcount, 1, 1))
151  return -EBUSY;
152 
153  ret = nouveau_object_create(parent, engine, oclass, 0, &chan);
154  *pobject = nv_object(chan);
155  if (ret)
156  return ret;
157 
158  return 0;
159 }
160 
161 static void
162 nv31_mpeg_context_dtor(struct nouveau_object *object)
163 {
164  struct nv31_mpeg_priv *priv = (void *)object->engine;
165  struct nv31_mpeg_chan *chan = (void *)object;
166  atomic_dec(&priv->refcount);
168 }
169 
170 static struct nouveau_oclass
171 nv31_mpeg_cclass = {
172  .handle = NV_ENGCTX(MPEG, 0x31),
173  .ofuncs = &(struct nouveau_ofuncs) {
174  .ctor = nv31_mpeg_context_ctor,
175  .dtor = nv31_mpeg_context_dtor,
176  .init = nouveau_object_init,
177  .fini = nouveau_object_fini,
178  },
179 };
180 
181 /*******************************************************************************
182  * PMPEG engine/subdev functions
183  ******************************************************************************/
184 
185 void
187 {
188  struct nouveau_fb_tile *tile = &nouveau_fb(engine)->tile.region[i];
189  struct nv31_mpeg_priv *priv = (void *)engine;
190 
191  nv_wr32(priv, 0x00b008 + (i * 0x10), tile->pitch);
192  nv_wr32(priv, 0x00b004 + (i * 0x10), tile->limit);
193  nv_wr32(priv, 0x00b000 + (i * 0x10), tile->addr);
194 }
195 
196 void
198 {
199  struct nouveau_fifo *pfifo = nouveau_fifo(subdev);
200  struct nouveau_engine *engine = nv_engine(subdev);
201  struct nouveau_object *engctx;
202  struct nouveau_handle *handle;
203  struct nv31_mpeg_priv *priv = (void *)subdev;
204  u32 inst = nv_rd32(priv, 0x00b318) & 0x000fffff;
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  int chid;
211 
212  engctx = nouveau_engctx_get(engine, inst);
213  chid = pfifo->chid(pfifo, engctx);
214 
215  if (stat & 0x01000000) {
216  /* happens on initial binding of the object */
217  if (type == 0x00000020 && mthd == 0x0000) {
218  nv_mask(priv, 0x00b308, 0x00000000, 0x00000000);
219  show &= ~0x01000000;
220  }
221 
222  if (type == 0x00000010) {
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 [0x%08x] 0x%08x 0x%08x 0x%08x 0x%08x\n",
235  chid, inst << 4, stat, type, mthd, data);
236  }
237 
238  nouveau_engctx_put(engctx);
239 }
240 
241 static int
242 nv31_mpeg_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
243  struct nouveau_oclass *oclass, void *data, u32 size,
244  struct nouveau_object **pobject)
245 {
246  struct nv31_mpeg_priv *priv;
247  int ret;
248 
249  ret = nouveau_mpeg_create(parent, engine, oclass, &priv);
250  *pobject = nv_object(priv);
251  if (ret)
252  return ret;
253 
254  nv_subdev(priv)->unit = 0x00000002;
255  nv_subdev(priv)->intr = nv31_mpeg_intr;
256  nv_engine(priv)->cclass = &nv31_mpeg_cclass;
257  nv_engine(priv)->sclass = nv31_mpeg_sclass;
258  nv_engine(priv)->tile_prog = nv31_mpeg_tile_prog;
259  return 0;
260 }
261 
262 int
264 {
265  struct nouveau_engine *engine = nv_engine(object->engine);
266  struct nv31_mpeg_priv *priv = (void *)engine;
267  struct nouveau_fb *pfb = nouveau_fb(object);
268  int ret, i;
269 
270  ret = nouveau_mpeg_init(&priv->base);
271  if (ret)
272  return ret;
273 
274  /* VPE init */
275  nv_wr32(priv, 0x00b0e0, 0x00000020); /* nvidia: rd 0x01, wr 0x20 */
276  nv_wr32(priv, 0x00b0e8, 0x00000020); /* nvidia: rd 0x01, wr 0x20 */
277 
278  for (i = 0; i < pfb->tile.regions; i++)
279  engine->tile_prog(engine, i);
280 
281  /* PMPEG init */
282  nv_wr32(priv, 0x00b32c, 0x00000000);
283  nv_wr32(priv, 0x00b314, 0x00000100);
284  nv_wr32(priv, 0x00b220, nv44_graph_class(priv) ? 0x00000044 : 0x00000031);
285  nv_wr32(priv, 0x00b300, 0x02001ec1);
286  nv_mask(priv, 0x00b32c, 0x00000001, 0x00000001);
287 
288  nv_wr32(priv, 0x00b100, 0xffffffff);
289  nv_wr32(priv, 0x00b140, 0xffffffff);
290 
291  if (!nv_wait(priv, 0x00b200, 0x00000001, 0x00000000)) {
292  nv_error(priv, "timeout 0x%08x\n", nv_rd32(priv, 0x00b200));
293  return -EBUSY;
294  }
295 
296  return 0;
297 }
298 
299 struct nouveau_oclass
301  .handle = NV_ENGINE(MPEG, 0x31),
302  .ofuncs = &(struct nouveau_ofuncs) {
303  .ctor = nv31_mpeg_ctor,
304  .dtor = _nouveau_mpeg_dtor,
305  .init = nv31_mpeg_init,
306  .fini = _nouveau_mpeg_fini,
307  },
308 };