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