posix-clock: Fix return code on the poll method's error path
[linux/fpc-iii.git] / drivers / gpu / drm / nouveau / nvkm / engine / gr / base.c
blob090765ff070debcb2f33e9361f6dc27c20576caa
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 void
29 nvkm_gr_tile(struct nvkm_engine *engine, int region, struct nvkm_fb_tile *tile)
31 struct nvkm_gr *gr = nvkm_gr(engine);
32 if (gr->func->tile)
33 gr->func->tile(gr, region, tile);
36 u64
37 nvkm_gr_units(struct nvkm_gr *gr)
39 if (gr->func->units)
40 return gr->func->units(gr);
41 return 0;
44 int
45 nvkm_gr_tlb_flush(struct nvkm_gr *gr)
47 if (gr->func->tlb_flush)
48 return gr->func->tlb_flush(gr);
49 return -ENODEV;
52 static int
53 nvkm_gr_oclass_get(struct nvkm_oclass *oclass, int index)
55 struct nvkm_gr *gr = nvkm_gr(oclass->engine);
56 int c = 0;
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;
65 while (gr->func->sclass[c].oclass) {
66 if (c++ == index) {
67 oclass->base = gr->func->sclass[index];
68 return index;
72 return c;
75 static int
76 nvkm_gr_cclass_new(struct nvkm_fifo_chan *chan,
77 const struct nvkm_oclass *oclass,
78 struct nvkm_object **pobject)
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;
86 static void
87 nvkm_gr_intr(struct nvkm_engine *engine)
89 struct nvkm_gr *gr = nvkm_gr(engine);
90 gr->func->intr(gr);
93 static int
94 nvkm_gr_oneinit(struct nvkm_engine *engine)
96 struct nvkm_gr *gr = nvkm_gr(engine);
97 if (gr->func->oneinit)
98 return gr->func->oneinit(gr);
99 return 0;
102 static int
103 nvkm_gr_init(struct nvkm_engine *engine)
105 struct nvkm_gr *gr = nvkm_gr(engine);
106 return gr->func->init(gr);
109 static void *
110 nvkm_gr_dtor(struct nvkm_engine *engine)
112 struct nvkm_gr *gr = nvkm_gr(engine);
113 if (gr->func->dtor)
114 return gr->func->dtor(gr);
115 return gr;
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,
130 nvkm_gr_ctor(const struct nvkm_gr_func *func, struct nvkm_device *device,
131 int index, u32 pmc_enable, bool enable, struct nvkm_gr *gr)
133 gr->func = func;
134 return nvkm_engine_ctor(&nvkm_gr, device, index, pmc_enable,
135 enable, &gr->engine);