]>
Commit | Line | Data |
---|---|---|
4b223eef | 1 | /* |
ebb945a9 | 2 | * Copyright 2012 Red Hat Inc. |
4b223eef BS |
3 | * |
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: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | * | |
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. | |
21 | * | |
22 | * Authors: Ben Skeggs | |
23 | */ | |
e3c71eb2 BS |
24 | #include "gf100.h" |
25 | #include "ctxgf100.h" | |
26 | #include "fuc/os.h" | |
27 | ||
28 | #include <core/client.h> | |
e3c71eb2 | 29 | #include <core/option.h> |
33bcb4c3 | 30 | #include <core/firmware.h> |
e3c71eb2 BS |
31 | #include <subdev/fb.h> |
32 | #include <subdev/mc.h> | |
c85ee6ca | 33 | #include <subdev/pmu.h> |
e3c71eb2 | 34 | #include <subdev/timer.h> |
a65955e1 | 35 | #include <engine/fifo.h> |
e3c71eb2 BS |
36 | |
37 | #include <nvif/class.h> | |
53a6df77 | 38 | #include <nvif/cl9097.h> |
e3c71eb2 | 39 | #include <nvif/unpack.h> |
0411de85 | 40 | |
ac9738bb BS |
41 | /******************************************************************************* |
42 | * Zero Bandwidth Clear | |
43 | ******************************************************************************/ | |
44 | ||
45 | static void | |
bfee3f3d | 46 | gf100_gr_zbc_clear_color(struct gf100_gr *gr, int zbc) |
ac9738bb | 47 | { |
276836d4 | 48 | struct nvkm_device *device = gr->base.engine.subdev.device; |
bfee3f3d | 49 | if (gr->zbc_color[zbc].format) { |
276836d4 BS |
50 | nvkm_wr32(device, 0x405804, gr->zbc_color[zbc].ds[0]); |
51 | nvkm_wr32(device, 0x405808, gr->zbc_color[zbc].ds[1]); | |
52 | nvkm_wr32(device, 0x40580c, gr->zbc_color[zbc].ds[2]); | |
53 | nvkm_wr32(device, 0x405810, gr->zbc_color[zbc].ds[3]); | |
54 | } | |
55 | nvkm_wr32(device, 0x405814, gr->zbc_color[zbc].format); | |
56 | nvkm_wr32(device, 0x405820, zbc); | |
57 | nvkm_wr32(device, 0x405824, 0x00000004); /* TRIGGER | WRITE | COLOR */ | |
ac9738bb BS |
58 | } |
59 | ||
60 | static int | |
bfee3f3d | 61 | gf100_gr_zbc_color_get(struct gf100_gr *gr, int format, |
e3c71eb2 | 62 | const u32 ds[4], const u32 l2[4]) |
ac9738bb | 63 | { |
70bc7182 | 64 | struct nvkm_ltc *ltc = gr->base.engine.subdev.device->ltc; |
ac9738bb BS |
65 | int zbc = -ENOSPC, i; |
66 | ||
67 | for (i = ltc->zbc_min; i <= ltc->zbc_max; i++) { | |
bfee3f3d BS |
68 | if (gr->zbc_color[i].format) { |
69 | if (gr->zbc_color[i].format != format) | |
ac9738bb | 70 | continue; |
bfee3f3d BS |
71 | if (memcmp(gr->zbc_color[i].ds, ds, sizeof( |
72 | gr->zbc_color[i].ds))) | |
ac9738bb | 73 | continue; |
bfee3f3d BS |
74 | if (memcmp(gr->zbc_color[i].l2, l2, sizeof( |
75 | gr->zbc_color[i].l2))) { | |
ac9738bb BS |
76 | WARN_ON(1); |
77 | return -EINVAL; | |
78 | } | |
79 | return i; | |
80 | } else { | |
81 | zbc = (zbc < 0) ? i : zbc; | |
82 | } | |
83 | } | |
84 | ||
da7c74ea BS |
85 | if (zbc < 0) |
86 | return zbc; | |
87 | ||
bfee3f3d BS |
88 | memcpy(gr->zbc_color[zbc].ds, ds, sizeof(gr->zbc_color[zbc].ds)); |
89 | memcpy(gr->zbc_color[zbc].l2, l2, sizeof(gr->zbc_color[zbc].l2)); | |
90 | gr->zbc_color[zbc].format = format; | |
70bc7182 | 91 | nvkm_ltc_zbc_color_get(ltc, zbc, l2); |
bfee3f3d | 92 | gf100_gr_zbc_clear_color(gr, zbc); |
ac9738bb BS |
93 | return zbc; |
94 | } | |
95 | ||
96 | static void | |
bfee3f3d | 97 | gf100_gr_zbc_clear_depth(struct gf100_gr *gr, int zbc) |
ac9738bb | 98 | { |
276836d4 | 99 | struct nvkm_device *device = gr->base.engine.subdev.device; |
bfee3f3d | 100 | if (gr->zbc_depth[zbc].format) |
276836d4 BS |
101 | nvkm_wr32(device, 0x405818, gr->zbc_depth[zbc].ds); |
102 | nvkm_wr32(device, 0x40581c, gr->zbc_depth[zbc].format); | |
103 | nvkm_wr32(device, 0x405820, zbc); | |
104 | nvkm_wr32(device, 0x405824, 0x00000005); /* TRIGGER | WRITE | DEPTH */ | |
ac9738bb BS |
105 | } |
106 | ||
107 | static int | |
bfee3f3d | 108 | gf100_gr_zbc_depth_get(struct gf100_gr *gr, int format, |
e3c71eb2 | 109 | const u32 ds, const u32 l2) |
ac9738bb | 110 | { |
70bc7182 | 111 | struct nvkm_ltc *ltc = gr->base.engine.subdev.device->ltc; |
ac9738bb BS |
112 | int zbc = -ENOSPC, i; |
113 | ||
114 | for (i = ltc->zbc_min; i <= ltc->zbc_max; i++) { | |
bfee3f3d BS |
115 | if (gr->zbc_depth[i].format) { |
116 | if (gr->zbc_depth[i].format != format) | |
ac9738bb | 117 | continue; |
bfee3f3d | 118 | if (gr->zbc_depth[i].ds != ds) |
ac9738bb | 119 | continue; |
bfee3f3d | 120 | if (gr->zbc_depth[i].l2 != l2) { |
ac9738bb BS |
121 | WARN_ON(1); |
122 | return -EINVAL; | |
123 | } | |
124 | return i; | |
125 | } else { | |
126 | zbc = (zbc < 0) ? i : zbc; | |
127 | } | |
128 | } | |
129 | ||
da7c74ea BS |
130 | if (zbc < 0) |
131 | return zbc; | |
132 | ||
bfee3f3d BS |
133 | gr->zbc_depth[zbc].format = format; |
134 | gr->zbc_depth[zbc].ds = ds; | |
135 | gr->zbc_depth[zbc].l2 = l2; | |
70bc7182 | 136 | nvkm_ltc_zbc_depth_get(ltc, zbc, l2); |
bfee3f3d | 137 | gf100_gr_zbc_clear_depth(gr, zbc); |
ac9738bb BS |
138 | return zbc; |
139 | } | |
140 | ||
ebb945a9 BS |
141 | /******************************************************************************* |
142 | * Graphics object classes | |
143 | ******************************************************************************/ | |
5bf561ee BS |
144 | #define gf100_gr_object(p) container_of((p), struct gf100_gr_object, object) |
145 | ||
146 | struct gf100_gr_object { | |
147 | struct nvkm_object object; | |
148 | struct gf100_gr_chan *chan; | |
149 | }; | |
ebb945a9 | 150 | |
ac9738bb | 151 | static int |
e3c71eb2 | 152 | gf100_fermi_mthd_zbc_color(struct nvkm_object *object, void *data, u32 size) |
ac9738bb | 153 | { |
0d7fc246 | 154 | struct gf100_gr *gr = gf100_gr(nvkm_gr(object->engine)); |
ac9738bb BS |
155 | union { |
156 | struct fermi_a_zbc_color_v0 v0; | |
157 | } *args = data; | |
f01c4e68 | 158 | int ret = -ENOSYS; |
ac9738bb | 159 | |
f01c4e68 | 160 | if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) { |
ac9738bb BS |
161 | switch (args->v0.format) { |
162 | case FERMI_A_ZBC_COLOR_V0_FMT_ZERO: | |
163 | case FERMI_A_ZBC_COLOR_V0_FMT_UNORM_ONE: | |
164 | case FERMI_A_ZBC_COLOR_V0_FMT_RF32_GF32_BF32_AF32: | |
165 | case FERMI_A_ZBC_COLOR_V0_FMT_R16_G16_B16_A16: | |
166 | case FERMI_A_ZBC_COLOR_V0_FMT_RN16_GN16_BN16_AN16: | |
167 | case FERMI_A_ZBC_COLOR_V0_FMT_RS16_GS16_BS16_AS16: | |
168 | case FERMI_A_ZBC_COLOR_V0_FMT_RU16_GU16_BU16_AU16: | |
169 | case FERMI_A_ZBC_COLOR_V0_FMT_RF16_GF16_BF16_AF16: | |
170 | case FERMI_A_ZBC_COLOR_V0_FMT_A8R8G8B8: | |
171 | case FERMI_A_ZBC_COLOR_V0_FMT_A8RL8GL8BL8: | |
172 | case FERMI_A_ZBC_COLOR_V0_FMT_A2B10G10R10: | |
173 | case FERMI_A_ZBC_COLOR_V0_FMT_AU2BU10GU10RU10: | |
174 | case FERMI_A_ZBC_COLOR_V0_FMT_A8B8G8R8: | |
175 | case FERMI_A_ZBC_COLOR_V0_FMT_A8BL8GL8RL8: | |
176 | case FERMI_A_ZBC_COLOR_V0_FMT_AN8BN8GN8RN8: | |
177 | case FERMI_A_ZBC_COLOR_V0_FMT_AS8BS8GS8RS8: | |
178 | case FERMI_A_ZBC_COLOR_V0_FMT_AU8BU8GU8RU8: | |
179 | case FERMI_A_ZBC_COLOR_V0_FMT_A2R10G10B10: | |
180 | case FERMI_A_ZBC_COLOR_V0_FMT_BF10GF11RF11: | |
bfee3f3d | 181 | ret = gf100_gr_zbc_color_get(gr, args->v0.format, |
e3c71eb2 BS |
182 | args->v0.ds, |
183 | args->v0.l2); | |
ac9738bb BS |
184 | if (ret >= 0) { |
185 | args->v0.index = ret; | |
186 | return 0; | |
187 | } | |
188 | break; | |
189 | default: | |
190 | return -EINVAL; | |
191 | } | |
192 | } | |
193 | ||
194 | return ret; | |
195 | } | |
196 | ||
197 | static int | |
e3c71eb2 | 198 | gf100_fermi_mthd_zbc_depth(struct nvkm_object *object, void *data, u32 size) |
ac9738bb | 199 | { |
0d7fc246 | 200 | struct gf100_gr *gr = gf100_gr(nvkm_gr(object->engine)); |
ac9738bb BS |
201 | union { |
202 | struct fermi_a_zbc_depth_v0 v0; | |
203 | } *args = data; | |
f01c4e68 | 204 | int ret = -ENOSYS; |
ac9738bb | 205 | |
f01c4e68 | 206 | if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) { |
ac9738bb BS |
207 | switch (args->v0.format) { |
208 | case FERMI_A_ZBC_DEPTH_V0_FMT_FP32: | |
bfee3f3d | 209 | ret = gf100_gr_zbc_depth_get(gr, args->v0.format, |
e3c71eb2 BS |
210 | args->v0.ds, |
211 | args->v0.l2); | |
ac9738bb BS |
212 | return (ret >= 0) ? 0 : -ENOSPC; |
213 | default: | |
214 | return -EINVAL; | |
215 | } | |
216 | } | |
217 | ||
218 | return ret; | |
219 | } | |
220 | ||
221 | static int | |
e3c71eb2 | 222 | gf100_fermi_mthd(struct nvkm_object *object, u32 mthd, void *data, u32 size) |
ac9738bb | 223 | { |
f01c4e68 | 224 | nvif_ioctl(object, "fermi mthd %08x\n", mthd); |
ac9738bb BS |
225 | switch (mthd) { |
226 | case FERMI_A_ZBC_COLOR: | |
e3c71eb2 | 227 | return gf100_fermi_mthd_zbc_color(object, data, size); |
ac9738bb | 228 | case FERMI_A_ZBC_DEPTH: |
e3c71eb2 | 229 | return gf100_fermi_mthd_zbc_depth(object, data, size); |
ac9738bb BS |
230 | default: |
231 | break; | |
232 | } | |
233 | return -EINVAL; | |
234 | } | |
235 | ||
27f3d6cf BS |
236 | const struct nvkm_object_func |
237 | gf100_fermi = { | |
e3c71eb2 | 238 | .mthd = gf100_fermi_mthd, |
ac9738bb BS |
239 | }; |
240 | ||
a65955e1 BS |
241 | static void |
242 | gf100_gr_mthd_set_shader_exceptions(struct nvkm_device *device, u32 data) | |
d6bd3803 | 243 | { |
a65955e1 BS |
244 | nvkm_wr32(device, 0x419e44, data ? 0xffffffff : 0x00000000); |
245 | nvkm_wr32(device, 0x419e4c, data ? 0xffffffff : 0x00000000); | |
d6bd3803 BS |
246 | } |
247 | ||
a65955e1 BS |
248 | static bool |
249 | gf100_gr_mthd_sw(struct nvkm_device *device, u16 class, u32 mthd, u32 data) | |
250 | { | |
251 | switch (class & 0x00ff) { | |
252 | case 0x97: | |
253 | case 0xc0: | |
254 | switch (mthd) { | |
255 | case 0x1528: | |
256 | gf100_gr_mthd_set_shader_exceptions(device, data); | |
257 | return true; | |
258 | default: | |
259 | break; | |
260 | } | |
261 | break; | |
262 | default: | |
263 | break; | |
264 | } | |
265 | return false; | |
266 | } | |
d6bd3803 | 267 | |
5bf561ee BS |
268 | static const struct nvkm_object_func |
269 | gf100_gr_object_func = { | |
270 | }; | |
271 | ||
272 | static int | |
273 | gf100_gr_object_new(const struct nvkm_oclass *oclass, void *data, u32 size, | |
274 | struct nvkm_object **pobject) | |
275 | { | |
276 | struct gf100_gr_chan *chan = gf100_gr_chan(oclass->parent); | |
277 | struct gf100_gr_object *object; | |
278 | ||
279 | if (!(object = kzalloc(sizeof(*object), GFP_KERNEL))) | |
280 | return -ENOMEM; | |
281 | *pobject = &object->object; | |
282 | ||
283 | nvkm_object_ctor(oclass->base.func ? oclass->base.func : | |
284 | &gf100_gr_object_func, oclass, &object->object); | |
285 | object->chan = chan; | |
286 | return 0; | |
287 | } | |
288 | ||
27f3d6cf BS |
289 | static int |
290 | gf100_gr_object_get(struct nvkm_gr *base, int index, struct nvkm_sclass *sclass) | |
291 | { | |
292 | struct gf100_gr *gr = gf100_gr(base); | |
293 | int c = 0; | |
294 | ||
295 | while (gr->func->sclass[c].oclass) { | |
296 | if (c++ == index) { | |
297 | *sclass = gr->func->sclass[index]; | |
5bf561ee | 298 | sclass->ctor = gf100_gr_object_new; |
27f3d6cf BS |
299 | return index; |
300 | } | |
301 | } | |
302 | ||
303 | return c; | |
304 | } | |
ebb945a9 | 305 | |
ebb945a9 BS |
306 | /******************************************************************************* |
307 | * PGRAPH context | |
308 | ******************************************************************************/ | |
966a5b7d | 309 | |
27f3d6cf BS |
310 | static int |
311 | gf100_gr_chan_bind(struct nvkm_object *object, struct nvkm_gpuobj *parent, | |
312 | int align, struct nvkm_gpuobj **pgpuobj) | |
966a5b7d | 313 | { |
27f3d6cf BS |
314 | struct gf100_gr_chan *chan = gf100_gr_chan(object); |
315 | struct gf100_gr *gr = chan->gr; | |
316 | int ret, i; | |
317 | ||
318 | ret = nvkm_gpuobj_new(gr->base.engine.subdev.device, gr->size, | |
319 | align, false, parent, pgpuobj); | |
320 | if (ret) | |
321 | return ret; | |
322 | ||
323 | nvkm_kmap(*pgpuobj); | |
324 | for (i = 0; i < gr->size; i += 4) | |
325 | nvkm_wo32(*pgpuobj, i, gr->data[i / 4]); | |
326 | ||
327 | if (!gr->firmware) { | |
328 | nvkm_wo32(*pgpuobj, 0x00, chan->mmio_nr / 2); | |
329 | nvkm_wo32(*pgpuobj, 0x04, chan->mmio_vma.offset >> 8); | |
330 | } else { | |
331 | nvkm_wo32(*pgpuobj, 0xf4, 0); | |
332 | nvkm_wo32(*pgpuobj, 0xf8, 0); | |
333 | nvkm_wo32(*pgpuobj, 0x10, chan->mmio_nr / 2); | |
334 | nvkm_wo32(*pgpuobj, 0x14, lower_32_bits(chan->mmio_vma.offset)); | |
335 | nvkm_wo32(*pgpuobj, 0x18, upper_32_bits(chan->mmio_vma.offset)); | |
336 | nvkm_wo32(*pgpuobj, 0x1c, 1); | |
337 | nvkm_wo32(*pgpuobj, 0x20, 0); | |
338 | nvkm_wo32(*pgpuobj, 0x28, 0); | |
339 | nvkm_wo32(*pgpuobj, 0x2c, 0); | |
340 | } | |
341 | nvkm_done(*pgpuobj); | |
342 | return 0; | |
343 | } | |
344 | ||
345 | static void * | |
346 | gf100_gr_chan_dtor(struct nvkm_object *object) | |
347 | { | |
348 | struct gf100_gr_chan *chan = gf100_gr_chan(object); | |
349 | int i; | |
350 | ||
351 | for (i = 0; i < ARRAY_SIZE(chan->data); i++) { | |
352 | if (chan->data[i].vma.node) { | |
353 | nvkm_vm_unmap(&chan->data[i].vma); | |
354 | nvkm_vm_put(&chan->data[i].vma); | |
355 | } | |
356 | nvkm_memory_del(&chan->data[i].mem); | |
357 | } | |
358 | ||
359 | if (chan->mmio_vma.node) { | |
360 | nvkm_vm_unmap(&chan->mmio_vma); | |
361 | nvkm_vm_put(&chan->mmio_vma); | |
362 | } | |
363 | nvkm_memory_del(&chan->mmio); | |
364 | return chan; | |
365 | } | |
366 | ||
367 | static const struct nvkm_object_func | |
368 | gf100_gr_chan = { | |
369 | .dtor = gf100_gr_chan_dtor, | |
370 | .bind = gf100_gr_chan_bind, | |
371 | }; | |
372 | ||
373 | static int | |
374 | gf100_gr_chan_new(struct nvkm_gr *base, struct nvkm_fifo_chan *fifoch, | |
375 | const struct nvkm_oclass *oclass, | |
376 | struct nvkm_object **pobject) | |
377 | { | |
378 | struct gf100_gr *gr = gf100_gr(base); | |
bfee3f3d BS |
379 | struct gf100_gr_data *data = gr->mmio_data; |
380 | struct gf100_gr_mmio *mmio = gr->mmio_list; | |
e3c71eb2 | 381 | struct gf100_gr_chan *chan; |
227c95d9 | 382 | struct nvkm_device *device = gr->base.engine.subdev.device; |
966a5b7d | 383 | int ret, i; |
966a5b7d | 384 | |
27f3d6cf BS |
385 | if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL))) |
386 | return -ENOMEM; | |
387 | nvkm_object_ctor(&gf100_gr_chan, oclass, &chan->object); | |
388 | chan->gr = gr; | |
389 | *pobject = &chan->object; | |
966a5b7d | 390 | |
ac1499d9 BS |
391 | /* allocate memory for a "mmio list" buffer that's used by the HUB |
392 | * fuc to modify some per-context register settings on first load | |
393 | * of the context. | |
394 | */ | |
227c95d9 BS |
395 | ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST, 0x1000, 0x100, |
396 | false, &chan->mmio); | |
73a60c0d BS |
397 | if (ret) |
398 | return ret; | |
399 | ||
27f3d6cf | 400 | ret = nvkm_vm_get(fifoch->vm, 0x1000, 12, NV_MEM_ACCESS_RW | |
227c95d9 | 401 | NV_MEM_ACCESS_SYS, &chan->mmio_vma); |
73a60c0d BS |
402 | if (ret) |
403 | return ret; | |
404 | ||
227c95d9 BS |
405 | nvkm_memory_map(chan->mmio, &chan->mmio_vma, 0); |
406 | ||
ac1499d9 | 407 | /* allocate buffers referenced by mmio list */ |
bfee3f3d | 408 | for (i = 0; data->size && i < ARRAY_SIZE(gr->mmio_data); i++) { |
227c95d9 BS |
409 | ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST, |
410 | data->size, data->align, false, | |
411 | &chan->data[i].mem); | |
ac1499d9 BS |
412 | if (ret) |
413 | return ret; | |
73a60c0d | 414 | |
27f3d6cf BS |
415 | ret = nvkm_vm_get(fifoch->vm, |
416 | nvkm_memory_size(chan->data[i].mem), 12, | |
417 | data->access, &chan->data[i].vma); | |
ac1499d9 BS |
418 | if (ret) |
419 | return ret; | |
966a5b7d | 420 | |
227c95d9 | 421 | nvkm_memory_map(chan->data[i].mem, &chan->data[i].vma, 0); |
ac1499d9 | 422 | data++; |
966a5b7d BS |
423 | } |
424 | ||
ac1499d9 | 425 | /* finally, fill in the mmio list and point the context at it */ |
142ea05f | 426 | nvkm_kmap(chan->mmio); |
bfee3f3d | 427 | for (i = 0; mmio->addr && i < ARRAY_SIZE(gr->mmio_list); i++) { |
ac1499d9 BS |
428 | u32 addr = mmio->addr; |
429 | u32 data = mmio->data; | |
966a5b7d | 430 | |
694c6caf | 431 | if (mmio->buffer >= 0) { |
ebb945a9 | 432 | u64 info = chan->data[mmio->buffer].vma.offset; |
ac1499d9 BS |
433 | data |= info >> mmio->shift; |
434 | } | |
73a60c0d | 435 | |
142ea05f BS |
436 | nvkm_wo32(chan->mmio, chan->mmio_nr++ * 4, addr); |
437 | nvkm_wo32(chan->mmio, chan->mmio_nr++ * 4, data); | |
ac1499d9 BS |
438 | mmio++; |
439 | } | |
142ea05f | 440 | nvkm_done(chan->mmio); |
ebb945a9 | 441 | return 0; |
4b223eef BS |
442 | } |
443 | ||
ebb945a9 | 444 | /******************************************************************************* |
c33b1e8c | 445 | * PGRAPH register lists |
ebb945a9 BS |
446 | ******************************************************************************/ |
447 | ||
e3c71eb2 BS |
448 | const struct gf100_gr_init |
449 | gf100_gr_init_main_0[] = { | |
30f4e087 BS |
450 | { 0x400080, 1, 0x04, 0x003083c2 }, |
451 | { 0x400088, 1, 0x04, 0x00006fe7 }, | |
452 | { 0x40008c, 1, 0x04, 0x00000000 }, | |
453 | { 0x400090, 1, 0x04, 0x00000030 }, | |
454 | { 0x40013c, 1, 0x04, 0x013901f7 }, | |
455 | { 0x400140, 1, 0x04, 0x00000100 }, | |
456 | { 0x400144, 1, 0x04, 0x00000000 }, | |
457 | { 0x400148, 1, 0x04, 0x00000110 }, | |
458 | { 0x400138, 1, 0x04, 0x00000000 }, | |
459 | { 0x400130, 2, 0x04, 0x00000000 }, | |
460 | { 0x400124, 1, 0x04, 0x00000002 }, | |
461 | {} | |
462 | }; | |
463 | ||
e3c71eb2 BS |
464 | const struct gf100_gr_init |
465 | gf100_gr_init_fe_0[] = { | |
30f4e087 BS |
466 | { 0x40415c, 1, 0x04, 0x00000000 }, |
467 | { 0x404170, 1, 0x04, 0x00000000 }, | |
468 | {} | |
469 | }; | |
470 | ||
e3c71eb2 BS |
471 | const struct gf100_gr_init |
472 | gf100_gr_init_pri_0[] = { | |
30f4e087 BS |
473 | { 0x404488, 2, 0x04, 0x00000000 }, |
474 | {} | |
475 | }; | |
476 | ||
e3c71eb2 BS |
477 | const struct gf100_gr_init |
478 | gf100_gr_init_rstr2d_0[] = { | |
30f4e087 BS |
479 | { 0x407808, 1, 0x04, 0x00000000 }, |
480 | {} | |
481 | }; | |
482 | ||
e3c71eb2 BS |
483 | const struct gf100_gr_init |
484 | gf100_gr_init_pd_0[] = { | |
30f4e087 BS |
485 | { 0x406024, 1, 0x04, 0x00000000 }, |
486 | {} | |
487 | }; | |
488 | ||
e3c71eb2 BS |
489 | const struct gf100_gr_init |
490 | gf100_gr_init_ds_0[] = { | |
30f4e087 BS |
491 | { 0x405844, 1, 0x04, 0x00ffffff }, |
492 | { 0x405850, 1, 0x04, 0x00000000 }, | |
493 | { 0x405908, 1, 0x04, 0x00000000 }, | |
494 | {} | |
495 | }; | |
496 | ||
e3c71eb2 BS |
497 | const struct gf100_gr_init |
498 | gf100_gr_init_scc_0[] = { | |
30f4e087 BS |
499 | { 0x40803c, 1, 0x04, 0x00000000 }, |
500 | {} | |
501 | }; | |
502 | ||
e3c71eb2 BS |
503 | const struct gf100_gr_init |
504 | gf100_gr_init_prop_0[] = { | |
30f4e087 | 505 | { 0x4184a0, 1, 0x04, 0x00000000 }, |
97af71fa BS |
506 | {} |
507 | }; | |
508 | ||
e3c71eb2 BS |
509 | const struct gf100_gr_init |
510 | gf100_gr_init_gpc_unk_0[] = { | |
30f4e087 BS |
511 | { 0x418604, 1, 0x04, 0x00000000 }, |
512 | { 0x418680, 1, 0x04, 0x00000000 }, | |
513 | { 0x418714, 1, 0x04, 0x80000000 }, | |
514 | { 0x418384, 1, 0x04, 0x00000000 }, | |
97af71fa BS |
515 | {} |
516 | }; | |
517 | ||
e3c71eb2 BS |
518 | const struct gf100_gr_init |
519 | gf100_gr_init_setup_0[] = { | |
30f4e087 | 520 | { 0x418814, 3, 0x04, 0x00000000 }, |
97af71fa BS |
521 | {} |
522 | }; | |
523 | ||
e3c71eb2 BS |
524 | const struct gf100_gr_init |
525 | gf100_gr_init_crstr_0[] = { | |
30f4e087 | 526 | { 0x418b04, 1, 0x04, 0x00000000 }, |
97af71fa BS |
527 | {} |
528 | }; | |
529 | ||
e3c71eb2 BS |
530 | const struct gf100_gr_init |
531 | gf100_gr_init_setup_1[] = { | |
30f4e087 BS |
532 | { 0x4188c8, 1, 0x04, 0x80000000 }, |
533 | { 0x4188cc, 1, 0x04, 0x00000000 }, | |
534 | { 0x4188d0, 1, 0x04, 0x00010000 }, | |
535 | { 0x4188d4, 1, 0x04, 0x00000001 }, | |
97af71fa BS |
536 | {} |
537 | }; | |
538 | ||
e3c71eb2 BS |
539 | const struct gf100_gr_init |
540 | gf100_gr_init_zcull_0[] = { | |
30f4e087 BS |
541 | { 0x418910, 1, 0x04, 0x00010001 }, |
542 | { 0x418914, 1, 0x04, 0x00000301 }, | |
543 | { 0x418918, 1, 0x04, 0x00800000 }, | |
544 | { 0x418980, 1, 0x04, 0x77777770 }, | |
545 | { 0x418984, 3, 0x04, 0x77777777 }, | |
97af71fa BS |
546 | {} |
547 | }; | |
548 | ||
e3c71eb2 BS |
549 | const struct gf100_gr_init |
550 | gf100_gr_init_gpm_0[] = { | |
30f4e087 BS |
551 | { 0x418c04, 1, 0x04, 0x00000000 }, |
552 | { 0x418c88, 1, 0x04, 0x00000000 }, | |
97af71fa BS |
553 | {} |
554 | }; | |
555 | ||
e3c71eb2 BS |
556 | const struct gf100_gr_init |
557 | gf100_gr_init_gpc_unk_1[] = { | |
30f4e087 BS |
558 | { 0x418d00, 1, 0x04, 0x00000000 }, |
559 | { 0x418f08, 1, 0x04, 0x00000000 }, | |
560 | { 0x418e00, 1, 0x04, 0x00000050 }, | |
561 | { 0x418e08, 1, 0x04, 0x00000000 }, | |
97af71fa BS |
562 | {} |
563 | }; | |
564 | ||
e3c71eb2 BS |
565 | const struct gf100_gr_init |
566 | gf100_gr_init_gcc_0[] = { | |
30f4e087 BS |
567 | { 0x41900c, 1, 0x04, 0x00000000 }, |
568 | { 0x419018, 1, 0x04, 0x00000000 }, | |
569 | {} | |
570 | }; | |
571 | ||
e3c71eb2 BS |
572 | const struct gf100_gr_init |
573 | gf100_gr_init_tpccs_0[] = { | |
30f4e087 BS |
574 | { 0x419d08, 2, 0x04, 0x00000000 }, |
575 | { 0x419d10, 1, 0x04, 0x00000014 }, | |
7e194533 BS |
576 | {} |
577 | }; | |
578 | ||
e3c71eb2 BS |
579 | const struct gf100_gr_init |
580 | gf100_gr_init_tex_0[] = { | |
30f4e087 BS |
581 | { 0x419ab0, 1, 0x04, 0x00000000 }, |
582 | { 0x419ab8, 1, 0x04, 0x000000e7 }, | |
583 | { 0x419abc, 2, 0x04, 0x00000000 }, | |
7e194533 BS |
584 | {} |
585 | }; | |
586 | ||
e3c71eb2 BS |
587 | const struct gf100_gr_init |
588 | gf100_gr_init_pe_0[] = { | |
30f4e087 BS |
589 | { 0x41980c, 3, 0x04, 0x00000000 }, |
590 | { 0x419844, 1, 0x04, 0x00000000 }, | |
591 | { 0x41984c, 1, 0x04, 0x00005bc5 }, | |
592 | { 0x419850, 4, 0x04, 0x00000000 }, | |
7e194533 BS |
593 | {} |
594 | }; | |
595 | ||
e3c71eb2 BS |
596 | const struct gf100_gr_init |
597 | gf100_gr_init_l1c_0[] = { | |
30f4e087 BS |
598 | { 0x419c98, 1, 0x04, 0x00000000 }, |
599 | { 0x419ca8, 1, 0x04, 0x80000000 }, | |
600 | { 0x419cb4, 1, 0x04, 0x00000000 }, | |
601 | { 0x419cb8, 1, 0x04, 0x00008bf4 }, | |
602 | { 0x419cbc, 1, 0x04, 0x28137606 }, | |
603 | { 0x419cc0, 2, 0x04, 0x00000000 }, | |
7e194533 BS |
604 | {} |
605 | }; | |
606 | ||
e3c71eb2 BS |
607 | const struct gf100_gr_init |
608 | gf100_gr_init_wwdx_0[] = { | |
30f4e087 BS |
609 | { 0x419bd4, 1, 0x04, 0x00800000 }, |
610 | { 0x419bdc, 1, 0x04, 0x00000000 }, | |
7e194533 BS |
611 | {} |
612 | }; | |
613 | ||
e3c71eb2 BS |
614 | const struct gf100_gr_init |
615 | gf100_gr_init_tpccs_1[] = { | |
30f4e087 | 616 | { 0x419d2c, 1, 0x04, 0x00000000 }, |
7e194533 BS |
617 | {} |
618 | }; | |
619 | ||
e3c71eb2 BS |
620 | const struct gf100_gr_init |
621 | gf100_gr_init_mpc_0[] = { | |
30f4e087 | 622 | { 0x419c0c, 1, 0x04, 0x00000000 }, |
7e194533 BS |
623 | {} |
624 | }; | |
625 | ||
e3c71eb2 BS |
626 | static const struct gf100_gr_init |
627 | gf100_gr_init_sm_0[] = { | |
30f4e087 BS |
628 | { 0x419e00, 1, 0x04, 0x00000000 }, |
629 | { 0x419ea0, 1, 0x04, 0x00000000 }, | |
630 | { 0x419ea4, 1, 0x04, 0x00000100 }, | |
631 | { 0x419ea8, 1, 0x04, 0x00001100 }, | |
632 | { 0x419eac, 1, 0x04, 0x11100702 }, | |
633 | { 0x419eb0, 1, 0x04, 0x00000003 }, | |
634 | { 0x419eb4, 4, 0x04, 0x00000000 }, | |
635 | { 0x419ec8, 1, 0x04, 0x06060618 }, | |
636 | { 0x419ed0, 1, 0x04, 0x0eff0e38 }, | |
637 | { 0x419ed4, 1, 0x04, 0x011104f1 }, | |
638 | { 0x419edc, 1, 0x04, 0x00000000 }, | |
639 | { 0x419f00, 1, 0x04, 0x00000000 }, | |
640 | { 0x419f2c, 1, 0x04, 0x00000000 }, | |
641 | {} | |
642 | }; | |
643 | ||
e3c71eb2 BS |
644 | const struct gf100_gr_init |
645 | gf100_gr_init_be_0[] = { | |
30f4e087 BS |
646 | { 0x40880c, 1, 0x04, 0x00000000 }, |
647 | { 0x408910, 9, 0x04, 0x00000000 }, | |
648 | { 0x408950, 1, 0x04, 0x00000000 }, | |
649 | { 0x408954, 1, 0x04, 0x0000ffff }, | |
650 | { 0x408984, 1, 0x04, 0x00000000 }, | |
651 | { 0x408988, 1, 0x04, 0x08040201 }, | |
652 | { 0x40898c, 1, 0x04, 0x80402010 }, | |
653 | {} | |
654 | }; | |
655 | ||
e3c71eb2 BS |
656 | const struct gf100_gr_init |
657 | gf100_gr_init_fe_1[] = { | |
c33b1e8c BS |
658 | { 0x4040f0, 1, 0x04, 0x00000000 }, |
659 | {} | |
660 | }; | |
661 | ||
e3c71eb2 BS |
662 | const struct gf100_gr_init |
663 | gf100_gr_init_pe_1[] = { | |
c33b1e8c BS |
664 | { 0x419880, 1, 0x04, 0x00000002 }, |
665 | {} | |
666 | }; | |
667 | ||
e3c71eb2 BS |
668 | static const struct gf100_gr_pack |
669 | gf100_gr_pack_mmio[] = { | |
670 | { gf100_gr_init_main_0 }, | |
671 | { gf100_gr_init_fe_0 }, | |
672 | { gf100_gr_init_pri_0 }, | |
673 | { gf100_gr_init_rstr2d_0 }, | |
674 | { gf100_gr_init_pd_0 }, | |
675 | { gf100_gr_init_ds_0 }, | |
676 | { gf100_gr_init_scc_0 }, | |
677 | { gf100_gr_init_prop_0 }, | |
678 | { gf100_gr_init_gpc_unk_0 }, | |
679 | { gf100_gr_init_setup_0 }, | |
680 | { gf100_gr_init_crstr_0 }, | |
681 | { gf100_gr_init_setup_1 }, | |
682 | { gf100_gr_init_zcull_0 }, | |
683 | { gf100_gr_init_gpm_0 }, | |
684 | { gf100_gr_init_gpc_unk_1 }, | |
685 | { gf100_gr_init_gcc_0 }, | |
686 | { gf100_gr_init_tpccs_0 }, | |
687 | { gf100_gr_init_tex_0 }, | |
688 | { gf100_gr_init_pe_0 }, | |
689 | { gf100_gr_init_l1c_0 }, | |
690 | { gf100_gr_init_wwdx_0 }, | |
691 | { gf100_gr_init_tpccs_1 }, | |
692 | { gf100_gr_init_mpc_0 }, | |
693 | { gf100_gr_init_sm_0 }, | |
694 | { gf100_gr_init_be_0 }, | |
695 | { gf100_gr_init_fe_1 }, | |
696 | { gf100_gr_init_pe_1 }, | |
26410c67 ML |
697 | {} |
698 | }; | |
699 | ||
c33b1e8c BS |
700 | /******************************************************************************* |
701 | * PGRAPH engine/subdev functions | |
702 | ******************************************************************************/ | |
703 | ||
ac9738bb | 704 | void |
bfee3f3d | 705 | gf100_gr_zbc_init(struct gf100_gr *gr) |
ac9738bb BS |
706 | { |
707 | const u32 zero[] = { 0x00000000, 0x00000000, 0x00000000, 0x00000000, | |
708 | 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; | |
709 | const u32 one[] = { 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, | |
710 | 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; | |
711 | const u32 f32_0[] = { 0x00000000, 0x00000000, 0x00000000, 0x00000000, | |
712 | 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; | |
713 | const u32 f32_1[] = { 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, | |
714 | 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000 }; | |
70bc7182 | 715 | struct nvkm_ltc *ltc = gr->base.engine.subdev.device->ltc; |
ac9738bb BS |
716 | int index; |
717 | ||
bfee3f3d BS |
718 | if (!gr->zbc_color[0].format) { |
719 | gf100_gr_zbc_color_get(gr, 1, & zero[0], &zero[4]); | |
720 | gf100_gr_zbc_color_get(gr, 2, & one[0], &one[4]); | |
721 | gf100_gr_zbc_color_get(gr, 4, &f32_0[0], &f32_0[4]); | |
722 | gf100_gr_zbc_color_get(gr, 4, &f32_1[0], &f32_1[4]); | |
723 | gf100_gr_zbc_depth_get(gr, 1, 0x00000000, 0x00000000); | |
724 | gf100_gr_zbc_depth_get(gr, 1, 0x3f800000, 0x3f800000); | |
ac9738bb BS |
725 | } |
726 | ||
727 | for (index = ltc->zbc_min; index <= ltc->zbc_max; index++) | |
bfee3f3d | 728 | gf100_gr_zbc_clear_color(gr, index); |
ac9738bb | 729 | for (index = ltc->zbc_min; index <= ltc->zbc_max; index++) |
bfee3f3d | 730 | gf100_gr_zbc_clear_depth(gr, index); |
ac9738bb BS |
731 | } |
732 | ||
4a8cf451 AC |
733 | /** |
734 | * Wait until GR goes idle. GR is considered idle if it is disabled by the | |
735 | * MC (0x200) register, or GR is not busy and a context switch is not in | |
736 | * progress. | |
737 | */ | |
738 | int | |
bfee3f3d | 739 | gf100_gr_wait_idle(struct gf100_gr *gr) |
4a8cf451 | 740 | { |
109c2f2f BS |
741 | struct nvkm_subdev *subdev = &gr->base.engine.subdev; |
742 | struct nvkm_device *device = subdev->device; | |
4a8cf451 AC |
743 | unsigned long end_jiffies = jiffies + msecs_to_jiffies(2000); |
744 | bool gr_enabled, ctxsw_active, gr_busy; | |
745 | ||
746 | do { | |
747 | /* | |
748 | * required to make sure FIFO_ENGINE_STATUS (0x2640) is | |
749 | * up-to-date | |
750 | */ | |
276836d4 | 751 | nvkm_rd32(device, 0x400700); |
4a8cf451 | 752 | |
276836d4 BS |
753 | gr_enabled = nvkm_rd32(device, 0x200) & 0x1000; |
754 | ctxsw_active = nvkm_rd32(device, 0x2640) & 0x8000; | |
755 | gr_busy = nvkm_rd32(device, 0x40060c) & 0x1; | |
4a8cf451 AC |
756 | |
757 | if (!gr_enabled || (!gr_busy && !ctxsw_active)) | |
758 | return 0; | |
759 | } while (time_before(jiffies, end_jiffies)); | |
760 | ||
109c2f2f BS |
761 | nvkm_error(subdev, |
762 | "wait for idle timeout (en: %d, ctxsw: %d, busy: %d)\n", | |
763 | gr_enabled, ctxsw_active, gr_busy); | |
4a8cf451 AC |
764 | return -EAGAIN; |
765 | } | |
766 | ||
30f4e087 | 767 | void |
bfee3f3d | 768 | gf100_gr_mmio(struct gf100_gr *gr, const struct gf100_gr_pack *p) |
4b223eef | 769 | { |
276836d4 | 770 | struct nvkm_device *device = gr->base.engine.subdev.device; |
e3c71eb2 BS |
771 | const struct gf100_gr_pack *pack; |
772 | const struct gf100_gr_init *init; | |
c33b1e8c BS |
773 | |
774 | pack_for_each_init(init, pack, p) { | |
775 | u32 next = init->addr + init->count * init->pitch; | |
776 | u32 addr = init->addr; | |
777 | while (addr < next) { | |
276836d4 | 778 | nvkm_wr32(device, addr, init->data); |
30f4e087 BS |
779 | addr += init->pitch; |
780 | } | |
781 | } | |
ebb945a9 BS |
782 | } |
783 | ||
784 | void | |
bfee3f3d | 785 | gf100_gr_icmd(struct gf100_gr *gr, const struct gf100_gr_pack *p) |
ebb945a9 | 786 | { |
276836d4 | 787 | struct nvkm_device *device = gr->base.engine.subdev.device; |
e3c71eb2 BS |
788 | const struct gf100_gr_pack *pack; |
789 | const struct gf100_gr_init *init; | |
c33b1e8c | 790 | u32 data = 0; |
30f4e087 | 791 | |
276836d4 | 792 | nvkm_wr32(device, 0x400208, 0x80000000); |
c33b1e8c BS |
793 | |
794 | pack_for_each_init(init, pack, p) { | |
795 | u32 next = init->addr + init->count * init->pitch; | |
796 | u32 addr = init->addr; | |
797 | ||
798 | if ((pack == p && init == p->init) || data != init->data) { | |
276836d4 | 799 | nvkm_wr32(device, 0x400204, init->data); |
30f4e087 BS |
800 | data = init->data; |
801 | } | |
ebb945a9 | 802 | |
c33b1e8c | 803 | while (addr < next) { |
276836d4 | 804 | nvkm_wr32(device, 0x400200, addr); |
4a8cf451 AC |
805 | /** |
806 | * Wait for GR to go idle after submitting a | |
807 | * GO_IDLE bundle | |
808 | */ | |
809 | if ((addr & 0xffff) == 0xe100) | |
bfee3f3d | 810 | gf100_gr_wait_idle(gr); |
c4584adc BS |
811 | nvkm_msec(device, 2000, |
812 | if (!(nvkm_rd32(device, 0x400700) & 0x00000004)) | |
813 | break; | |
814 | ); | |
30f4e087 | 815 | addr += init->pitch; |
30f4e087 BS |
816 | } |
817 | } | |
c33b1e8c | 818 | |
276836d4 | 819 | nvkm_wr32(device, 0x400208, 0x00000000); |
30f4e087 BS |
820 | } |
821 | ||
822 | void | |
bfee3f3d | 823 | gf100_gr_mthd(struct gf100_gr *gr, const struct gf100_gr_pack *p) |
30f4e087 | 824 | { |
276836d4 | 825 | struct nvkm_device *device = gr->base.engine.subdev.device; |
e3c71eb2 BS |
826 | const struct gf100_gr_pack *pack; |
827 | const struct gf100_gr_init *init; | |
c33b1e8c | 828 | u32 data = 0; |
30f4e087 | 829 | |
c33b1e8c BS |
830 | pack_for_each_init(init, pack, p) { |
831 | u32 ctrl = 0x80000000 | pack->type; | |
832 | u32 next = init->addr + init->count * init->pitch; | |
833 | u32 addr = init->addr; | |
834 | ||
835 | if ((pack == p && init == p->init) || data != init->data) { | |
276836d4 | 836 | nvkm_wr32(device, 0x40448c, init->data); |
c33b1e8c BS |
837 | data = init->data; |
838 | } | |
839 | ||
840 | while (addr < next) { | |
276836d4 | 841 | nvkm_wr32(device, 0x404488, ctrl | (addr << 14)); |
c33b1e8c | 842 | addr += init->pitch; |
30f4e087 BS |
843 | } |
844 | } | |
845 | } | |
846 | ||
847 | u64 | |
c85ee6ca | 848 | gf100_gr_units(struct nvkm_gr *base) |
30f4e087 | 849 | { |
c85ee6ca | 850 | struct gf100_gr *gr = gf100_gr(base); |
30f4e087 BS |
851 | u64 cfg; |
852 | ||
bfee3f3d BS |
853 | cfg = (u32)gr->gpc_nr; |
854 | cfg |= (u32)gr->tpc_total << 8; | |
855 | cfg |= (u64)gr->rop_nr << 32; | |
30f4e087 BS |
856 | |
857 | return cfg; | |
ebb945a9 BS |
858 | } |
859 | ||
caf2be8a IM |
860 | static const struct nvkm_bitfield gf100_dispatch_error[] = { |
861 | { 0x00000001, "INJECTED_BUNDLE_ERROR" }, | |
862 | { 0x00000002, "CLASS_SUBCH_MISMATCH" }, | |
863 | { 0x00000004, "SUBCHSW_DURING_NOTIFY" }, | |
864 | {} | |
865 | }; | |
866 | ||
867 | static const struct nvkm_bitfield gf100_m2mf_error[] = { | |
868 | { 0x00000001, "PUSH_TOO_MUCH_DATA" }, | |
869 | { 0x00000002, "PUSH_NOT_ENOUGH_DATA" }, | |
870 | {} | |
871 | }; | |
872 | ||
873 | static const struct nvkm_bitfield gf100_unk6_error[] = { | |
874 | { 0x00000001, "TEMP_TOO_SMALL" }, | |
875 | {} | |
876 | }; | |
877 | ||
878 | static const struct nvkm_bitfield gf100_ccache_error[] = { | |
879 | { 0x00000001, "INTR" }, | |
880 | { 0x00000002, "LDCONST_OOB" }, | |
881 | {} | |
882 | }; | |
883 | ||
884 | static const struct nvkm_bitfield gf100_macro_error[] = { | |
885 | { 0x00000001, "TOO_FEW_PARAMS" }, | |
886 | { 0x00000002, "TOO_MANY_PARAMS" }, | |
887 | { 0x00000004, "ILLEGAL_OPCODE" }, | |
888 | { 0x00000008, "DOUBLE_BRANCH" }, | |
889 | { 0x00000010, "WATCHDOG" }, | |
890 | {} | |
891 | }; | |
892 | ||
109c2f2f | 893 | static const struct nvkm_bitfield gk104_sked_error[] = { |
caf2be8a | 894 | { 0x00000040, "CTA_RESUME" }, |
109c2f2f BS |
895 | { 0x00000080, "CONSTANT_BUFFER_SIZE" }, |
896 | { 0x00000200, "LOCAL_MEMORY_SIZE_POS" }, | |
897 | { 0x00000400, "LOCAL_MEMORY_SIZE_NEG" }, | |
898 | { 0x00000800, "WARP_CSTACK_SIZE" }, | |
899 | { 0x00001000, "TOTAL_TEMP_SIZE" }, | |
900 | { 0x00002000, "REGISTER_COUNT" }, | |
901 | { 0x00040000, "TOTAL_THREADS" }, | |
902 | { 0x00100000, "PROGRAM_OFFSET" }, | |
903 | { 0x00200000, "SHARED_MEMORY_SIZE" }, | |
caf2be8a IM |
904 | { 0x00800000, "CTA_THREAD_DIMENSION_ZERO" }, |
905 | { 0x01000000, "MEMORY_WINDOW_OVERLAP" }, | |
109c2f2f BS |
906 | { 0x02000000, "SHARED_CONFIG_TOO_SMALL" }, |
907 | { 0x04000000, "TOTAL_REGISTER_COUNT" }, | |
30f4e087 BS |
908 | {} |
909 | }; | |
910 | ||
109c2f2f BS |
911 | static const struct nvkm_bitfield gf100_gpc_rop_error[] = { |
912 | { 0x00000002, "RT_PITCH_OVERRUN" }, | |
913 | { 0x00000010, "RT_WIDTH_OVERRUN" }, | |
914 | { 0x00000020, "RT_HEIGHT_OVERRUN" }, | |
915 | { 0x00000080, "ZETA_STORAGE_TYPE_MISMATCH" }, | |
916 | { 0x00000100, "RT_STORAGE_TYPE_MISMATCH" }, | |
917 | { 0x00000400, "RT_LINEAR_MISMATCH" }, | |
30f4e087 BS |
918 | {} |
919 | }; | |
920 | ||
ebb945a9 | 921 | static void |
bfee3f3d | 922 | gf100_gr_trap_gpc_rop(struct gf100_gr *gr, int gpc) |
ebb945a9 | 923 | { |
109c2f2f BS |
924 | struct nvkm_subdev *subdev = &gr->base.engine.subdev; |
925 | struct nvkm_device *device = subdev->device; | |
926 | char error[128]; | |
30f4e087 | 927 | u32 trap[4]; |
ebb945a9 | 928 | |
109c2f2f | 929 | trap[0] = nvkm_rd32(device, GPC_UNIT(gpc, 0x0420)) & 0x3fffffff; |
276836d4 BS |
930 | trap[1] = nvkm_rd32(device, GPC_UNIT(gpc, 0x0434)); |
931 | trap[2] = nvkm_rd32(device, GPC_UNIT(gpc, 0x0438)); | |
932 | trap[3] = nvkm_rd32(device, GPC_UNIT(gpc, 0x043c)); | |
ebb945a9 | 933 | |
109c2f2f | 934 | nvkm_snprintbf(error, sizeof(error), gf100_gpc_rop_error, trap[0]); |
30f4e087 | 935 | |
109c2f2f BS |
936 | nvkm_error(subdev, "GPC%d/PROP trap: %08x [%s] x = %u, y = %u, " |
937 | "format = %x, storage type = %x\n", | |
938 | gpc, trap[0], error, trap[1] & 0xffff, trap[1] >> 16, | |
939 | (trap[2] >> 8) & 0x3f, trap[3] & 0xff); | |
276836d4 | 940 | nvkm_wr32(device, GPC_UNIT(gpc, 0x0420), 0xc0000000); |
ebb945a9 BS |
941 | } |
942 | ||
e3c71eb2 | 943 | static const struct nvkm_enum gf100_mp_warp_error[] = { |
fec43a72 BS |
944 | { 0x00, "NO_ERROR" }, |
945 | { 0x01, "STACK_MISMATCH" }, | |
946 | { 0x05, "MISALIGNED_PC" }, | |
947 | { 0x08, "MISALIGNED_GPR" }, | |
948 | { 0x09, "INVALID_OPCODE" }, | |
949 | { 0x0d, "GPR_OUT_OF_BOUNDS" }, | |
950 | { 0x0e, "MEM_OUT_OF_BOUNDS" }, | |
951 | { 0x0f, "UNALIGNED_MEM_ACCESS" }, | |
3988f645 | 952 | { 0x10, "INVALID_ADDR_SPACE" }, |
fec43a72 BS |
953 | { 0x11, "INVALID_PARAM" }, |
954 | {} | |
955 | }; | |
956 | ||
e3c71eb2 | 957 | static const struct nvkm_bitfield gf100_mp_global_error[] = { |
fec43a72 BS |
958 | { 0x00000004, "MULTIPLE_WARP_ERRORS" }, |
959 | { 0x00000008, "OUT_OF_STACK_SPACE" }, | |
960 | {} | |
961 | }; | |
962 | ||
963 | static void | |
bfee3f3d | 964 | gf100_gr_trap_mp(struct gf100_gr *gr, int gpc, int tpc) |
fec43a72 | 965 | { |
109c2f2f BS |
966 | struct nvkm_subdev *subdev = &gr->base.engine.subdev; |
967 | struct nvkm_device *device = subdev->device; | |
276836d4 BS |
968 | u32 werr = nvkm_rd32(device, TPC_UNIT(gpc, tpc, 0x648)); |
969 | u32 gerr = nvkm_rd32(device, TPC_UNIT(gpc, tpc, 0x650)); | |
109c2f2f BS |
970 | const struct nvkm_enum *warp; |
971 | char glob[128]; | |
fec43a72 | 972 | |
109c2f2f BS |
973 | nvkm_snprintbf(glob, sizeof(glob), gf100_mp_global_error, gerr); |
974 | warp = nvkm_enum_find(gf100_mp_warp_error, werr & 0xffff); | |
975 | ||
976 | nvkm_error(subdev, "GPC%i/TPC%i/MP trap: " | |
977 | "global %08x [%s] warp %04x [%s]\n", | |
978 | gpc, tpc, gerr, glob, werr, warp ? warp->name : ""); | |
fec43a72 | 979 | |
276836d4 BS |
980 | nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x648), 0x00000000); |
981 | nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x650), gerr); | |
fec43a72 BS |
982 | } |
983 | ||
f73221e4 | 984 | static void |
bfee3f3d | 985 | gf100_gr_trap_tpc(struct gf100_gr *gr, int gpc, int tpc) |
f73221e4 | 986 | { |
109c2f2f BS |
987 | struct nvkm_subdev *subdev = &gr->base.engine.subdev; |
988 | struct nvkm_device *device = subdev->device; | |
276836d4 | 989 | u32 stat = nvkm_rd32(device, TPC_UNIT(gpc, tpc, 0x0508)); |
f73221e4 BS |
990 | |
991 | if (stat & 0x00000001) { | |
276836d4 | 992 | u32 trap = nvkm_rd32(device, TPC_UNIT(gpc, tpc, 0x0224)); |
109c2f2f | 993 | nvkm_error(subdev, "GPC%d/TPC%d/TEX: %08x\n", gpc, tpc, trap); |
276836d4 | 994 | nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x0224), 0xc0000000); |
f73221e4 BS |
995 | stat &= ~0x00000001; |
996 | } | |
997 | ||
998 | if (stat & 0x00000002) { | |
bfee3f3d | 999 | gf100_gr_trap_mp(gr, gpc, tpc); |
f73221e4 BS |
1000 | stat &= ~0x00000002; |
1001 | } | |
1002 | ||
1003 | if (stat & 0x00000004) { | |
276836d4 | 1004 | u32 trap = nvkm_rd32(device, TPC_UNIT(gpc, tpc, 0x0084)); |
109c2f2f | 1005 | nvkm_error(subdev, "GPC%d/TPC%d/POLY: %08x\n", gpc, tpc, trap); |
276836d4 | 1006 | nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x0084), 0xc0000000); |
f73221e4 BS |
1007 | stat &= ~0x00000004; |
1008 | } | |
1009 | ||
1010 | if (stat & 0x00000008) { | |
276836d4 | 1011 | u32 trap = nvkm_rd32(device, TPC_UNIT(gpc, tpc, 0x048c)); |
109c2f2f | 1012 | nvkm_error(subdev, "GPC%d/TPC%d/L1C: %08x\n", gpc, tpc, trap); |
276836d4 | 1013 | nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x048c), 0xc0000000); |
f73221e4 BS |
1014 | stat &= ~0x00000008; |
1015 | } | |
1016 | ||
1017 | if (stat) { | |
109c2f2f | 1018 | nvkm_error(subdev, "GPC%d/TPC%d/%08x: unknown\n", gpc, tpc, stat); |
f73221e4 BS |
1019 | } |
1020 | } | |
1021 | ||
1022 | static void | |
bfee3f3d | 1023 | gf100_gr_trap_gpc(struct gf100_gr *gr, int gpc) |
f73221e4 | 1024 | { |
109c2f2f BS |
1025 | struct nvkm_subdev *subdev = &gr->base.engine.subdev; |
1026 | struct nvkm_device *device = subdev->device; | |
276836d4 | 1027 | u32 stat = nvkm_rd32(device, GPC_UNIT(gpc, 0x2c90)); |
f73221e4 BS |
1028 | int tpc; |
1029 | ||
1030 | if (stat & 0x00000001) { | |
bfee3f3d | 1031 | gf100_gr_trap_gpc_rop(gr, gpc); |
f73221e4 BS |
1032 | stat &= ~0x00000001; |
1033 | } | |
1034 | ||
1035 | if (stat & 0x00000002) { | |
276836d4 | 1036 | u32 trap = nvkm_rd32(device, GPC_UNIT(gpc, 0x0900)); |
109c2f2f | 1037 | nvkm_error(subdev, "GPC%d/ZCULL: %08x\n", gpc, trap); |
276836d4 | 1038 | nvkm_wr32(device, GPC_UNIT(gpc, 0x0900), 0xc0000000); |
f73221e4 BS |
1039 | stat &= ~0x00000002; |
1040 | } | |
1041 | ||
1042 | if (stat & 0x00000004) { | |
276836d4 | 1043 | u32 trap = nvkm_rd32(device, GPC_UNIT(gpc, 0x1028)); |
109c2f2f | 1044 | nvkm_error(subdev, "GPC%d/CCACHE: %08x\n", gpc, trap); |
276836d4 | 1045 | nvkm_wr32(device, GPC_UNIT(gpc, 0x1028), 0xc0000000); |
f73221e4 BS |
1046 | stat &= ~0x00000004; |
1047 | } | |
1048 | ||
1049 | if (stat & 0x00000008) { | |
276836d4 | 1050 | u32 trap = nvkm_rd32(device, GPC_UNIT(gpc, 0x0824)); |
109c2f2f | 1051 | nvkm_error(subdev, "GPC%d/ESETUP: %08x\n", gpc, trap); |
276836d4 | 1052 | nvkm_wr32(device, GPC_UNIT(gpc, 0x0824), 0xc0000000); |
f73221e4 BS |
1053 | stat &= ~0x00000009; |
1054 | } | |
1055 | ||
bfee3f3d | 1056 | for (tpc = 0; tpc < gr->tpc_nr[gpc]; tpc++) { |
f73221e4 BS |
1057 | u32 mask = 0x00010000 << tpc; |
1058 | if (stat & mask) { | |
bfee3f3d | 1059 | gf100_gr_trap_tpc(gr, gpc, tpc); |
276836d4 | 1060 | nvkm_wr32(device, GPC_UNIT(gpc, 0x2c90), mask); |
f73221e4 BS |
1061 | stat &= ~mask; |
1062 | } | |
1063 | } | |
1064 | ||
1065 | if (stat) { | |
109c2f2f | 1066 | nvkm_error(subdev, "GPC%d/%08x: unknown\n", gpc, stat); |
f73221e4 BS |
1067 | } |
1068 | } | |
1069 | ||
1070 | static void | |
bfee3f3d | 1071 | gf100_gr_trap_intr(struct gf100_gr *gr) |
f73221e4 | 1072 | { |
109c2f2f BS |
1073 | struct nvkm_subdev *subdev = &gr->base.engine.subdev; |
1074 | struct nvkm_device *device = subdev->device; | |
caf2be8a | 1075 | char error[128]; |
276836d4 | 1076 | u32 trap = nvkm_rd32(device, 0x400108); |
109c2f2f | 1077 | int rop, gpc; |
f73221e4 BS |
1078 | |
1079 | if (trap & 0x00000001) { | |
276836d4 | 1080 | u32 stat = nvkm_rd32(device, 0x404000); |
caf2be8a IM |
1081 | |
1082 | nvkm_snprintbf(error, sizeof(error), gf100_dispatch_error, | |
1083 | stat & 0x3fffffff); | |
1084 | nvkm_error(subdev, "DISPATCH %08x [%s]\n", stat, error); | |
276836d4 BS |
1085 | nvkm_wr32(device, 0x404000, 0xc0000000); |
1086 | nvkm_wr32(device, 0x400108, 0x00000001); | |
f73221e4 BS |
1087 | trap &= ~0x00000001; |
1088 | } | |
1089 | ||
1090 | if (trap & 0x00000002) { | |
276836d4 | 1091 | u32 stat = nvkm_rd32(device, 0x404600); |
caf2be8a IM |
1092 | |
1093 | nvkm_snprintbf(error, sizeof(error), gf100_m2mf_error, | |
1094 | stat & 0x3fffffff); | |
1095 | nvkm_error(subdev, "M2MF %08x [%s]\n", stat, error); | |
1096 | ||
276836d4 BS |
1097 | nvkm_wr32(device, 0x404600, 0xc0000000); |
1098 | nvkm_wr32(device, 0x400108, 0x00000002); | |
f73221e4 BS |
1099 | trap &= ~0x00000002; |
1100 | } | |
1101 | ||
1102 | if (trap & 0x00000008) { | |
276836d4 | 1103 | u32 stat = nvkm_rd32(device, 0x408030); |
caf2be8a IM |
1104 | |
1105 | nvkm_snprintbf(error, sizeof(error), gf100_m2mf_error, | |
1106 | stat & 0x3fffffff); | |
1107 | nvkm_error(subdev, "CCACHE %08x [%s]\n", stat, error); | |
276836d4 BS |
1108 | nvkm_wr32(device, 0x408030, 0xc0000000); |
1109 | nvkm_wr32(device, 0x400108, 0x00000008); | |
f73221e4 BS |
1110 | trap &= ~0x00000008; |
1111 | } | |
1112 | ||
1113 | if (trap & 0x00000010) { | |
276836d4 | 1114 | u32 stat = nvkm_rd32(device, 0x405840); |
caf2be8a IM |
1115 | nvkm_error(subdev, "SHADER %08x, sph: 0x%06x, stage: 0x%02x\n", |
1116 | stat, stat & 0xffffff, (stat >> 24) & 0x3f); | |
276836d4 BS |
1117 | nvkm_wr32(device, 0x405840, 0xc0000000); |
1118 | nvkm_wr32(device, 0x400108, 0x00000010); | |
f73221e4 BS |
1119 | trap &= ~0x00000010; |
1120 | } | |
1121 | ||
1122 | if (trap & 0x00000040) { | |
276836d4 | 1123 | u32 stat = nvkm_rd32(device, 0x40601c); |
caf2be8a IM |
1124 | |
1125 | nvkm_snprintbf(error, sizeof(error), gf100_unk6_error, | |
1126 | stat & 0x3fffffff); | |
1127 | nvkm_error(subdev, "UNK6 %08x [%s]\n", stat, error); | |
1128 | ||
276836d4 BS |
1129 | nvkm_wr32(device, 0x40601c, 0xc0000000); |
1130 | nvkm_wr32(device, 0x400108, 0x00000040); | |
f73221e4 BS |
1131 | trap &= ~0x00000040; |
1132 | } | |
1133 | ||
1134 | if (trap & 0x00000080) { | |
276836d4 | 1135 | u32 stat = nvkm_rd32(device, 0x404490); |
caf2be8a IM |
1136 | u32 pc = nvkm_rd32(device, 0x404494); |
1137 | u32 op = nvkm_rd32(device, 0x40449c); | |
1138 | ||
1139 | nvkm_snprintbf(error, sizeof(error), gf100_macro_error, | |
1140 | stat & 0x1fffffff); | |
1141 | nvkm_error(subdev, "MACRO %08x [%s], pc: 0x%03x%s, op: 0x%08x\n", | |
1142 | stat, error, pc & 0x7ff, | |
1143 | (pc & 0x10000000) ? "" : " (invalid)", | |
1144 | op); | |
1145 | ||
276836d4 BS |
1146 | nvkm_wr32(device, 0x404490, 0xc0000000); |
1147 | nvkm_wr32(device, 0x400108, 0x00000080); | |
f73221e4 BS |
1148 | trap &= ~0x00000080; |
1149 | } | |
1150 | ||
30f4e087 | 1151 | if (trap & 0x00000100) { |
109c2f2f | 1152 | u32 stat = nvkm_rd32(device, 0x407020) & 0x3fffffff; |
30f4e087 | 1153 | |
caf2be8a IM |
1154 | nvkm_snprintbf(error, sizeof(error), gk104_sked_error, stat); |
1155 | nvkm_error(subdev, "SKED: %08x [%s]\n", stat, error); | |
30f4e087 | 1156 | |
109c2f2f | 1157 | if (stat) |
276836d4 BS |
1158 | nvkm_wr32(device, 0x407020, 0x40000000); |
1159 | nvkm_wr32(device, 0x400108, 0x00000100); | |
30f4e087 BS |
1160 | trap &= ~0x00000100; |
1161 | } | |
1162 | ||
f73221e4 | 1163 | if (trap & 0x01000000) { |
276836d4 | 1164 | u32 stat = nvkm_rd32(device, 0x400118); |
bfee3f3d | 1165 | for (gpc = 0; stat && gpc < gr->gpc_nr; gpc++) { |
f73221e4 BS |
1166 | u32 mask = 0x00000001 << gpc; |
1167 | if (stat & mask) { | |
bfee3f3d | 1168 | gf100_gr_trap_gpc(gr, gpc); |
276836d4 | 1169 | nvkm_wr32(device, 0x400118, mask); |
f73221e4 BS |
1170 | stat &= ~mask; |
1171 | } | |
1172 | } | |
276836d4 | 1173 | nvkm_wr32(device, 0x400108, 0x01000000); |
f73221e4 BS |
1174 | trap &= ~0x01000000; |
1175 | } | |
1176 | ||
1177 | if (trap & 0x02000000) { | |
bfee3f3d | 1178 | for (rop = 0; rop < gr->rop_nr; rop++) { |
276836d4 BS |
1179 | u32 statz = nvkm_rd32(device, ROP_UNIT(rop, 0x070)); |
1180 | u32 statc = nvkm_rd32(device, ROP_UNIT(rop, 0x144)); | |
109c2f2f | 1181 | nvkm_error(subdev, "ROP%d %08x %08x\n", |
f73221e4 | 1182 | rop, statz, statc); |
276836d4 BS |
1183 | nvkm_wr32(device, ROP_UNIT(rop, 0x070), 0xc0000000); |
1184 | nvkm_wr32(device, ROP_UNIT(rop, 0x144), 0xc0000000); | |
f73221e4 | 1185 | } |
276836d4 | 1186 | nvkm_wr32(device, 0x400108, 0x02000000); |
f73221e4 BS |
1187 | trap &= ~0x02000000; |
1188 | } | |
1189 | ||
1190 | if (trap) { | |
109c2f2f | 1191 | nvkm_error(subdev, "TRAP UNHANDLED %08x\n", trap); |
276836d4 | 1192 | nvkm_wr32(device, 0x400108, trap); |
f73221e4 BS |
1193 | } |
1194 | } | |
1195 | ||
30f4e087 | 1196 | static void |
bfee3f3d | 1197 | gf100_gr_ctxctl_debug_unit(struct gf100_gr *gr, u32 base) |
30f4e087 | 1198 | { |
109c2f2f BS |
1199 | struct nvkm_subdev *subdev = &gr->base.engine.subdev; |
1200 | struct nvkm_device *device = subdev->device; | |
1201 | nvkm_error(subdev, "%06x - done %08x\n", base, | |
1202 | nvkm_rd32(device, base + 0x400)); | |
1203 | nvkm_error(subdev, "%06x - stat %08x %08x %08x %08x\n", base, | |
1204 | nvkm_rd32(device, base + 0x800), | |
1205 | nvkm_rd32(device, base + 0x804), | |
1206 | nvkm_rd32(device, base + 0x808), | |
1207 | nvkm_rd32(device, base + 0x80c)); | |
1208 | nvkm_error(subdev, "%06x - stat %08x %08x %08x %08x\n", base, | |
1209 | nvkm_rd32(device, base + 0x810), | |
1210 | nvkm_rd32(device, base + 0x814), | |
1211 | nvkm_rd32(device, base + 0x818), | |
1212 | nvkm_rd32(device, base + 0x81c)); | |
30f4e087 BS |
1213 | } |
1214 | ||
1215 | void | |
bfee3f3d | 1216 | gf100_gr_ctxctl_debug(struct gf100_gr *gr) |
30f4e087 | 1217 | { |
276836d4 BS |
1218 | struct nvkm_device *device = gr->base.engine.subdev.device; |
1219 | u32 gpcnr = nvkm_rd32(device, 0x409604) & 0xffff; | |
30f4e087 BS |
1220 | u32 gpc; |
1221 | ||
bfee3f3d | 1222 | gf100_gr_ctxctl_debug_unit(gr, 0x409000); |
30f4e087 | 1223 | for (gpc = 0; gpc < gpcnr; gpc++) |
bfee3f3d | 1224 | gf100_gr_ctxctl_debug_unit(gr, 0x502000 + (gpc * 0x8000)); |
30f4e087 BS |
1225 | } |
1226 | ||
1227 | static void | |
bfee3f3d | 1228 | gf100_gr_ctxctl_isr(struct gf100_gr *gr) |
30f4e087 | 1229 | { |
109c2f2f BS |
1230 | struct nvkm_subdev *subdev = &gr->base.engine.subdev; |
1231 | struct nvkm_device *device = subdev->device; | |
276836d4 | 1232 | u32 stat = nvkm_rd32(device, 0x409c18); |
30f4e087 | 1233 | |
23f67841 | 1234 | if (stat & 0x00000001) { |
276836d4 | 1235 | u32 code = nvkm_rd32(device, 0x409814); |
23f67841 | 1236 | if (code == E_BAD_FWMTHD) { |
276836d4 BS |
1237 | u32 class = nvkm_rd32(device, 0x409808); |
1238 | u32 addr = nvkm_rd32(device, 0x40980c); | |
23f67841 BS |
1239 | u32 subc = (addr & 0x00070000) >> 16; |
1240 | u32 mthd = (addr & 0x00003ffc); | |
276836d4 | 1241 | u32 data = nvkm_rd32(device, 0x409810); |
23f67841 | 1242 | |
109c2f2f BS |
1243 | nvkm_error(subdev, "FECS MTHD subc %d class %04x " |
1244 | "mthd %04x data %08x\n", | |
1245 | subc, class, mthd, data); | |
23f67841 | 1246 | |
276836d4 | 1247 | nvkm_wr32(device, 0x409c20, 0x00000001); |
23f67841 BS |
1248 | stat &= ~0x00000001; |
1249 | } else { | |
109c2f2f | 1250 | nvkm_error(subdev, "FECS ucode error %d\n", code); |
23f67841 BS |
1251 | } |
1252 | } | |
30f4e087 | 1253 | |
23f67841 | 1254 | if (stat & 0x00080000) { |
109c2f2f | 1255 | nvkm_error(subdev, "FECS watchdog timeout\n"); |
bfee3f3d | 1256 | gf100_gr_ctxctl_debug(gr); |
276836d4 | 1257 | nvkm_wr32(device, 0x409c20, 0x00080000); |
23f67841 BS |
1258 | stat &= ~0x00080000; |
1259 | } | |
1260 | ||
1261 | if (stat) { | |
109c2f2f | 1262 | nvkm_error(subdev, "FECS %08x\n", stat); |
bfee3f3d | 1263 | gf100_gr_ctxctl_debug(gr); |
276836d4 | 1264 | nvkm_wr32(device, 0x409c20, stat); |
23f67841 | 1265 | } |
30f4e087 BS |
1266 | } |
1267 | ||
ebb945a9 | 1268 | static void |
c85ee6ca | 1269 | gf100_gr_intr(struct nvkm_gr *base) |
ebb945a9 | 1270 | { |
c85ee6ca BS |
1271 | struct gf100_gr *gr = gf100_gr(base); |
1272 | struct nvkm_subdev *subdev = &gr->base.engine.subdev; | |
1273 | struct nvkm_device *device = subdev->device; | |
a65955e1 BS |
1274 | struct nvkm_fifo_chan *chan; |
1275 | unsigned long flags; | |
276836d4 BS |
1276 | u64 inst = nvkm_rd32(device, 0x409b00) & 0x0fffffff; |
1277 | u32 stat = nvkm_rd32(device, 0x400100); | |
1278 | u32 addr = nvkm_rd32(device, 0x400704); | |
ebb945a9 BS |
1279 | u32 mthd = (addr & 0x00003ffc); |
1280 | u32 subc = (addr & 0x00070000) >> 16; | |
276836d4 BS |
1281 | u32 data = nvkm_rd32(device, 0x400708); |
1282 | u32 code = nvkm_rd32(device, 0x400110); | |
91c772ec | 1283 | u32 class; |
8f0649b5 BS |
1284 | const char *name = "unknown"; |
1285 | int chid = -1; | |
72a14827 | 1286 | |
a65955e1 | 1287 | chan = nvkm_fifo_chan_inst(device->fifo, (u64)inst << 12, &flags); |
8f0649b5 BS |
1288 | if (chan) { |
1289 | name = chan->object.client->name; | |
1290 | chid = chan->chid; | |
1291 | } | |
a65955e1 | 1292 | |
c85ee6ca | 1293 | if (device->card_type < NV_E0 || subc < 4) |
276836d4 | 1294 | class = nvkm_rd32(device, 0x404200 + (subc * 4)); |
91c772ec BS |
1295 | else |
1296 | class = 0x0000; | |
1297 | ||
c6a7b026 LP |
1298 | if (stat & 0x00000001) { |
1299 | /* | |
1300 | * notifier interrupt, only needed for cyclestats | |
1301 | * can be safely ignored | |
1302 | */ | |
276836d4 | 1303 | nvkm_wr32(device, 0x400100, 0x00000001); |
c6a7b026 LP |
1304 | stat &= ~0x00000001; |
1305 | } | |
1306 | ||
ebb945a9 | 1307 | if (stat & 0x00000010) { |
a65955e1 | 1308 | if (!gf100_gr_mthd_sw(device, class, mthd, data)) { |
109c2f2f BS |
1309 | nvkm_error(subdev, "ILLEGAL_MTHD ch %d [%010llx %s] " |
1310 | "subc %d class %04x mthd %04x data %08x\n", | |
8f0649b5 BS |
1311 | chid, inst << 12, name, subc, |
1312 | class, mthd, data); | |
ebb945a9 | 1313 | } |
276836d4 | 1314 | nvkm_wr32(device, 0x400100, 0x00000010); |
ebb945a9 BS |
1315 | stat &= ~0x00000010; |
1316 | } | |
1317 | ||
1318 | if (stat & 0x00000020) { | |
109c2f2f BS |
1319 | nvkm_error(subdev, "ILLEGAL_CLASS ch %d [%010llx %s] " |
1320 | "subc %d class %04x mthd %04x data %08x\n", | |
8f0649b5 | 1321 | chid, inst << 12, name, subc, class, mthd, data); |
276836d4 | 1322 | nvkm_wr32(device, 0x400100, 0x00000020); |
ebb945a9 BS |
1323 | stat &= ~0x00000020; |
1324 | } | |
1325 | ||
1326 | if (stat & 0x00100000) { | |
109c2f2f BS |
1327 | const struct nvkm_enum *en = |
1328 | nvkm_enum_find(nv50_data_error_names, code); | |
1329 | nvkm_error(subdev, "DATA_ERROR %08x [%s] ch %d [%010llx %s] " | |
1330 | "subc %d class %04x mthd %04x data %08x\n", | |
1331 | code, en ? en->name : "", chid, inst << 12, | |
8f0649b5 | 1332 | name, subc, class, mthd, data); |
276836d4 | 1333 | nvkm_wr32(device, 0x400100, 0x00100000); |
ebb945a9 BS |
1334 | stat &= ~0x00100000; |
1335 | } | |
1336 | ||
1337 | if (stat & 0x00200000) { | |
109c2f2f | 1338 | nvkm_error(subdev, "TRAP ch %d [%010llx %s]\n", |
8f0649b5 | 1339 | chid, inst << 12, name); |
bfee3f3d | 1340 | gf100_gr_trap_intr(gr); |
276836d4 | 1341 | nvkm_wr32(device, 0x400100, 0x00200000); |
ebb945a9 BS |
1342 | stat &= ~0x00200000; |
1343 | } | |
1344 | ||
1345 | if (stat & 0x00080000) { | |
bfee3f3d | 1346 | gf100_gr_ctxctl_isr(gr); |
276836d4 | 1347 | nvkm_wr32(device, 0x400100, 0x00080000); |
ebb945a9 BS |
1348 | stat &= ~0x00080000; |
1349 | } | |
1350 | ||
1351 | if (stat) { | |
109c2f2f | 1352 | nvkm_error(subdev, "intr %08x\n", stat); |
276836d4 | 1353 | nvkm_wr32(device, 0x400100, stat); |
ebb945a9 BS |
1354 | } |
1355 | ||
276836d4 | 1356 | nvkm_wr32(device, 0x400500, 0x00010001); |
a65955e1 | 1357 | nvkm_fifo_chan_put(device->fifo, flags, &chan); |
ebb945a9 BS |
1358 | } |
1359 | ||
30f4e087 | 1360 | void |
bfee3f3d | 1361 | gf100_gr_init_fw(struct gf100_gr *gr, u32 fuc_base, |
e3c71eb2 | 1362 | struct gf100_gr_fuc *code, struct gf100_gr_fuc *data) |
ebb945a9 | 1363 | { |
276836d4 | 1364 | struct nvkm_device *device = gr->base.engine.subdev.device; |
30f4e087 | 1365 | int i; |
ebb945a9 | 1366 | |
276836d4 | 1367 | nvkm_wr32(device, fuc_base + 0x01c0, 0x01000000); |
30f4e087 | 1368 | for (i = 0; i < data->size / 4; i++) |
276836d4 | 1369 | nvkm_wr32(device, fuc_base + 0x01c4, data->data[i]); |
ebb945a9 | 1370 | |
276836d4 | 1371 | nvkm_wr32(device, fuc_base + 0x0180, 0x01000000); |
30f4e087 BS |
1372 | for (i = 0; i < code->size / 4; i++) { |
1373 | if ((i & 0x3f) == 0) | |
276836d4 BS |
1374 | nvkm_wr32(device, fuc_base + 0x0188, i >> 6); |
1375 | nvkm_wr32(device, fuc_base + 0x0184, code->data[i]); | |
30f4e087 | 1376 | } |
370eec76 AC |
1377 | |
1378 | /* code must be padded to 0x40 words */ | |
1379 | for (; i & 0x3f; i++) | |
276836d4 | 1380 | nvkm_wr32(device, fuc_base + 0x0184, 0); |
966a5b7d BS |
1381 | } |
1382 | ||
a32b2ffb | 1383 | static void |
bfee3f3d | 1384 | gf100_gr_init_csdata(struct gf100_gr *gr, |
e3c71eb2 BS |
1385 | const struct gf100_gr_pack *pack, |
1386 | u32 falcon, u32 starstar, u32 base) | |
a32b2ffb | 1387 | { |
276836d4 | 1388 | struct nvkm_device *device = gr->base.engine.subdev.device; |
e3c71eb2 BS |
1389 | const struct gf100_gr_pack *iter; |
1390 | const struct gf100_gr_init *init; | |
c33b1e8c | 1391 | u32 addr = ~0, prev = ~0, xfer = 0; |
a32b2ffb BS |
1392 | u32 star, temp; |
1393 | ||
276836d4 BS |
1394 | nvkm_wr32(device, falcon + 0x01c0, 0x02000000 + starstar); |
1395 | star = nvkm_rd32(device, falcon + 0x01c4); | |
1396 | temp = nvkm_rd32(device, falcon + 0x01c4); | |
a32b2ffb BS |
1397 | if (temp > star) |
1398 | star = temp; | |
276836d4 | 1399 | nvkm_wr32(device, falcon + 0x01c0, 0x01000000 + star); |
a32b2ffb | 1400 | |
c33b1e8c BS |
1401 | pack_for_each_init(init, iter, pack) { |
1402 | u32 head = init->addr - base; | |
1403 | u32 tail = head + init->count * init->pitch; | |
1404 | while (head < tail) { | |
1405 | if (head != prev + 4 || xfer >= 32) { | |
1406 | if (xfer) { | |
1407 | u32 data = ((--xfer << 26) | addr); | |
276836d4 | 1408 | nvkm_wr32(device, falcon + 0x01c4, data); |
c33b1e8c BS |
1409 | star += 4; |
1410 | } | |
1411 | addr = head; | |
1412 | xfer = 0; | |
a32b2ffb | 1413 | } |
c33b1e8c BS |
1414 | prev = head; |
1415 | xfer = xfer + 1; | |
1416 | head = head + init->pitch; | |
a32b2ffb | 1417 | } |
c33b1e8c | 1418 | } |
a32b2ffb | 1419 | |
276836d4 BS |
1420 | nvkm_wr32(device, falcon + 0x01c4, (--xfer << 26) | addr); |
1421 | nvkm_wr32(device, falcon + 0x01c0, 0x01000004 + starstar); | |
1422 | nvkm_wr32(device, falcon + 0x01c4, star + 4); | |
a32b2ffb BS |
1423 | } |
1424 | ||
30f4e087 | 1425 | int |
bfee3f3d | 1426 | gf100_gr_init_ctxctl(struct gf100_gr *gr) |
966a5b7d | 1427 | { |
27f3d6cf | 1428 | const struct gf100_grctx_func *grctx = gr->func->grctx; |
109c2f2f BS |
1429 | struct nvkm_subdev *subdev = &gr->base.engine.subdev; |
1430 | struct nvkm_device *device = subdev->device; | |
30f4e087 | 1431 | int i; |
ebb945a9 | 1432 | |
bfee3f3d | 1433 | if (gr->firmware) { |
30f4e087 | 1434 | /* load fuc microcode */ |
54dcadd5 | 1435 | nvkm_mc_unk260(device->mc, 0); |
c85ee6ca BS |
1436 | gf100_gr_init_fw(gr, 0x409000, &gr->fuc409c, &gr->fuc409d); |
1437 | gf100_gr_init_fw(gr, 0x41a000, &gr->fuc41ac, &gr->fuc41ad); | |
54dcadd5 | 1438 | nvkm_mc_unk260(device->mc, 1); |
ebb945a9 | 1439 | |
30f4e087 | 1440 | /* start both of them running */ |
276836d4 BS |
1441 | nvkm_wr32(device, 0x409840, 0xffffffff); |
1442 | nvkm_wr32(device, 0x41a10c, 0x00000000); | |
1443 | nvkm_wr32(device, 0x40910c, 0x00000000); | |
1444 | nvkm_wr32(device, 0x41a100, 0x00000002); | |
1445 | nvkm_wr32(device, 0x409100, 0x00000002); | |
c4584adc BS |
1446 | if (nvkm_msec(device, 2000, |
1447 | if (nvkm_rd32(device, 0x409800) & 0x00000001) | |
1448 | break; | |
1449 | ) < 0) | |
1450 | return -EBUSY; | |
bfee3f3d | 1451 | |
276836d4 BS |
1452 | nvkm_wr32(device, 0x409840, 0xffffffff); |
1453 | nvkm_wr32(device, 0x409500, 0x7fffffff); | |
1454 | nvkm_wr32(device, 0x409504, 0x00000021); | |
bfee3f3d | 1455 | |
276836d4 BS |
1456 | nvkm_wr32(device, 0x409840, 0xffffffff); |
1457 | nvkm_wr32(device, 0x409500, 0x00000000); | |
1458 | nvkm_wr32(device, 0x409504, 0x00000010); | |
c4584adc BS |
1459 | if (nvkm_msec(device, 2000, |
1460 | if ((gr->size = nvkm_rd32(device, 0x409800))) | |
1461 | break; | |
1462 | ) < 0) | |
30f4e087 | 1463 | return -EBUSY; |
0411de85 | 1464 | |
276836d4 BS |
1465 | nvkm_wr32(device, 0x409840, 0xffffffff); |
1466 | nvkm_wr32(device, 0x409500, 0x00000000); | |
1467 | nvkm_wr32(device, 0x409504, 0x00000016); | |
c4584adc BS |
1468 | if (nvkm_msec(device, 2000, |
1469 | if (nvkm_rd32(device, 0x409800)) | |
1470 | break; | |
1471 | ) < 0) | |
ac1499d9 | 1472 | return -EBUSY; |
ac1499d9 | 1473 | |
276836d4 BS |
1474 | nvkm_wr32(device, 0x409840, 0xffffffff); |
1475 | nvkm_wr32(device, 0x409500, 0x00000000); | |
1476 | nvkm_wr32(device, 0x409504, 0x00000025); | |
c4584adc BS |
1477 | if (nvkm_msec(device, 2000, |
1478 | if (nvkm_rd32(device, 0x409800)) | |
1479 | break; | |
1480 | ) < 0) | |
ac1499d9 | 1481 | return -EBUSY; |
ac1499d9 | 1482 | |
c85ee6ca | 1483 | if (device->chipset >= 0xe0) { |
276836d4 BS |
1484 | nvkm_wr32(device, 0x409800, 0x00000000); |
1485 | nvkm_wr32(device, 0x409500, 0x00000001); | |
1486 | nvkm_wr32(device, 0x409504, 0x00000030); | |
c4584adc BS |
1487 | if (nvkm_msec(device, 2000, |
1488 | if (nvkm_rd32(device, 0x409800)) | |
1489 | break; | |
1490 | ) < 0) | |
30f4e087 | 1491 | return -EBUSY; |
30f4e087 | 1492 | |
276836d4 BS |
1493 | nvkm_wr32(device, 0x409810, 0xb00095c8); |
1494 | nvkm_wr32(device, 0x409800, 0x00000000); | |
1495 | nvkm_wr32(device, 0x409500, 0x00000001); | |
1496 | nvkm_wr32(device, 0x409504, 0x00000031); | |
c4584adc BS |
1497 | if (nvkm_msec(device, 2000, |
1498 | if (nvkm_rd32(device, 0x409800)) | |
1499 | break; | |
1500 | ) < 0) | |
30f4e087 | 1501 | return -EBUSY; |
30f4e087 | 1502 | |
276836d4 BS |
1503 | nvkm_wr32(device, 0x409810, 0x00080420); |
1504 | nvkm_wr32(device, 0x409800, 0x00000000); | |
1505 | nvkm_wr32(device, 0x409500, 0x00000001); | |
1506 | nvkm_wr32(device, 0x409504, 0x00000032); | |
c4584adc BS |
1507 | if (nvkm_msec(device, 2000, |
1508 | if (nvkm_rd32(device, 0x409800)) | |
1509 | break; | |
1510 | ) < 0) | |
30f4e087 | 1511 | return -EBUSY; |
30f4e087 | 1512 | |
276836d4 BS |
1513 | nvkm_wr32(device, 0x409614, 0x00000070); |
1514 | nvkm_wr32(device, 0x409614, 0x00000770); | |
1515 | nvkm_wr32(device, 0x40802c, 0x00000001); | |
30f4e087 BS |
1516 | } |
1517 | ||
bfee3f3d BS |
1518 | if (gr->data == NULL) { |
1519 | int ret = gf100_grctx_generate(gr); | |
ebb945a9 | 1520 | if (ret) { |
109c2f2f | 1521 | nvkm_error(subdev, "failed to construct context\n"); |
ebb945a9 BS |
1522 | return ret; |
1523 | } | |
1524 | } | |
1525 | ||
1526 | return 0; | |
96616b4c | 1527 | } else |
c85ee6ca | 1528 | if (!gr->func->fecs.ucode) { |
96616b4c | 1529 | return -ENOSYS; |
0411de85 | 1530 | } |
966a5b7d | 1531 | |
ac1499d9 | 1532 | /* load HUB microcode */ |
54dcadd5 | 1533 | nvkm_mc_unk260(device->mc, 0); |
276836d4 | 1534 | nvkm_wr32(device, 0x4091c0, 0x01000000); |
c85ee6ca BS |
1535 | for (i = 0; i < gr->func->fecs.ucode->data.size / 4; i++) |
1536 | nvkm_wr32(device, 0x4091c4, gr->func->fecs.ucode->data.data[i]); | |
ac1499d9 | 1537 | |
276836d4 | 1538 | nvkm_wr32(device, 0x409180, 0x01000000); |
c85ee6ca | 1539 | for (i = 0; i < gr->func->fecs.ucode->code.size / 4; i++) { |
ac1499d9 | 1540 | if ((i & 0x3f) == 0) |
276836d4 | 1541 | nvkm_wr32(device, 0x409188, i >> 6); |
c85ee6ca | 1542 | nvkm_wr32(device, 0x409184, gr->func->fecs.ucode->code.data[i]); |
ac1499d9 BS |
1543 | } |
1544 | ||
1545 | /* load GPC microcode */ | |
276836d4 | 1546 | nvkm_wr32(device, 0x41a1c0, 0x01000000); |
c85ee6ca BS |
1547 | for (i = 0; i < gr->func->gpccs.ucode->data.size / 4; i++) |
1548 | nvkm_wr32(device, 0x41a1c4, gr->func->gpccs.ucode->data.data[i]); | |
ac1499d9 | 1549 | |
276836d4 | 1550 | nvkm_wr32(device, 0x41a180, 0x01000000); |
c85ee6ca | 1551 | for (i = 0; i < gr->func->gpccs.ucode->code.size / 4; i++) { |
ac1499d9 | 1552 | if ((i & 0x3f) == 0) |
276836d4 | 1553 | nvkm_wr32(device, 0x41a188, i >> 6); |
c85ee6ca | 1554 | nvkm_wr32(device, 0x41a184, gr->func->gpccs.ucode->code.data[i]); |
ac1499d9 | 1555 | } |
54dcadd5 | 1556 | nvkm_mc_unk260(device->mc, 1); |
966a5b7d | 1557 | |
c33b1e8c | 1558 | /* load register lists */ |
27f3d6cf BS |
1559 | gf100_gr_init_csdata(gr, grctx->hub, 0x409000, 0x000, 0x000000); |
1560 | gf100_gr_init_csdata(gr, grctx->gpc, 0x41a000, 0x000, 0x418000); | |
1561 | gf100_gr_init_csdata(gr, grctx->tpc, 0x41a000, 0x004, 0x419800); | |
1562 | gf100_gr_init_csdata(gr, grctx->ppc, 0x41a000, 0x008, 0x41be00); | |
a32b2ffb | 1563 | |
ac1499d9 | 1564 | /* start HUB ucode running, it'll init the GPCs */ |
276836d4 BS |
1565 | nvkm_wr32(device, 0x40910c, 0x00000000); |
1566 | nvkm_wr32(device, 0x409100, 0x00000002); | |
c4584adc BS |
1567 | if (nvkm_msec(device, 2000, |
1568 | if (nvkm_rd32(device, 0x409800) & 0x80000000) | |
1569 | break; | |
1570 | ) < 0) { | |
bfee3f3d | 1571 | gf100_gr_ctxctl_debug(gr); |
966a5b7d BS |
1572 | return -EBUSY; |
1573 | } | |
966a5b7d | 1574 | |
276836d4 | 1575 | gr->size = nvkm_rd32(device, 0x409804); |
bfee3f3d BS |
1576 | if (gr->data == NULL) { |
1577 | int ret = gf100_grctx_generate(gr); | |
ac1499d9 | 1578 | if (ret) { |
109c2f2f | 1579 | nvkm_error(subdev, "failed to construct context\n"); |
ac1499d9 BS |
1580 | return ret; |
1581 | } | |
966a5b7d BS |
1582 | } |
1583 | ||
1584 | return 0; | |
4b223eef BS |
1585 | } |
1586 | ||
c85ee6ca BS |
1587 | static int |
1588 | gf100_gr_oneinit(struct nvkm_gr *base) | |
1589 | { | |
1590 | struct gf100_gr *gr = gf100_gr(base); | |
1591 | struct nvkm_device *device = gr->base.engine.subdev.device; | |
1592 | int ret, i, j; | |
1593 | ||
1594 | nvkm_pmu_pgob(device->pmu, false); | |
1595 | ||
1596 | ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST, 0x1000, 256, false, | |
1597 | &gr->unk4188b4); | |
1598 | if (ret) | |
1599 | return ret; | |
1600 | ||
1601 | ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST, 0x1000, 256, false, | |
1602 | &gr->unk4188b8); | |
1603 | if (ret) | |
1604 | return ret; | |
1605 | ||
1606 | nvkm_kmap(gr->unk4188b4); | |
1607 | for (i = 0; i < 0x1000; i += 4) | |
1608 | nvkm_wo32(gr->unk4188b4, i, 0x00000010); | |
1609 | nvkm_done(gr->unk4188b4); | |
1610 | ||
1611 | nvkm_kmap(gr->unk4188b8); | |
1612 | for (i = 0; i < 0x1000; i += 4) | |
1613 | nvkm_wo32(gr->unk4188b8, i, 0x00000010); | |
1614 | nvkm_done(gr->unk4188b8); | |
1615 | ||
1616 | gr->rop_nr = (nvkm_rd32(device, 0x409604) & 0x001f0000) >> 16; | |
1617 | gr->gpc_nr = nvkm_rd32(device, 0x409604) & 0x0000001f; | |
1618 | for (i = 0; i < gr->gpc_nr; i++) { | |
1619 | gr->tpc_nr[i] = nvkm_rd32(device, GPC_UNIT(i, 0x2608)); | |
1620 | gr->tpc_total += gr->tpc_nr[i]; | |
1621 | gr->ppc_nr[i] = gr->func->ppc_nr; | |
1622 | for (j = 0; j < gr->ppc_nr[i]; j++) { | |
1623 | u8 mask = nvkm_rd32(device, GPC_UNIT(i, 0x0c30 + (j * 4))); | |
2fb2b3c6 BS |
1624 | if (mask) |
1625 | gr->ppc_mask[i] |= (1 << j); | |
c85ee6ca BS |
1626 | gr->ppc_tpc_nr[i][j] = hweight8(mask); |
1627 | } | |
1628 | } | |
1629 | ||
1630 | /*XXX: these need figuring out... though it might not even matter */ | |
1631 | switch (device->chipset) { | |
1632 | case 0xc0: | |
1633 | if (gr->tpc_total == 11) { /* 465, 3/4/4/0, 4 */ | |
1634 | gr->magic_not_rop_nr = 0x07; | |
1635 | } else | |
1636 | if (gr->tpc_total == 14) { /* 470, 3/3/4/4, 5 */ | |
1637 | gr->magic_not_rop_nr = 0x05; | |
1638 | } else | |
1639 | if (gr->tpc_total == 15) { /* 480, 3/4/4/4, 6 */ | |
1640 | gr->magic_not_rop_nr = 0x06; | |
1641 | } | |
1642 | break; | |
1643 | case 0xc3: /* 450, 4/0/0/0, 2 */ | |
1644 | gr->magic_not_rop_nr = 0x03; | |
1645 | break; | |
1646 | case 0xc4: /* 460, 3/4/0/0, 4 */ | |
1647 | gr->magic_not_rop_nr = 0x01; | |
1648 | break; | |
1649 | case 0xc1: /* 2/0/0/0, 1 */ | |
1650 | gr->magic_not_rop_nr = 0x01; | |
1651 | break; | |
1652 | case 0xc8: /* 4/4/3/4, 5 */ | |
1653 | gr->magic_not_rop_nr = 0x06; | |
1654 | break; | |
1655 | case 0xce: /* 4/4/0/0, 4 */ | |
1656 | gr->magic_not_rop_nr = 0x03; | |
1657 | break; | |
1658 | case 0xcf: /* 4/0/0/0, 3 */ | |
1659 | gr->magic_not_rop_nr = 0x03; | |
1660 | break; | |
1661 | case 0xd7: | |
1662 | case 0xd9: /* 1/0/0/0, 1 */ | |
1663 | case 0xea: /* gk20a */ | |
1664 | case 0x12b: /* gm20b */ | |
1665 | gr->magic_not_rop_nr = 0x01; | |
1666 | break; | |
1667 | } | |
1668 | ||
1669 | return 0; | |
1670 | } | |
1671 | ||
1672 | int | |
1673 | gf100_gr_init_(struct nvkm_gr *base) | |
1674 | { | |
1675 | struct gf100_gr *gr = gf100_gr(base); | |
1676 | nvkm_pmu_pgob(gr->base.engine.subdev.device->pmu, false); | |
1677 | return gr->func->init(gr); | |
1678 | } | |
1679 | ||
1680 | void | |
1681 | gf100_gr_dtor_fw(struct gf100_gr_fuc *fuc) | |
1682 | { | |
1683 | kfree(fuc->data); | |
1684 | fuc->data = NULL; | |
1685 | } | |
1686 | ||
336c4652 AC |
1687 | static void |
1688 | gf100_gr_dtor_init(struct gf100_gr_pack *pack) | |
1689 | { | |
1690 | vfree(pack); | |
1691 | } | |
1692 | ||
c85ee6ca BS |
1693 | void * |
1694 | gf100_gr_dtor(struct nvkm_gr *base) | |
1695 | { | |
1696 | struct gf100_gr *gr = gf100_gr(base); | |
1697 | ||
1698 | if (gr->func->dtor) | |
1699 | gr->func->dtor(gr); | |
1700 | kfree(gr->data); | |
1701 | ||
1702 | gf100_gr_dtor_fw(&gr->fuc409c); | |
1703 | gf100_gr_dtor_fw(&gr->fuc409d); | |
1704 | gf100_gr_dtor_fw(&gr->fuc41ac); | |
1705 | gf100_gr_dtor_fw(&gr->fuc41ad); | |
1706 | ||
336c4652 AC |
1707 | gf100_gr_dtor_init(gr->fuc_bundle); |
1708 | gf100_gr_dtor_init(gr->fuc_method); | |
1709 | gf100_gr_dtor_init(gr->fuc_sw_ctx); | |
1710 | gf100_gr_dtor_init(gr->fuc_sw_nonctx); | |
1711 | ||
c85ee6ca BS |
1712 | nvkm_memory_del(&gr->unk4188b8); |
1713 | nvkm_memory_del(&gr->unk4188b4); | |
1714 | return gr; | |
1715 | } | |
1716 | ||
1717 | static const struct nvkm_gr_func | |
1718 | gf100_gr_ = { | |
1719 | .dtor = gf100_gr_dtor, | |
1720 | .oneinit = gf100_gr_oneinit, | |
1721 | .init = gf100_gr_init_, | |
1722 | .intr = gf100_gr_intr, | |
1723 | .units = gf100_gr_units, | |
1724 | .chan_new = gf100_gr_chan_new, | |
1725 | .object_get = gf100_gr_object_get, | |
1726 | }; | |
1727 | ||
1728 | int | |
1729 | gf100_gr_ctor_fw(struct gf100_gr *gr, const char *fwname, | |
1730 | struct gf100_gr_fuc *fuc) | |
1731 | { | |
1732 | struct nvkm_subdev *subdev = &gr->base.engine.subdev; | |
1733 | struct nvkm_device *device = subdev->device; | |
1734 | const struct firmware *fw; | |
c85ee6ca | 1735 | int ret; |
c85ee6ca | 1736 | |
33bcb4c3 | 1737 | ret = nvkm_firmware_get(device, fwname, &fw); |
c85ee6ca BS |
1738 | if (ret) { |
1739 | nvkm_error(subdev, "failed to load %s\n", fwname); | |
1740 | return ret; | |
1741 | } | |
1742 | ||
1743 | fuc->size = fw->size; | |
1744 | fuc->data = kmemdup(fw->data, fuc->size, GFP_KERNEL); | |
33bcb4c3 | 1745 | nvkm_firmware_put(fw); |
c85ee6ca BS |
1746 | return (fuc->data != NULL) ? 0 : -ENOMEM; |
1747 | } | |
1748 | ||
1749 | int | |
1750 | gf100_gr_ctor(const struct gf100_gr_func *func, struct nvkm_device *device, | |
1751 | int index, struct gf100_gr *gr) | |
1752 | { | |
1753 | int ret; | |
1754 | ||
1755 | gr->func = func; | |
1756 | gr->firmware = nvkm_boolopt(device->cfgopt, "NvGrUseFW", | |
1757 | func->fecs.ucode == NULL); | |
1758 | ||
1759 | ret = nvkm_gr_ctor(&gf100_gr_, device, index, 0x08001000, | |
1760 | gr->firmware || func->fecs.ucode != NULL, | |
1761 | &gr->base); | |
1762 | if (ret) | |
1763 | return ret; | |
1764 | ||
1765 | if (gr->firmware) { | |
1766 | nvkm_info(&gr->base.engine.subdev, "using external firmware\n"); | |
1767 | if (gf100_gr_ctor_fw(gr, "fecs_inst", &gr->fuc409c) || | |
1768 | gf100_gr_ctor_fw(gr, "fecs_data", &gr->fuc409d) || | |
1769 | gf100_gr_ctor_fw(gr, "gpccs_inst", &gr->fuc41ac) || | |
1770 | gf100_gr_ctor_fw(gr, "gpccs_data", &gr->fuc41ad)) | |
1771 | return -ENODEV; | |
1772 | } | |
1773 | ||
1774 | return 0; | |
1775 | } | |
1776 | ||
30f4e087 | 1777 | int |
c85ee6ca BS |
1778 | gf100_gr_new_(const struct gf100_gr_func *func, struct nvkm_device *device, |
1779 | int index, struct nvkm_gr **pgr) | |
1780 | { | |
1781 | struct gf100_gr *gr; | |
1782 | if (!(gr = kzalloc(sizeof(*gr), GFP_KERNEL))) | |
1783 | return -ENOMEM; | |
1784 | *pgr = &gr->base; | |
1785 | return gf100_gr_ctor(func, device, index, gr); | |
1786 | } | |
1787 | ||
1788 | int | |
1789 | gf100_gr_init(struct gf100_gr *gr) | |
4b223eef | 1790 | { |
276836d4 | 1791 | struct nvkm_device *device = gr->base.engine.subdev.device; |
bfee3f3d | 1792 | const u32 magicgpc918 = DIV_ROUND_UP(0x00800000, gr->tpc_total); |
30f4e087 BS |
1793 | u32 data[TPC_MAX / 8] = {}; |
1794 | u8 tpcnr[GPC_MAX]; | |
1795 | int gpc, tpc, rop; | |
c85ee6ca | 1796 | int i; |
ebb945a9 | 1797 | |
276836d4 BS |
1798 | nvkm_wr32(device, GPC_BCAST(0x0880), 0x00000000); |
1799 | nvkm_wr32(device, GPC_BCAST(0x08a4), 0x00000000); | |
1800 | nvkm_wr32(device, GPC_BCAST(0x0888), 0x00000000); | |
1801 | nvkm_wr32(device, GPC_BCAST(0x088c), 0x00000000); | |
1802 | nvkm_wr32(device, GPC_BCAST(0x0890), 0x00000000); | |
1803 | nvkm_wr32(device, GPC_BCAST(0x0894), 0x00000000); | |
227c95d9 BS |
1804 | nvkm_wr32(device, GPC_BCAST(0x08b4), nvkm_memory_addr(gr->unk4188b4) >> 8); |
1805 | nvkm_wr32(device, GPC_BCAST(0x08b8), nvkm_memory_addr(gr->unk4188b8) >> 8); | |
30f4e087 | 1806 | |
c85ee6ca | 1807 | gf100_gr_mmio(gr, gr->func->mmio); |
30f4e087 | 1808 | |
bfee3f3d BS |
1809 | memcpy(tpcnr, gr->tpc_nr, sizeof(gr->tpc_nr)); |
1810 | for (i = 0, gpc = -1; i < gr->tpc_total; i++) { | |
30f4e087 | 1811 | do { |
bfee3f3d | 1812 | gpc = (gpc + 1) % gr->gpc_nr; |
30f4e087 | 1813 | } while (!tpcnr[gpc]); |
bfee3f3d | 1814 | tpc = gr->tpc_nr[gpc] - tpcnr[gpc]--; |
30f4e087 BS |
1815 | |
1816 | data[i / 8] |= tpc << ((i % 8) * 4); | |
1817 | } | |
1818 | ||
276836d4 BS |
1819 | nvkm_wr32(device, GPC_BCAST(0x0980), data[0]); |
1820 | nvkm_wr32(device, GPC_BCAST(0x0984), data[1]); | |
1821 | nvkm_wr32(device, GPC_BCAST(0x0988), data[2]); | |
1822 | nvkm_wr32(device, GPC_BCAST(0x098c), data[3]); | |
30f4e087 | 1823 | |
bfee3f3d | 1824 | for (gpc = 0; gpc < gr->gpc_nr; gpc++) { |
276836d4 | 1825 | nvkm_wr32(device, GPC_UNIT(gpc, 0x0914), |
bfee3f3d | 1826 | gr->magic_not_rop_nr << 8 | gr->tpc_nr[gpc]); |
276836d4 | 1827 | nvkm_wr32(device, GPC_UNIT(gpc, 0x0910), 0x00040000 | |
bfee3f3d | 1828 | gr->tpc_total); |
276836d4 | 1829 | nvkm_wr32(device, GPC_UNIT(gpc, 0x0918), magicgpc918); |
30f4e087 BS |
1830 | } |
1831 | ||
c85ee6ca | 1832 | if (device->chipset != 0xd7) |
276836d4 | 1833 | nvkm_wr32(device, GPC_BCAST(0x1bd4), magicgpc918); |
26410c67 | 1834 | else |
276836d4 | 1835 | nvkm_wr32(device, GPC_BCAST(0x3fd4), magicgpc918); |
bfee3f3d | 1836 | |
276836d4 | 1837 | nvkm_wr32(device, GPC_BCAST(0x08ac), nvkm_rd32(device, 0x100800)); |
bfee3f3d | 1838 | |
276836d4 | 1839 | nvkm_wr32(device, 0x400500, 0x00010001); |
bfee3f3d | 1840 | |
276836d4 BS |
1841 | nvkm_wr32(device, 0x400100, 0xffffffff); |
1842 | nvkm_wr32(device, 0x40013c, 0xffffffff); | |
bfee3f3d | 1843 | |
276836d4 BS |
1844 | nvkm_wr32(device, 0x409c24, 0x000f0000); |
1845 | nvkm_wr32(device, 0x404000, 0xc0000000); | |
1846 | nvkm_wr32(device, 0x404600, 0xc0000000); | |
1847 | nvkm_wr32(device, 0x408030, 0xc0000000); | |
1848 | nvkm_wr32(device, 0x40601c, 0xc0000000); | |
1849 | nvkm_wr32(device, 0x404490, 0xc0000000); | |
1850 | nvkm_wr32(device, 0x406018, 0xc0000000); | |
1851 | nvkm_wr32(device, 0x405840, 0xc0000000); | |
1852 | nvkm_wr32(device, 0x405844, 0x00ffffff); | |
1853 | nvkm_mask(device, 0x419cc0, 0x00000008, 0x00000008); | |
1854 | nvkm_mask(device, 0x419eb4, 0x00001000, 0x00001000); | |
bfee3f3d BS |
1855 | |
1856 | for (gpc = 0; gpc < gr->gpc_nr; gpc++) { | |
276836d4 BS |
1857 | nvkm_wr32(device, GPC_UNIT(gpc, 0x0420), 0xc0000000); |
1858 | nvkm_wr32(device, GPC_UNIT(gpc, 0x0900), 0xc0000000); | |
1859 | nvkm_wr32(device, GPC_UNIT(gpc, 0x1028), 0xc0000000); | |
1860 | nvkm_wr32(device, GPC_UNIT(gpc, 0x0824), 0xc0000000); | |
bfee3f3d | 1861 | for (tpc = 0; tpc < gr->tpc_nr[gpc]; tpc++) { |
276836d4 BS |
1862 | nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x508), 0xffffffff); |
1863 | nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x50c), 0xffffffff); | |
1864 | nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x224), 0xc0000000); | |
1865 | nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x48c), 0xc0000000); | |
1866 | nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x084), 0xc0000000); | |
1867 | nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x644), 0x001ffffe); | |
1868 | nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x64c), 0x0000000f); | |
30f4e087 | 1869 | } |
276836d4 BS |
1870 | nvkm_wr32(device, GPC_UNIT(gpc, 0x2c90), 0xffffffff); |
1871 | nvkm_wr32(device, GPC_UNIT(gpc, 0x2c94), 0xffffffff); | |
30f4e087 BS |
1872 | } |
1873 | ||
bfee3f3d | 1874 | for (rop = 0; rop < gr->rop_nr; rop++) { |
276836d4 BS |
1875 | nvkm_wr32(device, ROP_UNIT(rop, 0x144), 0xc0000000); |
1876 | nvkm_wr32(device, ROP_UNIT(rop, 0x070), 0xc0000000); | |
1877 | nvkm_wr32(device, ROP_UNIT(rop, 0x204), 0xffffffff); | |
1878 | nvkm_wr32(device, ROP_UNIT(rop, 0x208), 0xffffffff); | |
30f4e087 | 1879 | } |
ebb945a9 | 1880 | |
276836d4 BS |
1881 | nvkm_wr32(device, 0x400108, 0xffffffff); |
1882 | nvkm_wr32(device, 0x400138, 0xffffffff); | |
1883 | nvkm_wr32(device, 0x400118, 0xffffffff); | |
1884 | nvkm_wr32(device, 0x400130, 0xffffffff); | |
1885 | nvkm_wr32(device, 0x40011c, 0xffffffff); | |
1886 | nvkm_wr32(device, 0x400134, 0xffffffff); | |
30f4e087 | 1887 | |
276836d4 | 1888 | nvkm_wr32(device, 0x400054, 0x34ce3464); |
ac9738bb | 1889 | |
bfee3f3d | 1890 | gf100_gr_zbc_init(gr); |
ac9738bb | 1891 | |
bfee3f3d | 1892 | return gf100_gr_init_ctxctl(gr); |
30f4e087 BS |
1893 | } |
1894 | ||
e3c71eb2 | 1895 | #include "fuc/hubgf100.fuc3.h" |
30f4e087 | 1896 | |
e3c71eb2 BS |
1897 | struct gf100_gr_ucode |
1898 | gf100_gr_fecs_ucode = { | |
1899 | .code.data = gf100_grhub_code, | |
1900 | .code.size = sizeof(gf100_grhub_code), | |
1901 | .data.data = gf100_grhub_data, | |
1902 | .data.size = sizeof(gf100_grhub_data), | |
30f4e087 BS |
1903 | }; |
1904 | ||
e3c71eb2 | 1905 | #include "fuc/gpcgf100.fuc3.h" |
30f4e087 | 1906 | |
e3c71eb2 BS |
1907 | struct gf100_gr_ucode |
1908 | gf100_gr_gpccs_ucode = { | |
1909 | .code.data = gf100_grgpc_code, | |
1910 | .code.size = sizeof(gf100_grgpc_code), | |
1911 | .data.data = gf100_grgpc_data, | |
1912 | .data.size = sizeof(gf100_grgpc_data), | |
30f4e087 BS |
1913 | }; |
1914 | ||
27f3d6cf BS |
1915 | static const struct gf100_gr_func |
1916 | gf100_gr = { | |
c85ee6ca BS |
1917 | .init = gf100_gr_init, |
1918 | .mmio = gf100_gr_pack_mmio, | |
1919 | .fecs.ucode = &gf100_gr_fecs_ucode, | |
1920 | .gpccs.ucode = &gf100_gr_gpccs_ucode, | |
27f3d6cf BS |
1921 | .grctx = &gf100_grctx, |
1922 | .sclass = { | |
1923 | { -1, -1, FERMI_TWOD_A }, | |
1924 | { -1, -1, FERMI_MEMORY_TO_MEMORY_FORMAT_A }, | |
1925 | { -1, -1, FERMI_A, &gf100_fermi }, | |
1926 | { -1, -1, FERMI_COMPUTE_A }, | |
1927 | {} | |
1928 | } | |
1929 | }; | |
1930 | ||
c85ee6ca BS |
1931 | int |
1932 | gf100_gr_new(struct nvkm_device *device, int index, struct nvkm_gr **pgr) | |
1933 | { | |
1934 | return gf100_gr_new_(&gf100_gr, device, index, pgr); | |
1935 | } |