1 /* 2 * Copyright 2015 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 <bskeggs@redhat.com> 23 */ 24 #include "priv.h" 25 26 #include <engine/fifo.h> 27 28 static int 29 nvkm_gr_oclass_get(struct nvkm_oclass *oclass, int index) 30 { 31 struct nvkm_gr *gr = nvkm_gr(oclass->engine); 32 int c = 0; 33 34 if (gr->func->object_get) { 35 int ret = gr->func->object_get(gr, index, &oclass->base); 36 if (oclass->base.oclass) 37 return index; 38 return ret; 39 } 40 41 while (gr->func->sclass[c].oclass) { 42 if (c++ == index) { 43 oclass->base = gr->func->sclass[index]; 44 return index; 45 } 46 } 47 48 return c; 49 } 50 51 static int 52 nvkm_gr_cclass_new(struct nvkm_fifo_chan *chan, 53 const struct nvkm_oclass *oclass, 54 struct nvkm_object **pobject) 55 { 56 struct nvkm_gr *gr = nvkm_gr(oclass->engine); 57 if (gr->func->chan_new) 58 return gr->func->chan_new(gr, chan, oclass, pobject); 59 return 0; 60 } 61 62 struct nvkm_engine_func 63 nvkm_gr = { 64 .fifo.cclass = nvkm_gr_cclass_new, 65 .fifo.sclass = nvkm_gr_oclass_get, 66 }; 67 68 int 69 nvkm_gr_create_(struct nvkm_object *parent, struct nvkm_object *engine, 70 struct nvkm_oclass *oclass, bool enable, 71 int length, void **pobject) 72 { 73 struct nvkm_gr *gr; 74 int ret; 75 76 ret = nvkm_engine_create_(parent, engine, oclass, enable, 77 "gr", "gr", length, pobject); 78 gr = *pobject; 79 if (ret) 80 return ret; 81 82 gr->engine.func = &nvkm_gr; 83 return 0; 84 } 85