1/* $NetBSD: nouveau_engine_mpeg_nv40.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_nv40.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/engctx.h>
33
34#include <subdev/fb.h>
35#include <subdev/timer.h>
36#include <subdev/instmem.h>
37
38#include <engine/mpeg.h>
39#include <engine/mpeg/nv31.h>
40
41/*******************************************************************************
42 * MPEG object classes
43 ******************************************************************************/
44
45static int
46nv40_mpeg_mthd_dma(struct nouveau_object *object, u32 mthd, void *arg, u32 len)
47{
48 struct nouveau_instmem *imem = nouveau_instmem(object);
49 struct nv31_mpeg_priv *priv = (void *)object->engine;
50 u32 inst = *(u32 *)arg << 4;
51 u32 dma0 = nv_ro32(imem, inst + 0);
52 u32 dma1 = nv_ro32(imem, inst + 4);
53 u32 dma2 = nv_ro32(imem, inst + 8);
54 u32 base = (dma2 & 0xfffff000) | (dma0 >> 20);
55 u32 size = dma1 + 1;
56
57 /* only allow linear DMA objects */
58 if (!(dma0 & 0x00002000))
59 return -EINVAL;
60
61 if (mthd == 0x0190) {
62 /* DMA_CMD */
63 nv_mask(priv, 0x00b300, 0x00030000, (dma0 & 0x00030000));
64 nv_wr32(priv, 0x00b334, base);
65 nv_wr32(priv, 0x00b324, size);
66 } else
67 if (mthd == 0x01a0) {
68 /* DMA_DATA */
69 nv_mask(priv, 0x00b300, 0x000c0000, (dma0 & 0x00030000) << 2);
70 nv_wr32(priv, 0x00b360, base);
71 nv_wr32(priv, 0x00b364, size);
72 } else {
73 /* DMA_IMAGE, VRAM only */
74 if (dma0 & 0x00030000)
75 return -EINVAL;
76
77 nv_wr32(priv, 0x00b370, base);
78 nv_wr32(priv, 0x00b374, size);
79 }
80
81 return 0;
82}
83
84static struct nouveau_omthds
85nv40_mpeg_omthds[] = {
86 { 0x0190, 0x0190, nv40_mpeg_mthd_dma },
87 { 0x01a0, 0x01a0, nv40_mpeg_mthd_dma },
88 { 0x01b0, 0x01b0, nv40_mpeg_mthd_dma },
89 {}
90};
91
92struct nouveau_oclass
93nv40_mpeg_sclass[] = {
94 { 0x3174, &nv31_mpeg_ofuncs, nv40_mpeg_omthds },
95 {}
96};
97
98/*******************************************************************************
99 * PMPEG engine/subdev functions
100 ******************************************************************************/
101
102static void
103nv40_mpeg_intr(struct nouveau_subdev *subdev)
104{
105 struct nv31_mpeg_priv *priv = (void *)subdev;
106 u32 stat;
107
108 if ((stat = nv_rd32(priv, 0x00b100)))
109 nv31_mpeg_intr(subdev);
110
111 if ((stat = nv_rd32(priv, 0x00b800))) {
112 nv_error(priv, "PMSRCH 0x%08x\n", stat);
113 nv_wr32(priv, 0x00b800, stat);
114 }
115}
116
117static int
118nv40_mpeg_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
119 struct nouveau_oclass *oclass, void *data, u32 size,
120 struct nouveau_object **pobject)
121{
122 struct nv31_mpeg_priv *priv;
123 int ret;
124
125 ret = nouveau_mpeg_create(parent, engine, oclass, &priv);
126 *pobject = nv_object(priv);
127 if (ret)
128 return ret;
129
130 nv_subdev(priv)->unit = 0x00000002;
131 nv_subdev(priv)->intr = nv40_mpeg_intr;
132 nv_engine(priv)->cclass = &nv31_mpeg_cclass;
133 nv_engine(priv)->sclass = nv40_mpeg_sclass;
134 nv_engine(priv)->tile_prog = nv31_mpeg_tile_prog;
135 return 0;
136}
137
138struct nouveau_oclass
139nv40_mpeg_oclass = {
140 .handle = NV_ENGINE(MPEG, 0x40),
141 .ofuncs = &(struct nouveau_ofuncs) {
142 .ctor = nv40_mpeg_ctor,
143 .dtor = _nouveau_mpeg_dtor,
144 .init = nv31_mpeg_init,
145 .fini = _nouveau_mpeg_fini,
146 },
147};
148