drm/nouveau: merge nouveau_platform.ko into nouveau.ko
[deliverable/linux.git] / drivers / gpu / drm / nouveau / core / engine / mpeg / nv50.c
CommitLineData
c0924326 1/*
ebb945a9 2 * Copyright 2012 Red Hat Inc.
c0924326
BS
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
ebb945a9 25#include <core/os.h>
ebb945a9 26#include <core/engctx.h>
c0924326 27
ebb945a9
BS
28#include <subdev/vm.h>
29#include <subdev/bar.h>
30#include <subdev/timer.h>
c0924326 31
ebb945a9 32#include <engine/mpeg.h>
9548258f 33
ebb945a9
BS
34struct nv50_mpeg_priv {
35 struct nouveau_mpeg base;
36};
9548258f 37
ebb945a9
BS
38struct nv50_mpeg_chan {
39 struct nouveau_mpeg_chan base;
40};
41
42/*******************************************************************************
43 * MPEG object classes
44 ******************************************************************************/
9548258f 45
c0924326 46static int
ebb945a9
BS
47nv50_mpeg_object_ctor(struct nouveau_object *parent,
48 struct nouveau_object *engine,
49 struct nouveau_oclass *oclass, void *data, u32 size,
50 struct nouveau_object **pobject)
c0924326 51{
ebb945a9 52 struct nouveau_gpuobj *obj;
c0924326
BS
53 int ret;
54
ebb945a9
BS
55 ret = nouveau_gpuobj_create(parent, engine, oclass, 0, parent,
56 16, 16, 0, &obj);
57 *pobject = nv_object(obj);
c0924326
BS
58 if (ret)
59 return ret;
60
ebb945a9
BS
61 nv_wo32(obj, 0x00, nv_mclass(obj));
62 nv_wo32(obj, 0x04, 0x00000000);
63 nv_wo32(obj, 0x08, 0x00000000);
64 nv_wo32(obj, 0x0c, 0x00000000);
c0924326
BS
65 return 0;
66}
67
ebb945a9
BS
68struct nouveau_ofuncs
69nv50_mpeg_ofuncs = {
70 .ctor = nv50_mpeg_object_ctor,
71 .dtor = _nouveau_gpuobj_dtor,
72 .init = _nouveau_gpuobj_init,
73 .fini = _nouveau_gpuobj_fini,
74 .rd32 = _nouveau_gpuobj_rd32,
75 .wr32 = _nouveau_gpuobj_wr32,
76};
c0924326 77
ebb945a9
BS
78static struct nouveau_oclass
79nv50_mpeg_sclass[] = {
80 { 0x3174, &nv50_mpeg_ofuncs },
81 {}
82};
5511d490 83
ebb945a9
BS
84/*******************************************************************************
85 * PMPEG context
86 ******************************************************************************/
c0924326 87
ebb945a9
BS
88int
89nv50_mpeg_context_ctor(struct nouveau_object *parent,
90 struct nouveau_object *engine,
91 struct nouveau_oclass *oclass, void *data, u32 size,
92 struct nouveau_object **pobject)
c0924326 93{
ebb945a9
BS
94 struct nouveau_bar *bar = nouveau_bar(parent);
95 struct nv50_mpeg_chan *chan;
c0924326
BS
96 int ret;
97
ebb945a9
BS
98 ret = nouveau_mpeg_context_create(parent, engine, oclass, NULL, 128 * 4,
99 0, NVOBJ_FLAG_ZERO_ALLOC, &chan);
100 *pobject = nv_object(chan);
c0924326
BS
101 if (ret)
102 return ret;
c0924326 103
ebb945a9
BS
104 nv_wo32(chan, 0x0070, 0x00801ec1);
105 nv_wo32(chan, 0x007c, 0x0000037c);
106 bar->flush(bar);
107 return 0;
c0924326
BS
108}
109
ebb945a9
BS
110static struct nouveau_oclass
111nv50_mpeg_cclass = {
112 .handle = NV_ENGCTX(MPEG, 0x50),
113 .ofuncs = &(struct nouveau_ofuncs) {
114 .ctor = nv50_mpeg_context_ctor,
115 .dtor = _nouveau_mpeg_context_dtor,
116 .init = _nouveau_mpeg_context_init,
117 .fini = _nouveau_mpeg_context_fini,
118 .rd32 = _nouveau_mpeg_context_rd32,
119 .wr32 = _nouveau_mpeg_context_wr32,
120 },
121};
c0924326 122
ebb945a9
BS
123/*******************************************************************************
124 * PMPEG engine/subdev functions
125 ******************************************************************************/
c0924326 126
ebb945a9
BS
127void
128nv50_mpeg_intr(struct nouveau_subdev *subdev)
c0924326 129{
ebb945a9
BS
130 struct nv50_mpeg_priv *priv = (void *)subdev;
131 u32 stat = nv_rd32(priv, 0x00b100);
132 u32 type = nv_rd32(priv, 0x00b230);
133 u32 mthd = nv_rd32(priv, 0x00b234);
134 u32 data = nv_rd32(priv, 0x00b238);
c0924326
BS
135 u32 show = stat;
136
137 if (stat & 0x01000000) {
138 /* happens on initial binding of the object */
139 if (type == 0x00000020 && mthd == 0x0000) {
ebb945a9 140 nv_wr32(priv, 0x00b308, 0x00000100);
c0924326
BS
141 show &= ~0x01000000;
142 }
143 }
144
ebb945a9
BS
145 if (show) {
146 nv_info(priv, "0x%08x 0x%08x 0x%08x 0x%08x\n",
c0924326
BS
147 stat, type, mthd, data);
148 }
149
ebb945a9
BS
150 nv_wr32(priv, 0x00b100, stat);
151 nv_wr32(priv, 0x00b230, 0x00000001);
c0924326
BS
152}
153
9548258f 154static void
ebb945a9 155nv50_vpe_intr(struct nouveau_subdev *subdev)
9548258f 156{
ebb945a9 157 struct nv50_mpeg_priv *priv = (void *)subdev;
9548258f 158
ebb945a9
BS
159 if (nv_rd32(priv, 0x00b100))
160 nv50_mpeg_intr(subdev);
161
162 if (nv_rd32(priv, 0x00b800)) {
163 u32 stat = nv_rd32(priv, 0x00b800);
164 nv_info(priv, "PMSRCH: 0x%08x\n", stat);
165 nv_wr32(priv, 0xb800, stat);
9548258f
BS
166 }
167}
168
ebb945a9
BS
169static int
170nv50_mpeg_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
171 struct nouveau_oclass *oclass, void *data, u32 size,
172 struct nouveau_object **pobject)
c0924326 173{
ebb945a9
BS
174 struct nv50_mpeg_priv *priv;
175 int ret;
c0924326 176
ebb945a9
BS
177 ret = nouveau_mpeg_create(parent, engine, oclass, &priv);
178 *pobject = nv_object(priv);
179 if (ret)
180 return ret;
c0924326 181
ebb945a9
BS
182 nv_subdev(priv)->unit = 0x00400002;
183 nv_subdev(priv)->intr = nv50_vpe_intr;
184 nv_engine(priv)->cclass = &nv50_mpeg_cclass;
185 nv_engine(priv)->sclass = nv50_mpeg_sclass;
ebb945a9 186 return 0;
c0924326
BS
187}
188
189int
ebb945a9 190nv50_mpeg_init(struct nouveau_object *object)
c0924326 191{
ebb945a9
BS
192 struct nv50_mpeg_priv *priv = (void *)object;
193 int ret;
194
195 ret = nouveau_mpeg_init(&priv->base);
196 if (ret)
197 return ret;
198
199 nv_wr32(priv, 0x00b32c, 0x00000000);
200 nv_wr32(priv, 0x00b314, 0x00000100);
201 nv_wr32(priv, 0x00b0e0, 0x0000001a);
202
203 nv_wr32(priv, 0x00b220, 0x00000044);
204 nv_wr32(priv, 0x00b300, 0x00801ec1);
205 nv_wr32(priv, 0x00b390, 0x00000000);
206 nv_wr32(priv, 0x00b394, 0x00000000);
207 nv_wr32(priv, 0x00b398, 0x00000000);
208 nv_mask(priv, 0x00b32c, 0x00000001, 0x00000001);
209
210 nv_wr32(priv, 0x00b100, 0xffffffff);
211 nv_wr32(priv, 0x00b140, 0xffffffff);
212
213 if (!nv_wait(priv, 0x00b200, 0x00000001, 0x00000000)) {
214 nv_error(priv, "timeout 0x%08x\n", nv_rd32(priv, 0x00b200));
215 return -EBUSY;
9548258f 216 }
c0924326 217
c0924326 218 return 0;
c0924326 219}
ebb945a9
BS
220
221struct nouveau_oclass
222nv50_mpeg_oclass = {
223 .handle = NV_ENGINE(MPEG, 0x50),
224 .ofuncs = &(struct nouveau_ofuncs) {
225 .ctor = nv50_mpeg_ctor,
226 .dtor = _nouveau_mpeg_dtor,
227 .init = nv50_mpeg_init,
228 .fini = _nouveau_mpeg_fini,
229 },
230};
This page took 0.249375 seconds and 5 git commands to generate.