1c39f472eSBen Skeggs /*
2c39f472eSBen Skeggs * Copyright 2012 Red Hat Inc.
3c39f472eSBen Skeggs *
4c39f472eSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5c39f472eSBen Skeggs * copy of this software and associated documentation files (the "Software"),
6c39f472eSBen Skeggs * to deal in the Software without restriction, including without limitation
7c39f472eSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8c39f472eSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9c39f472eSBen Skeggs * Software is furnished to do so, subject to the following conditions:
10c39f472eSBen Skeggs *
11c39f472eSBen Skeggs * The above copyright notice and this permission notice shall be included in
12c39f472eSBen Skeggs * all copies or substantial portions of the Software.
13c39f472eSBen Skeggs *
14c39f472eSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15c39f472eSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16c39f472eSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17c39f472eSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18c39f472eSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19c39f472eSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20c39f472eSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21c39f472eSBen Skeggs *
22c39f472eSBen Skeggs * Authors: Ben Skeggs
23c39f472eSBen Skeggs */
24e7c29683SBen Skeggs #include "nv31.h"
25c39f472eSBen Skeggs
26c39f472eSBen Skeggs #include <subdev/instmem.h>
27c39f472eSBen Skeggs
28218f978dSBen Skeggs #include <nvif/class.h>
29c39f472eSBen Skeggs
30590801c1SBen Skeggs bool
nv40_mpeg_mthd_dma(struct nvkm_device * device,u32 mthd,u32 data)31590801c1SBen Skeggs nv40_mpeg_mthd_dma(struct nvkm_device *device, u32 mthd, u32 data)
32c39f472eSBen Skeggs {
33636e37aaSBen Skeggs struct nvkm_instmem *imem = device->imem;
34d257f9bfSIlia Mirkin struct nv31_mpeg *mpeg = nv31_mpeg(device->mpeg);
35d257f9bfSIlia Mirkin struct nvkm_subdev *subdev = &mpeg->engine.subdev;
36590801c1SBen Skeggs u32 inst = data << 4;
37b7a2bc18SBen Skeggs u32 dma0 = nvkm_instmem_rd32(imem, inst + 0);
38b7a2bc18SBen Skeggs u32 dma1 = nvkm_instmem_rd32(imem, inst + 4);
39b7a2bc18SBen Skeggs u32 dma2 = nvkm_instmem_rd32(imem, inst + 8);
40c39f472eSBen Skeggs u32 base = (dma2 & 0xfffff000) | (dma0 >> 20);
41c39f472eSBen Skeggs u32 size = dma1 + 1;
42c39f472eSBen Skeggs
43c39f472eSBen Skeggs /* only allow linear DMA objects */
44d257f9bfSIlia Mirkin if (!(dma0 & 0x00002000)) {
45d257f9bfSIlia Mirkin nvkm_error(subdev, "inst %08x dma0 %08x dma1 %08x dma2 %08x\n",
46d257f9bfSIlia Mirkin inst, dma0, dma1, dma2);
47590801c1SBen Skeggs return false;
48d257f9bfSIlia Mirkin }
49c39f472eSBen Skeggs
50c39f472eSBen Skeggs if (mthd == 0x0190) {
51c39f472eSBen Skeggs /* DMA_CMD */
52636e37aaSBen Skeggs nvkm_mask(device, 0x00b300, 0x00030000, (dma0 & 0x00030000));
53636e37aaSBen Skeggs nvkm_wr32(device, 0x00b334, base);
54636e37aaSBen Skeggs nvkm_wr32(device, 0x00b324, size);
55c39f472eSBen Skeggs } else
56c39f472eSBen Skeggs if (mthd == 0x01a0) {
57c39f472eSBen Skeggs /* DMA_DATA */
58636e37aaSBen Skeggs nvkm_mask(device, 0x00b300, 0x000c0000, (dma0 & 0x00030000) << 2);
59636e37aaSBen Skeggs nvkm_wr32(device, 0x00b360, base);
60636e37aaSBen Skeggs nvkm_wr32(device, 0x00b364, size);
61c39f472eSBen Skeggs } else {
62c39f472eSBen Skeggs /* DMA_IMAGE, VRAM only */
63c39f472eSBen Skeggs if (dma0 & 0x00030000)
64590801c1SBen Skeggs return false;
65c39f472eSBen Skeggs
66636e37aaSBen Skeggs nvkm_wr32(device, 0x00b370, base);
67636e37aaSBen Skeggs nvkm_wr32(device, 0x00b374, size);
68c39f472eSBen Skeggs }
69c39f472eSBen Skeggs
70590801c1SBen Skeggs return true;
71c39f472eSBen Skeggs }
72c39f472eSBen Skeggs
737624fc01SBen Skeggs static const struct nv31_mpeg_func
74218f978dSBen Skeggs nv40_mpeg = {
757624fc01SBen Skeggs .mthd_dma = nv40_mpeg_mthd_dma,
76218f978dSBen Skeggs };
77218f978dSBen Skeggs
787624fc01SBen Skeggs int
nv40_mpeg_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_engine ** pmpeg)79*e5e95a76SBen Skeggs nv40_mpeg_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
80*e5e95a76SBen Skeggs struct nvkm_engine **pmpeg)
81c39f472eSBen Skeggs {
82*e5e95a76SBen Skeggs return nv31_mpeg_new_(&nv40_mpeg, device, type, inst, pmpeg);
83c39f472eSBen Skeggs }
84