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 void 29 nvkm_gr_tile(struct nvkm_engine *engine, int region, struct nvkm_fb_tile *tile) 30 { 31 struct nvkm_gr *gr = nvkm_gr(engine); 32 if (gr->func->tile) 33 gr->func->tile(gr, region, tile); 34 } 35 36 u64 37 nvkm_gr_units(struct nvkm_gr *gr) 38 { 39 if (gr->func->units) 40 return gr->func->units(gr); 41 return 0; 42 } 43 44 int 45 nvkm_gr_tlb_flush(struct nvkm_gr *gr) 46 { 47 if (gr->func->tlb_flush) 48 return gr->func->tlb_flush(gr); 49 return -ENODEV; 50 } 51 52 static int 53 nvkm_gr_oclass_get(struct nvkm_oclass *oclass, int index) 54 { 55 struct nvkm_gr *gr = nvkm_gr(oclass->engine); 56 int c = 0; 57 58 if (gr->func->object_get) { 59 int ret = gr->func->object_get(gr, index, &oclass->base); 60 if (oclass->base.oclass) 61 return index; 62 return ret; 63 } 64 65 while (gr->func->sclass[c].oclass) { 66 if (c++ == index) { 67 oclass->base = gr->func->sclass[index]; 68 return index; 69 } 70 } 71 72 return c; 73 } 74 75 static int 76 nvkm_gr_cclass_new(struct nvkm_fifo_chan *chan, 77 const struct nvkm_oclass *oclass, 78 struct nvkm_object **pobject) 79 { 80 struct nvkm_gr *gr = nvkm_gr(oclass->engine); 81 if (gr->func->chan_new) 82 return gr->func->chan_new(gr, chan, oclass, pobject); 83 return 0; 84 } 85 86 static void 87 nvkm_gr_intr(struct nvkm_engine *engine) 88 { 89 struct nvkm_gr *gr = nvkm_gr(engine); 90 gr->func->intr(gr); 91 } 92 93 static int 94 nvkm_gr_oneinit(struct nvkm_engine *engine) 95 { 96 struct nvkm_gr *gr = nvkm_gr(engine); 97 if (gr->func->oneinit) 98 return gr->func->oneinit(gr); 99 return 0; 100 } 101 102 static int 103 nvkm_gr_init(struct nvkm_engine *engine) 104 { 105 struct nvkm_gr *gr = nvkm_gr(engine); 106 return gr->func->init(gr); 107 } 108 109 static void * 110 nvkm_gr_dtor(struct nvkm_engine *engine) 111 { 112 struct nvkm_gr *gr = nvkm_gr(engine); 113 if (gr->func->dtor) 114 return gr->func->dtor(gr); 115 return gr; 116 } 117 118 static const struct nvkm_engine_func 119 nvkm_gr = { 120 .dtor = nvkm_gr_dtor, 121 .oneinit = nvkm_gr_oneinit, 122 .init = nvkm_gr_init, 123 .intr = nvkm_gr_intr, 124 .tile = nvkm_gr_tile, 125 .fifo.cclass = nvkm_gr_cclass_new, 126 .fifo.sclass = nvkm_gr_oclass_get, 127 }; 128 129 int 130 nvkm_gr_ctor(const struct nvkm_gr_func *func, struct nvkm_device *device, 131 int index, bool enable, struct nvkm_gr *gr) 132 { 133 gr->func = func; 134 return nvkm_engine_ctor(&nvkm_gr, device, index, enable, &gr->engine); 135 } 136