Linux-libre 3.16.85-gnu
[librecmc/linux-libre.git] / drivers / gpu / drm / nouveau / core / engine / mpeg / nv44.c
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/client.h>
28 #include <core/engctx.h>
29 #include <core/handle.h>
30
31 #include <subdev/fb.h>
32 #include <subdev/timer.h>
33 #include <subdev/instmem.h>
34
35 #include <engine/fifo.h>
36 #include <engine/mpeg.h>
37
38 struct nv44_mpeg_priv {
39         struct nouveau_mpeg base;
40 };
41
42 struct nv44_mpeg_chan {
43         struct nouveau_mpeg_chan base;
44 };
45
46 /*******************************************************************************
47  * PMPEG context
48  ******************************************************************************/
49
50 static int
51 nv44_mpeg_context_ctor(struct nouveau_object *parent,
52                        struct nouveau_object *engine,
53                        struct nouveau_oclass *oclass, void *data, u32 size,
54                        struct nouveau_object **pobject)
55 {
56         struct nv44_mpeg_chan *chan;
57         int ret;
58
59         ret = nouveau_mpeg_context_create(parent, engine, oclass, NULL,
60                                           264 * 4, 16,
61                                           NVOBJ_FLAG_ZERO_ALLOC, &chan);
62         *pobject = nv_object(chan);
63         if (ret)
64                 return ret;
65
66         nv_wo32(&chan->base.base, 0x78, 0x02001ec1);
67         return 0;
68 }
69
70 static int
71 nv44_mpeg_context_fini(struct nouveau_object *object, bool suspend)
72 {
73
74         struct nv44_mpeg_priv *priv = (void *)object->engine;
75         struct nv44_mpeg_chan *chan = (void *)object;
76         u32 inst = 0x80000000 | nv_gpuobj(chan)->addr >> 4;
77
78         nv_mask(priv, 0x00b32c, 0x00000001, 0x00000000);
79         if (nv_rd32(priv, 0x00b318) == inst)
80                 nv_mask(priv, 0x00b318, 0x80000000, 0x00000000);
81         nv_mask(priv, 0x00b32c, 0x00000001, 0x00000001);
82         return 0;
83 }
84
85 static struct nouveau_oclass
86 nv44_mpeg_cclass = {
87         .handle = NV_ENGCTX(MPEG, 0x44),
88         .ofuncs = &(struct nouveau_ofuncs) {
89                 .ctor = nv44_mpeg_context_ctor,
90                 .dtor = _nouveau_mpeg_context_dtor,
91                 .init = _nouveau_mpeg_context_init,
92                 .fini = nv44_mpeg_context_fini,
93                 .rd32 = _nouveau_mpeg_context_rd32,
94                 .wr32 = _nouveau_mpeg_context_wr32,
95         },
96 };
97
98 /*******************************************************************************
99  * PMPEG engine/subdev functions
100  ******************************************************************************/
101
102 static void
103 nv44_mpeg_intr(struct nouveau_subdev *subdev)
104 {
105         struct nouveau_fifo *pfifo = nouveau_fifo(subdev);
106         struct nouveau_engine *engine = nv_engine(subdev);
107         struct nouveau_object *engctx;
108         struct nouveau_handle *handle;
109         struct nv44_mpeg_priv *priv = (void *)subdev;
110         u32 inst = nv_rd32(priv, 0x00b318) & 0x000fffff;
111         u32 stat = nv_rd32(priv, 0x00b100);
112         u32 type = nv_rd32(priv, 0x00b230);
113         u32 mthd = nv_rd32(priv, 0x00b234);
114         u32 data = nv_rd32(priv, 0x00b238);
115         u32 show = stat;
116         int chid;
117
118         engctx = nouveau_engctx_get(engine, inst);
119         chid   = pfifo->chid(pfifo, engctx);
120
121         if (stat & 0x01000000) {
122                 /* happens on initial binding of the object */
123                 if (type == 0x00000020 && mthd == 0x0000) {
124                         nv_mask(priv, 0x00b308, 0x00000000, 0x00000000);
125                         show &= ~0x01000000;
126                 }
127
128                 if (type == 0x00000010) {
129                         handle = nouveau_handle_get_class(engctx, 0x3174);
130                         if (handle && !nv_call(handle->object, mthd, data))
131                                 show &= ~0x01000000;
132                         nouveau_handle_put(handle);
133                 }
134         }
135
136         nv_wr32(priv, 0x00b100, stat);
137         nv_wr32(priv, 0x00b230, 0x00000001);
138
139         if (show) {
140                 nv_error(priv,
141                          "ch %d [0x%08x %s] 0x%08x 0x%08x 0x%08x 0x%08x\n",
142                          chid, inst << 4, nouveau_client_name(engctx), stat,
143                          type, mthd, data);
144         }
145
146         nouveau_engctx_put(engctx);
147 }
148
149 static void
150 nv44_mpeg_me_intr(struct nouveau_subdev *subdev)
151 {
152         struct nv44_mpeg_priv *priv = (void *)subdev;
153         u32 stat;
154
155         if ((stat = nv_rd32(priv, 0x00b100)))
156                 nv44_mpeg_intr(subdev);
157
158         if ((stat = nv_rd32(priv, 0x00b800))) {
159                 nv_error(priv, "PMSRCH 0x%08x\n", stat);
160                 nv_wr32(priv, 0x00b800, stat);
161         }
162 }
163
164 static int
165 nv44_mpeg_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
166                struct nouveau_oclass *oclass, void *data, u32 size,
167                struct nouveau_object **pobject)
168 {
169         struct nv44_mpeg_priv *priv;
170         int ret;
171
172         ret = nouveau_mpeg_create(parent, engine, oclass, &priv);
173         *pobject = nv_object(priv);
174         if (ret)
175                 return ret;
176
177         nv_subdev(priv)->unit = 0x00000002;
178         nv_subdev(priv)->intr = nv44_mpeg_me_intr;
179         nv_engine(priv)->cclass = &nv44_mpeg_cclass;
180         nv_engine(priv)->sclass = nv40_mpeg_sclass;
181         nv_engine(priv)->tile_prog = nv31_mpeg_tile_prog;
182         return 0;
183 }
184
185 struct nouveau_oclass
186 nv44_mpeg_oclass = {
187         .handle = NV_ENGINE(MPEG, 0x44),
188         .ofuncs = &(struct nouveau_ofuncs) {
189                 .ctor = nv44_mpeg_ctor,
190                 .dtor = _nouveau_mpeg_dtor,
191                 .init = nv31_mpeg_init,
192                 .fini = _nouveau_mpeg_fini,
193         },
194 };