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 struct nvkm_engine *ce = (void *)subdev; 68 u32 stat = nvkm_rd32(device, 0x104908 + (idx * 0x1000)); 69 70 if (stat) { 71 nv_warn(ce, "unhandled intr 0x%08x\n", stat); 72 nvkm_wr32(device, 0x104908 + (idx * 0x1000), stat); 73 } 74 } 75 76 static int 77 gk104_ce0_ctor(struct nvkm_object *parent, struct nvkm_object *engine, 78 struct nvkm_oclass *oclass, void *data, u32 size, 79 struct nvkm_object **pobject) 80 { 81 struct nvkm_engine *ce; 82 int ret; 83 84 ret = nvkm_engine_create(parent, engine, oclass, true, 85 "PCE0", "ce0", &ce); 86 *pobject = nv_object(ce); 87 if (ret) 88 return ret; 89 90 nv_subdev(ce)->unit = 0x00000040; 91 nv_subdev(ce)->intr = gk104_ce_intr; 92 nv_engine(ce)->cclass = &gk104_ce_cclass; 93 nv_engine(ce)->sclass = gk104_ce_sclass; 94 return 0; 95 } 96 97 static int 98 gk104_ce1_ctor(struct nvkm_object *parent, struct nvkm_object *engine, 99 struct nvkm_oclass *oclass, void *data, u32 size, 100 struct nvkm_object **pobject) 101 { 102 struct nvkm_engine *ce; 103 int ret; 104 105 ret = nvkm_engine_create(parent, engine, oclass, true, 106 "PCE1", "ce1", &ce); 107 *pobject = nv_object(ce); 108 if (ret) 109 return ret; 110 111 nv_subdev(ce)->unit = 0x00000080; 112 nv_subdev(ce)->intr = gk104_ce_intr; 113 nv_engine(ce)->cclass = &gk104_ce_cclass; 114 nv_engine(ce)->sclass = gk104_ce_sclass; 115 return 0; 116 } 117 118 static int 119 gk104_ce2_ctor(struct nvkm_object *parent, struct nvkm_object *engine, 120 struct nvkm_oclass *oclass, void *data, u32 size, 121 struct nvkm_object **pobject) 122 { 123 struct nvkm_engine *ce; 124 int ret; 125 126 ret = nvkm_engine_create(parent, engine, oclass, true, 127 "PCE2", "ce2", &ce); 128 *pobject = nv_object(ce); 129 if (ret) 130 return ret; 131 132 nv_subdev(ce)->unit = 0x00200000; 133 nv_subdev(ce)->intr = gk104_ce_intr; 134 nv_engine(ce)->cclass = &gk104_ce_cclass; 135 nv_engine(ce)->sclass = gk104_ce_sclass; 136 return 0; 137 } 138 139 struct nvkm_oclass 140 gk104_ce0_oclass = { 141 .handle = NV_ENGINE(CE0, 0xe0), 142 .ofuncs = &(struct nvkm_ofuncs) { 143 .ctor = gk104_ce0_ctor, 144 .dtor = _nvkm_engine_dtor, 145 .init = _nvkm_engine_init, 146 .fini = _nvkm_engine_fini, 147 }, 148 }; 149 150 struct nvkm_oclass 151 gk104_ce1_oclass = { 152 .handle = NV_ENGINE(CE1, 0xe0), 153 .ofuncs = &(struct nvkm_ofuncs) { 154 .ctor = gk104_ce1_ctor, 155 .dtor = _nvkm_engine_dtor, 156 .init = _nvkm_engine_init, 157 .fini = _nvkm_engine_fini, 158 }, 159 }; 160 161 struct nvkm_oclass 162 gk104_ce2_oclass = { 163 .handle = NV_ENGINE(CE2, 0xe0), 164 .ofuncs = &(struct nvkm_ofuncs) { 165 .ctor = gk104_ce2_ctor, 166 .dtor = _nvkm_engine_dtor, 167 .init = _nvkm_engine_init, 168 .fini = _nvkm_engine_fini, 169 }, 170 }; 171