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 u32 inst = 0x80000000 | nv_gpuobj(chan)->addr >> 4; 64 65 nv_mask(mpeg, 0x00b32c, 0x00000001, 0x00000000); 66 if (nv_rd32(mpeg, 0x00b318) == inst) 67 nv_mask(mpeg, 0x00b318, 0x80000000, 0x00000000); 68 nv_mask(mpeg, 0x00b32c, 0x00000001, 0x00000001); 69 return 0; 70 } 71 72 static struct nvkm_oclass 73 nv44_mpeg_cclass = { 74 .handle = NV_ENGCTX(MPEG, 0x44), 75 .ofuncs = &(struct nvkm_ofuncs) { 76 .ctor = nv44_mpeg_context_ctor, 77 .dtor = _nvkm_mpeg_context_dtor, 78 .init = _nvkm_mpeg_context_init, 79 .fini = nv44_mpeg_context_fini, 80 .rd32 = _nvkm_mpeg_context_rd32, 81 .wr32 = _nvkm_mpeg_context_wr32, 82 }, 83 }; 84 85 /******************************************************************************* 86 * PMPEG engine/subdev functions 87 ******************************************************************************/ 88 89 static void 90 nv44_mpeg_intr(struct nvkm_subdev *subdev) 91 { 92 struct nvkm_fifo *fifo = nvkm_fifo(subdev); 93 struct nvkm_engine *engine = nv_engine(subdev); 94 struct nvkm_object *engctx; 95 struct nvkm_handle *handle; 96 struct nvkm_mpeg *mpeg = (void *)subdev; 97 u32 inst = nv_rd32(mpeg, 0x00b318) & 0x000fffff; 98 u32 stat = nv_rd32(mpeg, 0x00b100); 99 u32 type = nv_rd32(mpeg, 0x00b230); 100 u32 mthd = nv_rd32(mpeg, 0x00b234); 101 u32 data = nv_rd32(mpeg, 0x00b238); 102 u32 show = stat; 103 int chid; 104 105 engctx = nvkm_engctx_get(engine, inst); 106 chid = fifo->chid(fifo, engctx); 107 108 if (stat & 0x01000000) { 109 /* happens on initial binding of the object */ 110 if (type == 0x00000020 && mthd == 0x0000) { 111 nv_mask(mpeg, 0x00b308, 0x00000000, 0x00000000); 112 show &= ~0x01000000; 113 } 114 115 if (type == 0x00000010) { 116 handle = nvkm_handle_get_class(engctx, 0x3174); 117 if (handle && !nv_call(handle->object, mthd, data)) 118 show &= ~0x01000000; 119 nvkm_handle_put(handle); 120 } 121 } 122 123 nv_wr32(mpeg, 0x00b100, stat); 124 nv_wr32(mpeg, 0x00b230, 0x00000001); 125 126 if (show) { 127 nv_error(mpeg, 128 "ch %d [0x%08x %s] 0x%08x 0x%08x 0x%08x 0x%08x\n", 129 chid, inst << 4, nvkm_client_name(engctx), stat, 130 type, mthd, data); 131 } 132 133 nvkm_engctx_put(engctx); 134 } 135 136 static void 137 nv44_mpeg_me_intr(struct nvkm_subdev *subdev) 138 { 139 struct nvkm_mpeg *mpeg = (void *)subdev; 140 u32 stat; 141 142 if ((stat = nv_rd32(mpeg, 0x00b100))) 143 nv44_mpeg_intr(subdev); 144 145 if ((stat = nv_rd32(mpeg, 0x00b800))) { 146 nv_error(mpeg, "PMSRCH 0x%08x\n", stat); 147 nv_wr32(mpeg, 0x00b800, stat); 148 } 149 } 150 151 static int 152 nv44_mpeg_ctor(struct nvkm_object *parent, struct nvkm_object *engine, 153 struct nvkm_oclass *oclass, void *data, u32 size, 154 struct nvkm_object **pobject) 155 { 156 struct nvkm_mpeg *mpeg; 157 int ret; 158 159 ret = nvkm_mpeg_create(parent, engine, oclass, &mpeg); 160 *pobject = nv_object(mpeg); 161 if (ret) 162 return ret; 163 164 nv_subdev(mpeg)->unit = 0x00000002; 165 nv_subdev(mpeg)->intr = nv44_mpeg_me_intr; 166 nv_engine(mpeg)->cclass = &nv44_mpeg_cclass; 167 nv_engine(mpeg)->sclass = nv40_mpeg_sclass; 168 nv_engine(mpeg)->tile_prog = nv31_mpeg_tile_prog; 169 return 0; 170 } 171 172 struct nvkm_oclass 173 nv44_mpeg_oclass = { 174 .handle = NV_ENGINE(MPEG, 0x44), 175 .ofuncs = &(struct nvkm_ofuncs) { 176 .ctor = nv44_mpeg_ctor, 177 .dtor = _nvkm_mpeg_dtor, 178 .init = nv31_mpeg_init, 179 .fini = _nvkm_mpeg_fini, 180 }, 181 }; 182