1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include "priv.h"
25
26#include <engine/fifo.h>
27
28static void
29nvkm_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
36u64
37nvkm_gr_units(struct nvkm_gr *gr)
38{
39 if (gr->func->units)
40 return gr->func->units(gr);
41 return 0;
42}
43
44int
45nvkm_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
52static int
53nvkm_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
75static int
76nvkm_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
86static void
87nvkm_gr_intr(struct nvkm_engine *engine)
88{
89 struct nvkm_gr *gr = nvkm_gr(engine);
90 gr->func->intr(gr);
91}
92
93static int
94nvkm_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
102static int
103nvkm_gr_init(struct nvkm_engine *engine)
104{
105 struct nvkm_gr *gr = nvkm_gr(engine);
106 return gr->func->init(gr);
107}
108
109static void *
110nvkm_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
118static const struct nvkm_engine_func
119nvkm_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
129int
130nvkm_gr_ctor(const struct nvkm_gr_func *func, struct nvkm_device *device,
131 int index, u32 pmc_enable, bool enable, struct nvkm_gr *gr)
132{
133 gr->func = func;
134 return nvkm_engine_ctor(&nvkm_gr, device, index, pmc_enable,
135 enable, &gr->engine);
136}
137