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