drm/nouveau/fifo: split user classes out from engine implementations
[deliverable/linux.git] / drivers / gpu / drm / nouveau / nvkm / engine / gr / nv20.c
CommitLineData
e3c71eb2
BS
1#include "nv20.h"
2#include "regs.h"
3
93260d3c 4#include <core/client.h>
ebb945a9 5#include <engine/fifo.h>
9a65a38c 6#include <engine/fifo/chan.h>
e3c71eb2
BS
7#include <subdev/fb.h>
8#include <subdev/timer.h>
ebb945a9
BS
9
10/*******************************************************************************
11 * Graphics object classes
12 ******************************************************************************/
13
e3c71eb2 14static struct nvkm_oclass
b8bf04e1
BS
15nv20_gr_sclass[] = {
16 { 0x0012, &nv04_gr_ofuncs, NULL }, /* beta1 */
17 { 0x0019, &nv04_gr_ofuncs, NULL }, /* clip */
18 { 0x0030, &nv04_gr_ofuncs, NULL }, /* null */
19 { 0x0039, &nv04_gr_ofuncs, NULL }, /* m2mf */
20 { 0x0043, &nv04_gr_ofuncs, NULL }, /* rop */
21 { 0x0044, &nv04_gr_ofuncs, NULL }, /* patt */
22 { 0x004a, &nv04_gr_ofuncs, NULL }, /* gdi */
23 { 0x0062, &nv04_gr_ofuncs, NULL }, /* surf2d */
24 { 0x0072, &nv04_gr_ofuncs, NULL }, /* beta4 */
25 { 0x0089, &nv04_gr_ofuncs, NULL }, /* sifm */
26 { 0x008a, &nv04_gr_ofuncs, NULL }, /* ifc */
27 { 0x0096, &nv04_gr_ofuncs, NULL }, /* celcius */
28 { 0x0097, &nv04_gr_ofuncs, NULL }, /* kelvin */
29 { 0x009e, &nv04_gr_ofuncs, NULL }, /* swzsurf */
30 { 0x009f, &nv04_gr_ofuncs, NULL }, /* imageblit */
ebb945a9 31 {},
a0b1de84
BS
32};
33
ebb945a9
BS
34/*******************************************************************************
35 * PGRAPH context
36 ******************************************************************************/
6ee73861 37
ebb945a9 38static int
e3c71eb2
BS
39nv20_gr_context_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
40 struct nvkm_oclass *oclass, void *data, u32 size,
41 struct nvkm_object **pobject)
a0b1de84 42{
b8bf04e1 43 struct nv20_gr_chan *chan;
142ea05f 44 struct nvkm_gpuobj *image;
ebb945a9 45 int ret, i;
a0b1de84 46
e3c71eb2
BS
47 ret = nvkm_gr_context_create(parent, engine, oclass, NULL, 0x37f0,
48 16, NVOBJ_FLAG_ZERO_ALLOC, &chan);
ebb945a9
BS
49 *pobject = nv_object(chan);
50 if (ret)
51 return ret;
a0b1de84 52
e3c71eb2 53 chan->chid = nvkm_fifo_chan(parent)->chid;
142ea05f
BS
54 image = &chan->base.base.gpuobj;
55
56 nvkm_kmap(image);
57 nvkm_wo32(image, 0x0000, 0x00000001 | (chan->chid << 24));
58 nvkm_wo32(image, 0x033c, 0xffff0000);
59 nvkm_wo32(image, 0x03a0, 0x0fff0000);
60 nvkm_wo32(image, 0x03a4, 0x0fff0000);
61 nvkm_wo32(image, 0x047c, 0x00000101);
62 nvkm_wo32(image, 0x0490, 0x00000111);
63 nvkm_wo32(image, 0x04a8, 0x44400000);
6ee73861 64 for (i = 0x04d4; i <= 0x04e0; i += 4)
142ea05f 65 nvkm_wo32(image, i, 0x00030303);
6ee73861 66 for (i = 0x04f4; i <= 0x0500; i += 4)
142ea05f 67 nvkm_wo32(image, i, 0x00080000);
6ee73861 68 for (i = 0x050c; i <= 0x0518; i += 4)
142ea05f 69 nvkm_wo32(image, i, 0x01012000);
6ee73861 70 for (i = 0x051c; i <= 0x0528; i += 4)
142ea05f 71 nvkm_wo32(image, i, 0x000105b8);
6ee73861 72 for (i = 0x052c; i <= 0x0538; i += 4)
142ea05f 73 nvkm_wo32(image, i, 0x00080008);
6ee73861 74 for (i = 0x055c; i <= 0x0598; i += 4)
142ea05f
BS
75 nvkm_wo32(image, i, 0x07ff0000);
76 nvkm_wo32(image, 0x05a4, 0x4b7fffff);
77 nvkm_wo32(image, 0x05fc, 0x00000001);
78 nvkm_wo32(image, 0x0604, 0x00004000);
79 nvkm_wo32(image, 0x0610, 0x00000001);
80 nvkm_wo32(image, 0x0618, 0x00040000);
81 nvkm_wo32(image, 0x061c, 0x00010000);
6ee73861 82 for (i = 0x1c1c; i <= 0x248c; i += 16) {
142ea05f
BS
83 nvkm_wo32(image, (i + 0), 0x10700ff9);
84 nvkm_wo32(image, (i + 4), 0x0436086c);
85 nvkm_wo32(image, (i + 8), 0x000c001b);
6ee73861 86 }
142ea05f
BS
87 nvkm_wo32(image, 0x281c, 0x3f800000);
88 nvkm_wo32(image, 0x2830, 0x3f800000);
89 nvkm_wo32(image, 0x285c, 0x40000000);
90 nvkm_wo32(image, 0x2860, 0x3f800000);
91 nvkm_wo32(image, 0x2864, 0x3f000000);
92 nvkm_wo32(image, 0x286c, 0x40000000);
93 nvkm_wo32(image, 0x2870, 0x3f800000);
94 nvkm_wo32(image, 0x2878, 0xbf800000);
95 nvkm_wo32(image, 0x2880, 0xbf800000);
96 nvkm_wo32(image, 0x34a4, 0x000fe000);
97 nvkm_wo32(image, 0x3530, 0x000003f8);
98 nvkm_wo32(image, 0x3540, 0x002fe000);
6ee73861 99 for (i = 0x355c; i <= 0x3578; i += 4)
142ea05f
BS
100 nvkm_wo32(image, i, 0x001c527c);
101 nvkm_done(image);
ebb945a9 102 return 0;
6ee73861
BS
103}
104
ebb945a9 105int
e3c71eb2 106nv20_gr_context_init(struct nvkm_object *object)
6ee73861 107{
bfee3f3d 108 struct nv20_gr *gr = (void *)object->engine;
b8bf04e1 109 struct nv20_gr_chan *chan = (void *)object;
ebb945a9 110 int ret;
6ee73861 111
e3c71eb2 112 ret = nvkm_gr_context_init(&chan->base);
ebb945a9
BS
113 if (ret)
114 return ret;
6ee73861 115
142ea05f
BS
116 nvkm_kmap(gr->ctxtab);
117 nvkm_wo32(gr->ctxtab, chan->chid * 4, nv_gpuobj(chan)->addr >> 4);
118 nvkm_done(gr->ctxtab);
ebb945a9 119 return 0;
6ee73861
BS
120}
121
ebb945a9 122int
e3c71eb2 123nv20_gr_context_fini(struct nvkm_object *object, bool suspend)
6ee73861 124{
bfee3f3d 125 struct nv20_gr *gr = (void *)object->engine;
b8bf04e1 126 struct nv20_gr_chan *chan = (void *)object;
276836d4 127 struct nvkm_device *device = gr->base.engine.subdev.device;
ebb945a9
BS
128 int chid = -1;
129
276836d4
BS
130 nvkm_mask(device, 0x400720, 0x00000001, 0x00000000);
131 if (nvkm_rd32(device, 0x400144) & 0x00010000)
132 chid = (nvkm_rd32(device, 0x400148) & 0x1f000000) >> 24;
ebb945a9 133 if (chan->chid == chid) {
276836d4
BS
134 nvkm_wr32(device, 0x400784, nv_gpuobj(chan)->addr >> 4);
135 nvkm_wr32(device, 0x400788, 0x00000002);
c4584adc
BS
136 nvkm_msec(device, 2000,
137 if (!nvkm_rd32(device, 0x400700))
138 break;
139 );
276836d4
BS
140 nvkm_wr32(device, 0x400144, 0x10000000);
141 nvkm_mask(device, 0x400148, 0xff000000, 0x1f000000);
6ee73861 142 }
276836d4 143 nvkm_mask(device, 0x400720, 0x00000001, 0x00000001);
6ee73861 144
142ea05f
BS
145 nvkm_kmap(gr->ctxtab);
146 nvkm_wo32(gr->ctxtab, chan->chid * 4, 0x00000000);
147 nvkm_done(gr->ctxtab);
a65955e1 148
e3c71eb2 149 return nvkm_gr_context_fini(&chan->base, suspend);
6ee73861
BS
150}
151
e3c71eb2 152static struct nvkm_oclass
b8bf04e1 153nv20_gr_cclass = {
ebb945a9 154 .handle = NV_ENGCTX(GR, 0x20),
e3c71eb2 155 .ofuncs = &(struct nvkm_ofuncs) {
b8bf04e1 156 .ctor = nv20_gr_context_ctor,
e3c71eb2 157 .dtor = _nvkm_gr_context_dtor,
b8bf04e1
BS
158 .init = nv20_gr_context_init,
159 .fini = nv20_gr_context_fini,
e3c71eb2
BS
160 .rd32 = _nvkm_gr_context_rd32,
161 .wr32 = _nvkm_gr_context_wr32,
ebb945a9
BS
162 },
163};
6ee73861 164
ebb945a9
BS
165/*******************************************************************************
166 * PGRAPH engine/subdev functions
167 ******************************************************************************/
6ee73861
BS
168
169void
e3c71eb2 170nv20_gr_tile_prog(struct nvkm_engine *engine, int i)
6ee73861 171{
bfee3f3d 172 struct nv20_gr *gr = (void *)engine;
276836d4
BS
173 struct nvkm_device *device = gr->base.engine.subdev.device;
174 struct nvkm_fifo *fifo = device->fifo;
175 struct nvkm_fb_tile *tile = &device->fb->tile.region[i];
3945e475 176 unsigned long flags;
6ee73861 177
6189f1b0 178 fifo->pause(fifo, &flags);
bfee3f3d 179 nv04_gr_idle(gr);
3945e475 180
276836d4
BS
181 nvkm_wr32(device, NV20_PGRAPH_TLIMIT(i), tile->limit);
182 nvkm_wr32(device, NV20_PGRAPH_TSIZE(i), tile->pitch);
183 nvkm_wr32(device, NV20_PGRAPH_TILE(i), tile->addr);
3945e475 184
276836d4
BS
185 nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00EA0030 + 4 * i);
186 nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, tile->limit);
187 nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00EA0050 + 4 * i);
188 nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, tile->pitch);
189 nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00EA0010 + 4 * i);
190 nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, tile->addr);
3945e475 191
fafa0cb3 192 if (nv_device(engine)->chipset != 0x34) {
276836d4
BS
193 nvkm_wr32(device, NV20_PGRAPH_ZCOMP(i), tile->zcomp);
194 nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00ea0090 + 4 * i);
195 nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, tile->zcomp);
ebb945a9 196 }
6ee73861 197
6189f1b0 198 fifo->start(fifo, &flags);
6ee73861
BS
199}
200
ebb945a9 201void
e3c71eb2 202nv20_gr_intr(struct nvkm_subdev *subdev)
0d87c100 203{
bfee3f3d 204 struct nv20_gr *gr = (void *)subdev;
276836d4 205 struct nvkm_device *device = gr->base.engine.subdev.device;
a65955e1 206 struct nvkm_fifo_chan *chan;
276836d4
BS
207 u32 stat = nvkm_rd32(device, NV03_PGRAPH_INTR);
208 u32 nsource = nvkm_rd32(device, NV03_PGRAPH_NSOURCE);
209 u32 nstatus = nvkm_rd32(device, NV03_PGRAPH_NSTATUS);
210 u32 addr = nvkm_rd32(device, NV04_PGRAPH_TRAPPED_ADDR);
ebb945a9
BS
211 u32 chid = (addr & 0x01f00000) >> 20;
212 u32 subc = (addr & 0x00070000) >> 16;
213 u32 mthd = (addr & 0x00001ffc);
276836d4
BS
214 u32 data = nvkm_rd32(device, NV04_PGRAPH_TRAPPED_DATA);
215 u32 class = nvkm_rd32(device, 0x400160 + subc * 4) & 0xfff;
ebb945a9 216 u32 show = stat;
109c2f2f 217 char msg[128], src[128], sta[128];
a65955e1 218 unsigned long flags;
ebb945a9 219
a65955e1 220 chan = nvkm_fifo_chan_chid(device->fifo, chid, &flags);
87a326a3 221
276836d4
BS
222 nvkm_wr32(device, NV03_PGRAPH_INTR, stat);
223 nvkm_wr32(device, NV04_PGRAPH_FIFO, 0x00000001);
ebb945a9
BS
224
225 if (show) {
109c2f2f
BS
226 nvkm_snprintbf(msg, sizeof(msg), nv10_gr_intr_name, show);
227 nvkm_snprintbf(src, sizeof(src), nv04_gr_nsource, nsource);
228 nvkm_snprintbf(sta, sizeof(sta), nv10_gr_nstatus, nstatus);
229 nvkm_error(subdev, "intr %08x [%s] nsource %08x [%s] "
230 "nstatus %08x [%s] ch %d [%s] subc %d "
231 "class %04x mthd %04x data %08x\n",
232 show, msg, nsource, src, nstatus, sta, chid,
a65955e1 233 nvkm_client_name(chan), subc, class, mthd, data);
6ee73861 234 }
72a14827 235
a65955e1 236 nvkm_fifo_chan_put(device->fifo, flags, &chan);
ebb945a9 237}
6ee73861 238
ebb945a9 239static int
e3c71eb2
BS
240nv20_gr_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
241 struct nvkm_oclass *oclass, void *data, u32 size,
242 struct nvkm_object **pobject)
ebb945a9 243{
227c95d9 244 struct nvkm_device *device = (void *)parent;
bfee3f3d 245 struct nv20_gr *gr;
ebb945a9 246 int ret;
6ee73861 247
bfee3f3d
BS
248 ret = nvkm_gr_create(parent, engine, oclass, true, &gr);
249 *pobject = nv_object(gr);
ebb945a9
BS
250 if (ret)
251 return ret;
6ee73861 252
227c95d9
BS
253 ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST, 32 * 4, 16, true,
254 &gr->ctxtab);
ebb945a9
BS
255 if (ret)
256 return ret;
6ee73861 257
bfee3f3d
BS
258 nv_subdev(gr)->unit = 0x00001000;
259 nv_subdev(gr)->intr = nv20_gr_intr;
260 nv_engine(gr)->cclass = &nv20_gr_cclass;
261 nv_engine(gr)->sclass = nv20_gr_sclass;
262 nv_engine(gr)->tile_prog = nv20_gr_tile_prog;
6ee73861
BS
263 return 0;
264}
265
ebb945a9 266void
e3c71eb2 267nv20_gr_dtor(struct nvkm_object *object)
6ee73861 268{
bfee3f3d 269 struct nv20_gr *gr = (void *)object;
227c95d9 270 nvkm_memory_del(&gr->ctxtab);
bfee3f3d 271 nvkm_gr_destroy(&gr->base);
ebb945a9 272}
6ee73861 273
ebb945a9 274int
e3c71eb2 275nv20_gr_init(struct nvkm_object *object)
ebb945a9 276{
e3c71eb2 277 struct nvkm_engine *engine = nv_engine(object);
bfee3f3d 278 struct nv20_gr *gr = (void *)engine;
276836d4
BS
279 struct nvkm_device *device = gr->base.engine.subdev.device;
280 struct nvkm_fb *fb = device->fb;
ebb945a9
BS
281 u32 tmp, vramsz;
282 int ret, i;
6ee73861 283
bfee3f3d 284 ret = nvkm_gr_init(&gr->base);
ebb945a9
BS
285 if (ret)
286 return ret;
6ee73861 287
227c95d9
BS
288 nvkm_wr32(device, NV20_PGRAPH_CHANNEL_CTX_TABLE,
289 nvkm_memory_addr(gr->ctxtab) >> 4);
6ee73861 290
bfee3f3d 291 if (nv_device(gr)->chipset == 0x20) {
276836d4 292 nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x003d0000);
ebb945a9 293 for (i = 0; i < 15; i++)
276836d4 294 nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, 0x00000000);
c4584adc
BS
295 nvkm_msec(device, 2000,
296 if (!nvkm_rd32(device, 0x400700))
297 break;
298 );
ebb945a9 299 } else {
276836d4 300 nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x02c80000);
ebb945a9 301 for (i = 0; i < 32; i++)
276836d4 302 nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, 0x00000000);
c4584adc
BS
303 nvkm_msec(device, 2000,
304 if (!nvkm_rd32(device, 0x400700))
305 break;
306 );
6ee73861
BS
307 }
308
276836d4
BS
309 nvkm_wr32(device, NV03_PGRAPH_INTR , 0xFFFFFFFF);
310 nvkm_wr32(device, NV03_PGRAPH_INTR_EN, 0xFFFFFFFF);
6ee73861 311
276836d4
BS
312 nvkm_wr32(device, NV04_PGRAPH_DEBUG_0, 0xFFFFFFFF);
313 nvkm_wr32(device, NV04_PGRAPH_DEBUG_0, 0x00000000);
314 nvkm_wr32(device, NV04_PGRAPH_DEBUG_1, 0x00118700);
315 nvkm_wr32(device, NV04_PGRAPH_DEBUG_3, 0xF3CE0475); /* 0x4 = auto ctx switch */
316 nvkm_wr32(device, NV10_PGRAPH_DEBUG_4, 0x00000000);
317 nvkm_wr32(device, 0x40009C , 0x00000040);
274fec93 318
bfee3f3d 319 if (nv_device(gr)->chipset >= 0x25) {
276836d4
BS
320 nvkm_wr32(device, 0x400890, 0x00a8cfff);
321 nvkm_wr32(device, 0x400610, 0x304B1FB6);
322 nvkm_wr32(device, 0x400B80, 0x1cbd3883);
323 nvkm_wr32(device, 0x400B84, 0x44000000);
324 nvkm_wr32(device, 0x400098, 0x40000080);
325 nvkm_wr32(device, 0x400B88, 0x000000ff);
274fec93 326
ebb945a9 327 } else {
276836d4
BS
328 nvkm_wr32(device, 0x400880, 0x0008c7df);
329 nvkm_wr32(device, 0x400094, 0x00000005);
330 nvkm_wr32(device, 0x400B80, 0x45eae20e);
331 nvkm_wr32(device, 0x400B84, 0x24000000);
332 nvkm_wr32(device, 0x400098, 0x00000040);
333 nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00E00038);
334 nvkm_wr32(device, NV10_PGRAPH_RDI_DATA , 0x00000030);
335 nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00E10038);
336 nvkm_wr32(device, NV10_PGRAPH_RDI_DATA , 0x00000030);
274fec93 337 }
a0b1de84 338
ebb945a9 339 /* Turn all the tiling regions off. */
b1e4553c 340 for (i = 0; i < fb->tile.regions; i++)
ebb945a9 341 engine->tile_prog(engine, i);
a0b1de84 342
276836d4
BS
343 nvkm_wr32(device, 0x4009a0, nvkm_rd32(device, 0x100324));
344 nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00EA000C);
345 nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, nvkm_rd32(device, 0x100324));
a0b1de84 346
276836d4
BS
347 nvkm_wr32(device, NV10_PGRAPH_CTX_CONTROL, 0x10000100);
348 nvkm_wr32(device, NV10_PGRAPH_STATE , 0xFFFFFFFF);
a0b1de84 349
276836d4
BS
350 tmp = nvkm_rd32(device, NV10_PGRAPH_SURFACE) & 0x0007ff00;
351 nvkm_wr32(device, NV10_PGRAPH_SURFACE, tmp);
352 tmp = nvkm_rd32(device, NV10_PGRAPH_SURFACE) | 0x00020100;
353 nvkm_wr32(device, NV10_PGRAPH_SURFACE, tmp);
a0b1de84 354
ebb945a9 355 /* begin RAM config */
bfee3f3d 356 vramsz = nv_device_resource_len(nv_device(gr), 1) - 1;
276836d4
BS
357 nvkm_wr32(device, 0x4009A4, nvkm_rd32(device, 0x100200));
358 nvkm_wr32(device, 0x4009A8, nvkm_rd32(device, 0x100204));
359 nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00EA0000);
360 nvkm_wr32(device, NV10_PGRAPH_RDI_DATA , nvkm_rd32(device, 0x100200));
361 nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00EA0004);
362 nvkm_wr32(device, NV10_PGRAPH_RDI_DATA , nvkm_rd32(device, 0x100204));
363 nvkm_wr32(device, 0x400820, 0);
364 nvkm_wr32(device, 0x400824, 0);
365 nvkm_wr32(device, 0x400864, vramsz - 1);
366 nvkm_wr32(device, 0x400868, vramsz - 1);
a0b1de84 367
ebb945a9 368 /* interesting.. the below overwrites some of the tile setup above.. */
276836d4
BS
369 nvkm_wr32(device, 0x400B20, 0x00000000);
370 nvkm_wr32(device, 0x400B04, 0xFFFFFFFF);
a0b1de84 371
276836d4
BS
372 nvkm_wr32(device, NV03_PGRAPH_ABS_UCLIP_XMIN, 0);
373 nvkm_wr32(device, NV03_PGRAPH_ABS_UCLIP_YMIN, 0);
374 nvkm_wr32(device, NV03_PGRAPH_ABS_UCLIP_XMAX, 0x7fff);
375 nvkm_wr32(device, NV03_PGRAPH_ABS_UCLIP_YMAX, 0x7fff);
a0b1de84
BS
376 return 0;
377}
ebb945a9 378
e3c71eb2 379struct nvkm_oclass
b8bf04e1 380nv20_gr_oclass = {
ebb945a9 381 .handle = NV_ENGINE(GR, 0x20),
e3c71eb2 382 .ofuncs = &(struct nvkm_ofuncs) {
b8bf04e1
BS
383 .ctor = nv20_gr_ctor,
384 .dtor = nv20_gr_dtor,
385 .init = nv20_gr_init,
e3c71eb2 386 .fini = _nvkm_gr_fini,
ebb945a9
BS
387 },
388};
This page took 0.488947 seconds and 5 git commands to generate.