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