Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / drivers / gpu / drm / nouveau / nvkm / engine / gr / base.c
blobcd8cf6f7024c2c4b916ae20b1fda7e2ded9080e0
1 /*
2 * Copyright 2015 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
22 * Authors: Ben Skeggs <bskeggs@redhat.com>
24 #include "priv.h"
26 #include <engine/fifo.h>
28 static bool
29 nvkm_gr_chsw_load(struct nvkm_engine *engine)
31 struct nvkm_gr *gr = nvkm_gr(engine);
32 if (gr->func->chsw_load)
33 return gr->func->chsw_load(gr);
34 return false;
37 static void
38 nvkm_gr_tile(struct nvkm_engine *engine, int region, struct nvkm_fb_tile *tile)
40 struct nvkm_gr *gr = nvkm_gr(engine);
41 if (gr->func->tile)
42 gr->func->tile(gr, region, tile);
45 u64
46 nvkm_gr_units(struct nvkm_gr *gr)
48 if (gr->func->units)
49 return gr->func->units(gr);
50 return 0;
53 int
54 nvkm_gr_tlb_flush(struct nvkm_gr *gr)
56 if (gr->func->tlb_flush)
57 return gr->func->tlb_flush(gr);
58 return -ENODEV;
61 static int
62 nvkm_gr_oclass_get(struct nvkm_oclass *oclass, int index)
64 struct nvkm_gr *gr = nvkm_gr(oclass->engine);
65 int c = 0;
67 if (gr->func->object_get) {
68 int ret = gr->func->object_get(gr, index, &oclass->base);
69 if (oclass->base.oclass)
70 return index;
71 return ret;
74 while (gr->func->sclass[c].oclass) {
75 if (c++ == index) {
76 oclass->base = gr->func->sclass[index];
77 return index;
81 return c;
84 static int
85 nvkm_gr_cclass_new(struct nvkm_fifo_chan *chan,
86 const struct nvkm_oclass *oclass,
87 struct nvkm_object **pobject)
89 struct nvkm_gr *gr = nvkm_gr(oclass->engine);
90 if (gr->func->chan_new)
91 return gr->func->chan_new(gr, chan, oclass, pobject);
92 return 0;
95 static void
96 nvkm_gr_intr(struct nvkm_engine *engine)
98 struct nvkm_gr *gr = nvkm_gr(engine);
99 gr->func->intr(gr);
102 static int
103 nvkm_gr_oneinit(struct nvkm_engine *engine)
105 struct nvkm_gr *gr = nvkm_gr(engine);
106 if (gr->func->oneinit)
107 return gr->func->oneinit(gr);
108 return 0;
111 static int
112 nvkm_gr_init(struct nvkm_engine *engine)
114 struct nvkm_gr *gr = nvkm_gr(engine);
115 return gr->func->init(gr);
118 static int
119 nvkm_gr_fini(struct nvkm_engine *engine, bool suspend)
121 struct nvkm_gr *gr = nvkm_gr(engine);
122 if (gr->func->fini)
123 return gr->func->fini(gr, suspend);
124 return 0;
127 static void *
128 nvkm_gr_dtor(struct nvkm_engine *engine)
130 struct nvkm_gr *gr = nvkm_gr(engine);
131 if (gr->func->dtor)
132 return gr->func->dtor(gr);
133 return gr;
136 static const struct nvkm_engine_func
137 nvkm_gr = {
138 .dtor = nvkm_gr_dtor,
139 .oneinit = nvkm_gr_oneinit,
140 .init = nvkm_gr_init,
141 .fini = nvkm_gr_fini,
142 .intr = nvkm_gr_intr,
143 .tile = nvkm_gr_tile,
144 .chsw_load = nvkm_gr_chsw_load,
145 .fifo.cclass = nvkm_gr_cclass_new,
146 .fifo.sclass = nvkm_gr_oclass_get,
150 nvkm_gr_ctor(const struct nvkm_gr_func *func, struct nvkm_device *device,
151 int index, bool enable, struct nvkm_gr *gr)
153 gr->func = func;
154 return nvkm_engine_ctor(&nvkm_gr, device, index, enable, &gr->engine);