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