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/ce.h> 25 26 #include <core/engctx.h> 27 28 /******************************************************************************* 29 * Copy object classes 30 ******************************************************************************/ 31 32 static struct nvkm_oclass 33 gk104_ce_sclass[] = { 34 { 0xa0b5, &nvkm_object_ofuncs }, 35 {}, 36 }; 37 38 /******************************************************************************* 39 * PCE context 40 ******************************************************************************/ 41 42 static struct nvkm_ofuncs 43 gk104_ce_context_ofuncs = { 44 .ctor = _nvkm_engctx_ctor, 45 .dtor = _nvkm_engctx_dtor, 46 .init = _nvkm_engctx_init, 47 .fini = _nvkm_engctx_fini, 48 .rd32 = _nvkm_engctx_rd32, 49 .wr32 = _nvkm_engctx_wr32, 50 }; 51 52 static struct nvkm_oclass 53 gk104_ce_cclass = { 54 .handle = NV_ENGCTX(CE0, 0xc0), 55 .ofuncs = &gk104_ce_context_ofuncs, 56 }; 57 58 /******************************************************************************* 59 * PCE engine/subdev functions 60 ******************************************************************************/ 61 62 static void 63 gk104_ce_intr(struct nvkm_subdev *subdev) 64 { 65 struct nvkm_device *device = subdev->device; 66 const int idx = nv_subidx(subdev) - NVDEV_ENGINE_CE0; 67 u32 stat = nvkm_rd32(device, 0x104908 + (idx * 0x1000)); 68 69 if (stat) { 70 nvkm_warn(subdev, "intr %08x\n", stat); 71 nvkm_wr32(device, 0x104908 + (idx * 0x1000), stat); 72 } 73 } 74 75 static int 76 gk104_ce0_ctor(struct nvkm_object *parent, struct nvkm_object *engine, 77 struct nvkm_oclass *oclass, void *data, u32 size, 78 struct nvkm_object **pobject) 79 { 80 struct nvkm_engine *ce; 81 int ret; 82 83 ret = nvkm_engine_create(parent, engine, oclass, true, 84 "PCE0", "ce0", &ce); 85 *pobject = nv_object(ce); 86 if (ret) 87 return ret; 88 89 nv_subdev(ce)->unit = 0x00000040; 90 nv_subdev(ce)->intr = gk104_ce_intr; 91 nv_engine(ce)->cclass = &gk104_ce_cclass; 92 nv_engine(ce)->sclass = gk104_ce_sclass; 93 return 0; 94 } 95 96 static int 97 gk104_ce1_ctor(struct nvkm_object *parent, struct nvkm_object *engine, 98 struct nvkm_oclass *oclass, void *data, u32 size, 99 struct nvkm_object **pobject) 100 { 101 struct nvkm_engine *ce; 102 int ret; 103 104 ret = nvkm_engine_create(parent, engine, oclass, true, 105 "PCE1", "ce1", &ce); 106 *pobject = nv_object(ce); 107 if (ret) 108 return ret; 109 110 nv_subdev(ce)->unit = 0x00000080; 111 nv_subdev(ce)->intr = gk104_ce_intr; 112 nv_engine(ce)->cclass = &gk104_ce_cclass; 113 nv_engine(ce)->sclass = gk104_ce_sclass; 114 return 0; 115 } 116 117 static int 118 gk104_ce2_ctor(struct nvkm_object *parent, struct nvkm_object *engine, 119 struct nvkm_oclass *oclass, void *data, u32 size, 120 struct nvkm_object **pobject) 121 { 122 struct nvkm_engine *ce; 123 int ret; 124 125 ret = nvkm_engine_create(parent, engine, oclass, true, 126 "PCE2", "ce2", &ce); 127 *pobject = nv_object(ce); 128 if (ret) 129 return ret; 130 131 nv_subdev(ce)->unit = 0x00200000; 132 nv_subdev(ce)->intr = gk104_ce_intr; 133 nv_engine(ce)->cclass = &gk104_ce_cclass; 134 nv_engine(ce)->sclass = gk104_ce_sclass; 135 return 0; 136 } 137 138 struct nvkm_oclass 139 gk104_ce0_oclass = { 140 .handle = NV_ENGINE(CE0, 0xe0), 141 .ofuncs = &(struct nvkm_ofuncs) { 142 .ctor = gk104_ce0_ctor, 143 .dtor = _nvkm_engine_dtor, 144 .init = _nvkm_engine_init, 145 .fini = _nvkm_engine_fini, 146 }, 147 }; 148 149 struct nvkm_oclass 150 gk104_ce1_oclass = { 151 .handle = NV_ENGINE(CE1, 0xe0), 152 .ofuncs = &(struct nvkm_ofuncs) { 153 .ctor = gk104_ce1_ctor, 154 .dtor = _nvkm_engine_dtor, 155 .init = _nvkm_engine_init, 156 .fini = _nvkm_engine_fini, 157 }, 158 }; 159 160 struct nvkm_oclass 161 gk104_ce2_oclass = { 162 .handle = NV_ENGINE(CE2, 0xe0), 163 .ofuncs = &(struct nvkm_ofuncs) { 164 .ctor = gk104_ce2_ctor, 165 .dtor = _nvkm_engine_dtor, 166 .init = _nvkm_engine_init, 167 .fini = _nvkm_engine_fini, 168 }, 169 }; 170