1/* $NetBSD: nouveau_engine_mpeg_nv44.c,v 1.1.1.1 2014/08/06 12:36:27 riastradh Exp $ */
2
3/*
4 * Copyright 2012 Red Hat Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Ben Skeggs
25 */
26
27#include <sys/cdefs.h>
28__KERNEL_RCSID(0, "$NetBSD: nouveau_engine_mpeg_nv44.c,v 1.1.1.1 2014/08/06 12:36:27 riastradh Exp $");
29
30#include <core/os.h>
31#include <core/class.h>
32#include <core/client.h>
33#include <core/engctx.h>
34#include <core/handle.h>
35
36#include <subdev/fb.h>
37#include <subdev/timer.h>
38#include <subdev/instmem.h>
39
40#include <engine/fifo.h>
41#include <engine/mpeg.h>
42
43struct nv44_mpeg_priv {
44 struct nouveau_mpeg base;
45};
46
47struct nv44_mpeg_chan {
48 struct nouveau_mpeg_chan base;
49};
50
51/*******************************************************************************
52 * PMPEG context
53 ******************************************************************************/
54
55static int
56nv44_mpeg_context_ctor(struct nouveau_object *parent,
57 struct nouveau_object *engine,
58 struct nouveau_oclass *oclass, void *data, u32 size,
59 struct nouveau_object **pobject)
60{
61 struct nv44_mpeg_chan *chan;
62 int ret;
63
64 ret = nouveau_mpeg_context_create(parent, engine, oclass, NULL,
65 264 * 4, 16,
66 NVOBJ_FLAG_ZERO_ALLOC, &chan);
67 *pobject = nv_object(chan);
68 if (ret)
69 return ret;
70
71 nv_wo32(&chan->base.base, 0x78, 0x02001ec1);
72 return 0;
73}
74
75static int
76nv44_mpeg_context_fini(struct nouveau_object *object, bool suspend)
77{
78
79 struct nv44_mpeg_priv *priv = (void *)object->engine;
80 struct nv44_mpeg_chan *chan = (void *)object;
81 u32 inst = 0x80000000 | nv_gpuobj(chan)->addr >> 4;
82
83 nv_mask(priv, 0x00b32c, 0x00000001, 0x00000000);
84 if (nv_rd32(priv, 0x00b318) == inst)
85 nv_mask(priv, 0x00b318, 0x80000000, 0x00000000);
86 nv_mask(priv, 0x00b32c, 0x00000001, 0x00000001);
87 return 0;
88}
89
90static struct nouveau_oclass
91nv44_mpeg_cclass = {
92 .handle = NV_ENGCTX(MPEG, 0x44),
93 .ofuncs = &(struct nouveau_ofuncs) {
94 .ctor = nv44_mpeg_context_ctor,
95 .dtor = _nouveau_mpeg_context_dtor,
96 .init = _nouveau_mpeg_context_init,
97 .fini = nv44_mpeg_context_fini,
98 .rd32 = _nouveau_mpeg_context_rd32,
99 .wr32 = _nouveau_mpeg_context_wr32,
100 },
101};
102
103/*******************************************************************************
104 * PMPEG engine/subdev functions
105 ******************************************************************************/
106
107static void
108nv44_mpeg_intr(struct nouveau_subdev *subdev)
109{
110 struct nouveau_fifo *pfifo = nouveau_fifo(subdev);
111 struct nouveau_engine *engine = nv_engine(subdev);
112 struct nouveau_object *engctx;
113 struct nouveau_handle *handle;
114 struct nv44_mpeg_priv *priv = (void *)subdev;
115 u32 inst = nv_rd32(priv, 0x00b318) & 0x000fffff;
116 u32 stat = nv_rd32(priv, 0x00b100);
117 u32 type = nv_rd32(priv, 0x00b230);
118 u32 mthd = nv_rd32(priv, 0x00b234);
119 u32 data = nv_rd32(priv, 0x00b238);
120 u32 show = stat;
121 int chid;
122
123 engctx = nouveau_engctx_get(engine, inst);
124 chid = pfifo->chid(pfifo, engctx);
125
126 if (stat & 0x01000000) {
127 /* happens on initial binding of the object */
128 if (type == 0x00000020 && mthd == 0x0000) {
129 nv_mask(priv, 0x00b308, 0x00000000, 0x00000000);
130 show &= ~0x01000000;
131 }
132
133 if (type == 0x00000010) {
134 handle = nouveau_handle_get_class(engctx, 0x3174);
135 if (handle && !nv_call(handle->object, mthd, data))
136 show &= ~0x01000000;
137 nouveau_handle_put(handle);
138 }
139 }
140
141 nv_wr32(priv, 0x00b100, stat);
142 nv_wr32(priv, 0x00b230, 0x00000001);
143
144 if (show) {
145 nv_error(priv,
146 "ch %d [0x%08x %s] 0x%08x 0x%08x 0x%08x 0x%08x\n",
147 chid, inst << 4, nouveau_client_name(engctx), stat,
148 type, mthd, data);
149 }
150
151 nouveau_engctx_put(engctx);
152}
153
154static void
155nv44_mpeg_me_intr(struct nouveau_subdev *subdev)
156{
157 struct nv44_mpeg_priv *priv = (void *)subdev;
158 u32 stat;
159
160 if ((stat = nv_rd32(priv, 0x00b100)))
161 nv44_mpeg_intr(subdev);
162
163 if ((stat = nv_rd32(priv, 0x00b800))) {
164 nv_error(priv, "PMSRCH 0x%08x\n", stat);
165 nv_wr32(priv, 0x00b800, stat);
166 }
167}
168
169static int
170nv44_mpeg_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
171 struct nouveau_oclass *oclass, void *data, u32 size,
172 struct nouveau_object **pobject)
173{
174 struct nv44_mpeg_priv *priv;
175 int ret;
176
177 ret = nouveau_mpeg_create(parent, engine, oclass, &priv);
178 *pobject = nv_object(priv);
179 if (ret)
180 return ret;
181
182 nv_subdev(priv)->unit = 0x00000002;
183 nv_subdev(priv)->intr = nv44_mpeg_me_intr;
184 nv_engine(priv)->cclass = &nv44_mpeg_cclass;
185 nv_engine(priv)->sclass = nv40_mpeg_sclass;
186 nv_engine(priv)->tile_prog = nv31_mpeg_tile_prog;
187 return 0;
188}
189
190struct nouveau_oclass
191nv44_mpeg_oclass = {
192 .handle = NV_ENGINE(MPEG, 0x44),
193 .ofuncs = &(struct nouveau_ofuncs) {
194 .ctor = nv44_mpeg_ctor,
195 .dtor = _nouveau_mpeg_dtor,
196 .init = nv31_mpeg_init,
197 .fini = _nouveau_mpeg_fini,
198 },
199};
200