Merge tag 'stable/for-linus-3.7-rc6-tag' of git://git.kernel.org/pub/scm/linux/kernel...
[sfrench/cifs-2.6.git] / drivers / gpu / drm / nouveau / core / engine / mpeg / nv40.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/engctx.h>
28
29 #include <subdev/fb.h>
30 #include <subdev/timer.h>
31 #include <subdev/instmem.h>
32
33 #include <engine/mpeg.h>
34 #include <engine/graph/nv40.h>
35
36 struct nv40_mpeg_priv {
37         struct nouveau_mpeg base;
38 };
39
40 struct nv40_mpeg_chan {
41         struct nouveau_mpeg_chan base;
42 };
43
44 /*******************************************************************************
45  * PMPEG context
46  ******************************************************************************/
47
48 static int
49 nv40_mpeg_context_ctor(struct nouveau_object *parent,
50                        struct nouveau_object *engine,
51                        struct nouveau_oclass *oclass, void *data, u32 size,
52                        struct nouveau_object **pobject)
53 {
54         struct nv40_mpeg_chan *chan;
55         int ret;
56
57         ret = nouveau_mpeg_context_create(parent, engine, oclass, NULL,
58                                           264 * 4, 16,
59                                           NVOBJ_FLAG_ZERO_ALLOC, &chan);
60         *pobject = nv_object(chan);
61         if (ret)
62                 return ret;
63
64         return 0;
65 }
66
67 static int
68 nv40_mpeg_context_fini(struct nouveau_object *object, bool suspend)
69 {
70
71         struct nv40_mpeg_priv *priv = (void *)object->engine;
72         struct nv40_mpeg_chan *chan = (void *)object;
73         u32 inst = 0x80000000 | nv_gpuobj(chan)->addr >> 4;
74
75         nv_mask(priv, 0x00b32c, 0x00000001, 0x00000000);
76         if (nv_rd32(priv, 0x00b318) == inst)
77                 nv_mask(priv, 0x00b318, 0x80000000, 0x00000000);
78         nv_mask(priv, 0x00b32c, 0x00000001, 0x00000001);
79         return 0;
80 }
81
82 static struct nouveau_oclass
83 nv40_mpeg_cclass = {
84         .handle = NV_ENGCTX(MPEG, 0x40),
85         .ofuncs = &(struct nouveau_ofuncs) {
86                 .ctor = nv40_mpeg_context_ctor,
87                 .dtor = _nouveau_mpeg_context_dtor,
88                 .init = _nouveau_mpeg_context_init,
89                 .fini = nv40_mpeg_context_fini,
90                 .rd32 = _nouveau_mpeg_context_rd32,
91                 .wr32 = _nouveau_mpeg_context_wr32,
92         },
93 };
94
95 /*******************************************************************************
96  * PMPEG engine/subdev functions
97  ******************************************************************************/
98
99 static void
100 nv40_mpeg_intr(struct nouveau_subdev *subdev)
101 {
102         struct nv40_mpeg_priv *priv = (void *)subdev;
103         u32 stat;
104
105         if ((stat = nv_rd32(priv, 0x00b100)))
106                 nv31_mpeg_intr(subdev);
107
108         if ((stat = nv_rd32(priv, 0x00b800))) {
109                 nv_error(priv, "PMSRCH 0x%08x\n", stat);
110                 nv_wr32(priv, 0x00b800, stat);
111         }
112 }
113
114 static int
115 nv40_mpeg_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
116                struct nouveau_oclass *oclass, void *data, u32 size,
117                struct nouveau_object **pobject)
118 {
119         struct nv40_mpeg_priv *priv;
120         int ret;
121
122         ret = nouveau_mpeg_create(parent, engine, oclass, &priv);
123         *pobject = nv_object(priv);
124         if (ret)
125                 return ret;
126
127         nv_subdev(priv)->unit = 0x00000002;
128         nv_subdev(priv)->intr = nv40_mpeg_intr;
129         nv_engine(priv)->cclass = &nv40_mpeg_cclass;
130         nv_engine(priv)->sclass = nv31_mpeg_sclass;
131         nv_engine(priv)->tile_prog = nv31_mpeg_tile_prog;
132         return 0;
133 }
134
135 struct nouveau_oclass
136 nv40_mpeg_oclass = {
137         .handle = NV_ENGINE(MPEG, 0x40),
138         .ofuncs = &(struct nouveau_ofuncs) {
139                 .ctor = nv40_mpeg_ctor,
140                 .dtor = _nouveau_mpeg_dtor,
141                 .init = nv31_mpeg_init,
142                 .fini = _nouveau_mpeg_fini,
143         },
144 };