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 #include <engine/mpeg.h> 25 26 #include <core/client.h> 27 #include <core/handle.h> 28 #include <engine/fifo.h> 29 30 struct nv44_mpeg_chan { 31 struct nvkm_mpeg_chan base; 32 }; 33 34 /******************************************************************************* 35 * PMPEG context 36 ******************************************************************************/ 37 38 static int 39 nv44_mpeg_context_ctor(struct nvkm_object *parent, 40 struct nvkm_object *engine, 41 struct nvkm_oclass *oclass, void *data, u32 size, 42 struct nvkm_object **pobject) 43 { 44 struct nv44_mpeg_chan *chan; 45 int ret; 46 47 ret = nvkm_mpeg_context_create(parent, engine, oclass, NULL, 264 * 4, 48 16, NVOBJ_FLAG_ZERO_ALLOC, &chan); 49 *pobject = nv_object(chan); 50 if (ret) 51 return ret; 52 53 nv_wo32(&chan->base.base, 0x78, 0x02001ec1); 54 return 0; 55 } 56 57 static int 58 nv44_mpeg_context_fini(struct nvkm_object *object, bool suspend) 59 { 60 61 struct nvkm_mpeg *mpeg = (void *)object->engine; 62 struct nv44_mpeg_chan *chan = (void *)object; 63 struct nvkm_device *device = mpeg->engine.subdev.device; 64 u32 inst = 0x80000000 | nv_gpuobj(chan)->addr >> 4; 65 66 nvkm_mask(device, 0x00b32c, 0x00000001, 0x00000000); 67 if (nvkm_rd32(device, 0x00b318) == inst) 68 nvkm_mask(device, 0x00b318, 0x80000000, 0x00000000); 69 nvkm_mask(device, 0x00b32c, 0x00000001, 0x00000001); 70 return 0; 71 } 72 73 static struct nvkm_oclass 74 nv44_mpeg_cclass = { 75 .handle = NV_ENGCTX(MPEG, 0x44), 76 .ofuncs = &(struct nvkm_ofuncs) { 77 .ctor = nv44_mpeg_context_ctor, 78 .dtor = _nvkm_mpeg_context_dtor, 79 .init = _nvkm_mpeg_context_init, 80 .fini = nv44_mpeg_context_fini, 81 .rd32 = _nvkm_mpeg_context_rd32, 82 .wr32 = _nvkm_mpeg_context_wr32, 83 }, 84 }; 85 86 /******************************************************************************* 87 * PMPEG engine/subdev functions 88 ******************************************************************************/ 89 90 static void 91 nv44_mpeg_intr(struct nvkm_subdev *subdev) 92 { 93 struct nvkm_mpeg *mpeg = (void *)subdev; 94 struct nvkm_device *device = mpeg->engine.subdev.device; 95 struct nvkm_fifo *fifo = device->fifo; 96 struct nvkm_engine *engine = nv_engine(subdev); 97 struct nvkm_object *engctx; 98 struct nvkm_handle *handle; 99 u32 inst = nvkm_rd32(device, 0x00b318) & 0x000fffff; 100 u32 stat = nvkm_rd32(device, 0x00b100); 101 u32 type = nvkm_rd32(device, 0x00b230); 102 u32 mthd = nvkm_rd32(device, 0x00b234); 103 u32 data = nvkm_rd32(device, 0x00b238); 104 u32 show = stat; 105 int chid; 106 107 engctx = nvkm_engctx_get(engine, inst); 108 chid = fifo->chid(fifo, engctx); 109 110 if (stat & 0x01000000) { 111 /* happens on initial binding of the object */ 112 if (type == 0x00000020 && mthd == 0x0000) { 113 nvkm_mask(device, 0x00b308, 0x00000000, 0x00000000); 114 show &= ~0x01000000; 115 } 116 117 if (type == 0x00000010) { 118 handle = nvkm_handle_get_class(engctx, 0x3174); 119 if (handle && !nv_call(handle->object, mthd, data)) 120 show &= ~0x01000000; 121 nvkm_handle_put(handle); 122 } 123 } 124 125 nvkm_wr32(device, 0x00b100, stat); 126 nvkm_wr32(device, 0x00b230, 0x00000001); 127 128 if (show) { 129 nv_error(mpeg, 130 "ch %d [0x%08x %s] 0x%08x 0x%08x 0x%08x 0x%08x\n", 131 chid, inst << 4, nvkm_client_name(engctx), stat, 132 type, mthd, data); 133 } 134 135 nvkm_engctx_put(engctx); 136 } 137 138 static void 139 nv44_mpeg_me_intr(struct nvkm_subdev *subdev) 140 { 141 struct nvkm_mpeg *mpeg = (void *)subdev; 142 struct nvkm_device *device = mpeg->engine.subdev.device; 143 u32 stat; 144 145 if ((stat = nvkm_rd32(device, 0x00b100))) 146 nv44_mpeg_intr(subdev); 147 148 if ((stat = nvkm_rd32(device, 0x00b800))) { 149 nv_error(mpeg, "PMSRCH 0x%08x\n", stat); 150 nvkm_wr32(device, 0x00b800, stat); 151 } 152 } 153 154 static int 155 nv44_mpeg_ctor(struct nvkm_object *parent, struct nvkm_object *engine, 156 struct nvkm_oclass *oclass, void *data, u32 size, 157 struct nvkm_object **pobject) 158 { 159 struct nvkm_mpeg *mpeg; 160 int ret; 161 162 ret = nvkm_mpeg_create(parent, engine, oclass, &mpeg); 163 *pobject = nv_object(mpeg); 164 if (ret) 165 return ret; 166 167 nv_subdev(mpeg)->unit = 0x00000002; 168 nv_subdev(mpeg)->intr = nv44_mpeg_me_intr; 169 nv_engine(mpeg)->cclass = &nv44_mpeg_cclass; 170 nv_engine(mpeg)->sclass = nv40_mpeg_sclass; 171 nv_engine(mpeg)->tile_prog = nv31_mpeg_tile_prog; 172 return 0; 173 } 174 175 struct nvkm_oclass 176 nv44_mpeg_oclass = { 177 .handle = NV_ENGINE(MPEG, 0x44), 178 .ofuncs = &(struct nvkm_ofuncs) { 179 .ctor = nv44_mpeg_ctor, 180 .dtor = _nvkm_mpeg_dtor, 181 .init = nv31_mpeg_init, 182 .fini = _nvkm_mpeg_fini, 183 }, 184 }; 185