blob: 9066102d11594c527e9beb54d581f8b891902967 [file] [log] [blame]
Ben Skeggs4b223ee2010-08-03 10:00:56 +10001/*
2 * Copyright 2010 Red Hat Inc.
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 */
24
Ben Skeggs966a5b72010-11-24 10:49:02 +100025#include <linux/firmware.h>
Paul Gortmakere0cd3602011-08-30 11:04:30 -040026#include <linux/module.h>
Ben Skeggs966a5b72010-11-24 10:49:02 +100027
Ben Skeggs4b223ee2010-08-03 10:00:56 +100028#include "drmP.h"
29
30#include "nouveau_drv.h"
Ben Skeggs966a5b72010-11-24 10:49:02 +100031#include "nouveau_mm.h"
Ben Skeggs0411de82011-05-25 18:32:44 +100032
Ben Skeggs966a5b72010-11-24 10:49:02 +100033#include "nvc0_graph.h"
Ben Skeggs0411de82011-05-25 18:32:44 +100034#include "nvc0_grhub.fuc.h"
35#include "nvc0_grgpc.fuc.h"
36
37static void
38nvc0_graph_ctxctl_debug_unit(struct drm_device *dev, u32 base)
39{
40 NV_INFO(dev, "PGRAPH: %06x - done 0x%08x\n", base,
41 nv_rd32(dev, base + 0x400));
42 NV_INFO(dev, "PGRAPH: %06x - stat 0x%08x 0x%08x 0x%08x 0x%08x\n", base,
43 nv_rd32(dev, base + 0x800), nv_rd32(dev, base + 0x804),
44 nv_rd32(dev, base + 0x808), nv_rd32(dev, base + 0x80c));
45 NV_INFO(dev, "PGRAPH: %06x - stat 0x%08x 0x%08x 0x%08x 0x%08x\n", base,
46 nv_rd32(dev, base + 0x810), nv_rd32(dev, base + 0x814),
47 nv_rd32(dev, base + 0x818), nv_rd32(dev, base + 0x81c));
48}
49
50static void
51nvc0_graph_ctxctl_debug(struct drm_device *dev)
52{
53 u32 gpcnr = nv_rd32(dev, 0x409604) & 0xffff;
54 u32 gpc;
55
56 nvc0_graph_ctxctl_debug_unit(dev, 0x409000);
57 for (gpc = 0; gpc < gpcnr; gpc++)
58 nvc0_graph_ctxctl_debug_unit(dev, 0x502000 + (gpc * 0x8000));
59}
Ben Skeggs966a5b72010-11-24 10:49:02 +100060
Ben Skeggs966a5b72010-11-24 10:49:02 +100061static int
Ben Skeggs7a45cd12011-04-01 10:59:53 +100062nvc0_graph_load_context(struct nouveau_channel *chan)
63{
64 struct drm_device *dev = chan->dev;
65
66 nv_wr32(dev, 0x409840, 0x00000030);
67 nv_wr32(dev, 0x409500, 0x80000000 | chan->ramin->vinst >> 12);
68 nv_wr32(dev, 0x409504, 0x00000003);
69 if (!nv_wait(dev, 0x409800, 0x00000010, 0x00000010))
70 NV_ERROR(dev, "PGRAPH: load_ctx timeout\n");
71
72 return 0;
73}
74
75static int
76nvc0_graph_unload_context_to(struct drm_device *dev, u64 chan)
77{
78 nv_wr32(dev, 0x409840, 0x00000003);
79 nv_wr32(dev, 0x409500, 0x80000000 | chan >> 12);
80 nv_wr32(dev, 0x409504, 0x00000009);
81 if (!nv_wait(dev, 0x409800, 0x00000001, 0x00000000)) {
82 NV_ERROR(dev, "PGRAPH: unload_ctx timeout\n");
83 return -EBUSY;
84 }
85
86 return 0;
87}
88
89static int
Ben Skeggs966a5b72010-11-24 10:49:02 +100090nvc0_graph_construct_context(struct nouveau_channel *chan)
91{
92 struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
Ben Skeggs7a45cd12011-04-01 10:59:53 +100093 struct nvc0_graph_priv *priv = nv_engine(chan->dev, NVOBJ_ENGINE_GR);
94 struct nvc0_graph_chan *grch = chan->engctx[NVOBJ_ENGINE_GR];
Ben Skeggs966a5b72010-11-24 10:49:02 +100095 struct drm_device *dev = chan->dev;
96 int ret, i;
97 u32 *ctx;
98
99 ctx = kmalloc(priv->grctx_size, GFP_KERNEL);
100 if (!ctx)
101 return -ENOMEM;
102
Ben Skeggs0411de82011-05-25 18:32:44 +1000103 if (!nouveau_ctxfw) {
104 nv_wr32(dev, 0x409840, 0x80000000);
105 nv_wr32(dev, 0x409500, 0x80000000 | chan->ramin->vinst >> 12);
106 nv_wr32(dev, 0x409504, 0x00000001);
107 if (!nv_wait(dev, 0x409800, 0x80000000, 0x80000000)) {
108 NV_ERROR(dev, "PGRAPH: HUB_SET_CHAN timeout\n");
109 nvc0_graph_ctxctl_debug(dev);
Dan Carpenter60f7ab02011-06-25 08:54:46 +0300110 ret = -EBUSY;
111 goto err;
Ben Skeggs0411de82011-05-25 18:32:44 +1000112 }
113 } else {
114 nvc0_graph_load_context(chan);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000115
Ben Skeggs0411de82011-05-25 18:32:44 +1000116 nv_wo32(grch->grctx, 0x1c, 1);
117 nv_wo32(grch->grctx, 0x20, 0);
118 nv_wo32(grch->grctx, 0x28, 0);
119 nv_wo32(grch->grctx, 0x2c, 0);
120 dev_priv->engine.instmem.flush(dev);
121 }
Ben Skeggs966a5b72010-11-24 10:49:02 +1000122
123 ret = nvc0_grctx_generate(chan);
Dan Carpenter60f7ab02011-06-25 08:54:46 +0300124 if (ret)
125 goto err;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000126
Ben Skeggs0411de82011-05-25 18:32:44 +1000127 if (!nouveau_ctxfw) {
128 nv_wr32(dev, 0x409840, 0x80000000);
129 nv_wr32(dev, 0x409500, 0x80000000 | chan->ramin->vinst >> 12);
130 nv_wr32(dev, 0x409504, 0x00000002);
131 if (!nv_wait(dev, 0x409800, 0x80000000, 0x80000000)) {
132 NV_ERROR(dev, "PGRAPH: HUB_CTX_SAVE timeout\n");
133 nvc0_graph_ctxctl_debug(dev);
Dan Carpenter60f7ab02011-06-25 08:54:46 +0300134 ret = -EBUSY;
135 goto err;
Ben Skeggs0411de82011-05-25 18:32:44 +1000136 }
137 } else {
138 ret = nvc0_graph_unload_context_to(dev, chan->ramin->vinst);
Dan Carpenter60f7ab02011-06-25 08:54:46 +0300139 if (ret)
140 goto err;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000141 }
142
143 for (i = 0; i < priv->grctx_size; i += 4)
144 ctx[i / 4] = nv_ro32(grch->grctx, i);
145
146 priv->grctx_vals = ctx;
147 return 0;
Dan Carpenter60f7ab02011-06-25 08:54:46 +0300148
149err:
150 kfree(ctx);
151 return ret;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000152}
153
154static int
155nvc0_graph_create_context_mmio_list(struct nouveau_channel *chan)
156{
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000157 struct nvc0_graph_priv *priv = nv_engine(chan->dev, NVOBJ_ENGINE_GR);
158 struct nvc0_graph_chan *grch = chan->engctx[NVOBJ_ENGINE_GR];
Ben Skeggs966a5b72010-11-24 10:49:02 +1000159 struct drm_device *dev = chan->dev;
Ben Skeggs6688a4d2011-10-28 11:43:04 +1000160 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000161 int i = 0, gpc, tp, ret;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000162
Ben Skeggs6e32fed2011-06-03 14:23:30 +1000163 ret = nouveau_gpuobj_new(dev, chan, 0x2000, 256, NVOBJ_FLAG_VM,
Ben Skeggs966a5b72010-11-24 10:49:02 +1000164 &grch->unk408004);
165 if (ret)
166 return ret;
167
Ben Skeggs6e32fed2011-06-03 14:23:30 +1000168 ret = nouveau_gpuobj_new(dev, chan, 0x8000, 256, NVOBJ_FLAG_VM,
Ben Skeggs966a5b72010-11-24 10:49:02 +1000169 &grch->unk40800c);
170 if (ret)
171 return ret;
172
Ben Skeggs6e32fed2011-06-03 14:23:30 +1000173 ret = nouveau_gpuobj_new(dev, chan, 384 * 1024, 4096,
Ben Skeggsc906ca02011-01-14 10:27:02 +1000174 NVOBJ_FLAG_VM | NVOBJ_FLAG_VM_USER,
Ben Skeggs966a5b72010-11-24 10:49:02 +1000175 &grch->unk418810);
176 if (ret)
177 return ret;
178
Ben Skeggs6e32fed2011-06-03 14:23:30 +1000179 ret = nouveau_gpuobj_new(dev, chan, 0x1000, 0, NVOBJ_FLAG_VM,
Ben Skeggs966a5b72010-11-24 10:49:02 +1000180 &grch->mmio);
181 if (ret)
182 return ret;
183
184
185 nv_wo32(grch->mmio, i++ * 4, 0x00408004);
Ben Skeggsf8522fc2011-05-25 17:22:43 +1000186 nv_wo32(grch->mmio, i++ * 4, grch->unk408004->linst >> 8);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000187 nv_wo32(grch->mmio, i++ * 4, 0x00408008);
188 nv_wo32(grch->mmio, i++ * 4, 0x80000018);
189
190 nv_wo32(grch->mmio, i++ * 4, 0x0040800c);
Ben Skeggsf8522fc2011-05-25 17:22:43 +1000191 nv_wo32(grch->mmio, i++ * 4, grch->unk40800c->linst >> 8);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000192 nv_wo32(grch->mmio, i++ * 4, 0x00408010);
193 nv_wo32(grch->mmio, i++ * 4, 0x80000000);
194
195 nv_wo32(grch->mmio, i++ * 4, 0x00418810);
Ben Skeggsf8522fc2011-05-25 17:22:43 +1000196 nv_wo32(grch->mmio, i++ * 4, 0x80000000 | grch->unk418810->linst >> 12);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000197 nv_wo32(grch->mmio, i++ * 4, 0x00419848);
Ben Skeggsf8522fc2011-05-25 17:22:43 +1000198 nv_wo32(grch->mmio, i++ * 4, 0x10000000 | grch->unk418810->linst >> 12);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000199
200 nv_wo32(grch->mmio, i++ * 4, 0x00419004);
Ben Skeggsf8522fc2011-05-25 17:22:43 +1000201 nv_wo32(grch->mmio, i++ * 4, grch->unk40800c->linst >> 8);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000202 nv_wo32(grch->mmio, i++ * 4, 0x00419008);
203 nv_wo32(grch->mmio, i++ * 4, 0x00000000);
204
205 nv_wo32(grch->mmio, i++ * 4, 0x00418808);
Ben Skeggsf8522fc2011-05-25 17:22:43 +1000206 nv_wo32(grch->mmio, i++ * 4, grch->unk408004->linst >> 8);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000207 nv_wo32(grch->mmio, i++ * 4, 0x0041880c);
208 nv_wo32(grch->mmio, i++ * 4, 0x80000018);
209
Ben Skeggs6688a4d2011-10-28 11:43:04 +1000210 if (dev_priv->chipset != 0xc1) {
211 u32 magic = 0x02180000;
212 nv_wo32(grch->mmio, i++ * 4, 0x00405830);
213 nv_wo32(grch->mmio, i++ * 4, magic);
214 for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
215 for (tp = 0; tp < priv->tp_nr[gpc]; tp++) {
216 u32 reg = TP_UNIT(gpc, tp, 0x520);
217 nv_wo32(grch->mmio, i++ * 4, reg);
218 nv_wo32(grch->mmio, i++ * 4, magic);
219 magic += 0x0324;
220 }
221 }
222 } else {
223 u32 magic = 0x02180000;
224 nv_wo32(grch->mmio, i++ * 4, 0x00405830);
225 nv_wo32(grch->mmio, i++ * 4, magic | 0x0000218);
226 nv_wo32(grch->mmio, i++ * 4, 0x004064c4);
227 nv_wo32(grch->mmio, i++ * 4, 0x0086ffff);
228 for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
229 for (tp = 0; tp < priv->tp_nr[gpc]; tp++) {
230 u32 reg = TP_UNIT(gpc, tp, 0x520);
231 nv_wo32(grch->mmio, i++ * 4, reg);
232 nv_wo32(grch->mmio, i++ * 4, (1 << 28) | magic);
233 magic += 0x0324;
234 }
235 for (tp = 0; tp < priv->tp_nr[gpc]; tp++) {
236 u32 reg = TP_UNIT(gpc, tp, 0x544);
237 nv_wo32(grch->mmio, i++ * 4, reg);
238 nv_wo32(grch->mmio, i++ * 4, magic);
239 magic += 0x0324;
240 }
Ben Skeggs966a5b72010-11-24 10:49:02 +1000241 }
242 }
243
244 grch->mmio_nr = i / 2;
245 return 0;
246}
247
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000248static int
249nvc0_graph_context_new(struct nouveau_channel *chan, int engine)
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000250{
Ben Skeggs966a5b72010-11-24 10:49:02 +1000251 struct drm_device *dev = chan->dev;
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000252 struct drm_nouveau_private *dev_priv = dev->dev_private;
253 struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem;
254 struct nvc0_graph_priv *priv = nv_engine(dev, engine);
255 struct nvc0_graph_chan *grch;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000256 struct nouveau_gpuobj *grctx;
257 int ret, i;
258
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000259 grch = kzalloc(sizeof(*grch), GFP_KERNEL);
260 if (!grch)
Ben Skeggs966a5b72010-11-24 10:49:02 +1000261 return -ENOMEM;
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000262 chan->engctx[NVOBJ_ENGINE_GR] = grch;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000263
Ben Skeggs6e32fed2011-06-03 14:23:30 +1000264 ret = nouveau_gpuobj_new(dev, chan, priv->grctx_size, 256,
Ben Skeggs966a5b72010-11-24 10:49:02 +1000265 NVOBJ_FLAG_VM | NVOBJ_FLAG_ZERO_ALLOC,
266 &grch->grctx);
267 if (ret)
268 goto error;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000269 grctx = grch->grctx;
270
271 ret = nvc0_graph_create_context_mmio_list(chan);
272 if (ret)
273 goto error;
274
Ben Skeggsf8522fc2011-05-25 17:22:43 +1000275 nv_wo32(chan->ramin, 0x0210, lower_32_bits(grctx->linst) | 4);
276 nv_wo32(chan->ramin, 0x0214, upper_32_bits(grctx->linst));
Ben Skeggs966a5b72010-11-24 10:49:02 +1000277 pinstmem->flush(dev);
278
279 if (!priv->grctx_vals) {
280 ret = nvc0_graph_construct_context(chan);
281 if (ret)
282 goto error;
283 }
284
285 for (i = 0; i < priv->grctx_size; i += 4)
286 nv_wo32(grctx, i, priv->grctx_vals[i / 4]);
287
Ben Skeggs0411de82011-05-25 18:32:44 +1000288 if (!nouveau_ctxfw) {
289 nv_wo32(grctx, 0x00, grch->mmio_nr);
290 nv_wo32(grctx, 0x04, grch->mmio->linst >> 8);
291 } else {
292 nv_wo32(grctx, 0xf4, 0);
293 nv_wo32(grctx, 0xf8, 0);
294 nv_wo32(grctx, 0x10, grch->mmio_nr);
295 nv_wo32(grctx, 0x14, lower_32_bits(grch->mmio->linst));
296 nv_wo32(grctx, 0x18, upper_32_bits(grch->mmio->linst));
297 nv_wo32(grctx, 0x1c, 1);
298 nv_wo32(grctx, 0x20, 0);
299 nv_wo32(grctx, 0x28, 0);
300 nv_wo32(grctx, 0x2c, 0);
301 }
Ben Skeggs966a5b72010-11-24 10:49:02 +1000302 pinstmem->flush(dev);
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000303 return 0;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000304
305error:
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000306 priv->base.context_del(chan, engine);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000307 return ret;
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000308}
309
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000310static void
311nvc0_graph_context_del(struct nouveau_channel *chan, int engine)
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000312{
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000313 struct nvc0_graph_chan *grch = chan->engctx[engine];
Ben Skeggs966a5b72010-11-24 10:49:02 +1000314
315 nouveau_gpuobj_ref(NULL, &grch->mmio);
316 nouveau_gpuobj_ref(NULL, &grch->unk418810);
317 nouveau_gpuobj_ref(NULL, &grch->unk40800c);
318 nouveau_gpuobj_ref(NULL, &grch->unk408004);
319 nouveau_gpuobj_ref(NULL, &grch->grctx);
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000320 chan->engctx[engine] = NULL;
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000321}
322
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000323static int
324nvc0_graph_object_new(struct nouveau_channel *chan, int engine,
325 u32 handle, u16 class)
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000326{
Ben Skeggs966a5b72010-11-24 10:49:02 +1000327 return 0;
328}
329
330static int
Ben Skeggs6c320fe2011-07-20 11:22:33 +1000331nvc0_graph_fini(struct drm_device *dev, int engine, bool suspend)
Ben Skeggs966a5b72010-11-24 10:49:02 +1000332{
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000333 return 0;
334}
335
Ben Skeggs966a5b72010-11-24 10:49:02 +1000336static void
337nvc0_graph_init_obj418880(struct drm_device *dev)
338{
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000339 struct nvc0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000340 int i;
341
342 nv_wr32(dev, GPC_BCAST(0x0880), 0x00000000);
343 nv_wr32(dev, GPC_BCAST(0x08a4), 0x00000000);
344 for (i = 0; i < 4; i++)
345 nv_wr32(dev, GPC_BCAST(0x0888) + (i * 4), 0x00000000);
346 nv_wr32(dev, GPC_BCAST(0x08b4), priv->unk4188b4->vinst >> 8);
347 nv_wr32(dev, GPC_BCAST(0x08b8), priv->unk4188b8->vinst >> 8);
348}
349
350static void
351nvc0_graph_init_regs(struct drm_device *dev)
352{
353 nv_wr32(dev, 0x400080, 0x003083c2);
354 nv_wr32(dev, 0x400088, 0x00006fe7);
355 nv_wr32(dev, 0x40008c, 0x00000000);
356 nv_wr32(dev, 0x400090, 0x00000030);
357 nv_wr32(dev, 0x40013c, 0x013901f7);
358 nv_wr32(dev, 0x400140, 0x00000100);
359 nv_wr32(dev, 0x400144, 0x00000000);
360 nv_wr32(dev, 0x400148, 0x00000110);
361 nv_wr32(dev, 0x400138, 0x00000000);
362 nv_wr32(dev, 0x400130, 0x00000000);
363 nv_wr32(dev, 0x400134, 0x00000000);
364 nv_wr32(dev, 0x400124, 0x00000002);
365}
366
367static void
368nvc0_graph_init_gpc_0(struct drm_device *dev)
369{
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000370 struct nvc0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
Ben Skeggs066d65d2011-05-26 12:12:43 +1000371 const u32 magicgpc918 = DIV_ROUND_UP(0x00800000, priv->tp_total);
Ben Skeggsaa58c402011-04-18 12:52:47 +1000372 u32 data[TP_MAX / 8];
373 u8 tpnr[GPC_MAX];
374 int i, gpc, tpc;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000375
Christoph Bumillerffe2dee2011-11-11 20:47:58 +0100376 nv_wr32(dev, TP_UNIT(0, 0, 0x5c), 1); /* affects TFB offset queries */
377
Emil Velikovf2129492011-03-19 23:31:52 +0000378 /*
379 * TP ROP UNKVAL(magic_not_rop_nr)
380 * 450: 4/0/0/0 2 3
381 * 460: 3/4/0/0 4 1
382 * 465: 3/4/4/0 4 7
383 * 470: 3/3/4/4 5 5
384 * 480: 3/4/4/4 6 6
Emil Velikovf2129492011-03-19 23:31:52 +0000385 */
386
Ben Skeggsaa58c402011-04-18 12:52:47 +1000387 memset(data, 0x00, sizeof(data));
388 memcpy(tpnr, priv->tp_nr, sizeof(priv->tp_nr));
389 for (i = 0, gpc = -1; i < priv->tp_total; i++) {
390 do {
391 gpc = (gpc + 1) % priv->gpc_nr;
392 } while (!tpnr[gpc]);
393 tpc = priv->tp_nr[gpc] - tpnr[gpc]--;
394
395 data[i / 8] |= tpc << ((i % 8) * 4);
396 }
397
398 nv_wr32(dev, GPC_BCAST(0x0980), data[0]);
399 nv_wr32(dev, GPC_BCAST(0x0984), data[1]);
400 nv_wr32(dev, GPC_BCAST(0x0988), data[2]);
401 nv_wr32(dev, GPC_BCAST(0x098c), data[3]);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000402
403 for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
404 nv_wr32(dev, GPC_UNIT(gpc, 0x0914), priv->magic_not_rop_nr << 8 |
405 priv->tp_nr[gpc]);
406 nv_wr32(dev, GPC_UNIT(gpc, 0x0910), 0x00040000 | priv->tp_total);
Ben Skeggs066d65d2011-05-26 12:12:43 +1000407 nv_wr32(dev, GPC_UNIT(gpc, 0x0918), magicgpc918);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000408 }
409
Ben Skeggs066d65d2011-05-26 12:12:43 +1000410 nv_wr32(dev, GPC_BCAST(0x1bd4), magicgpc918);
Ben Skeggse425e0b2011-06-29 10:42:14 +1000411 nv_wr32(dev, GPC_BCAST(0x08ac), nv_rd32(dev, 0x100800));
Ben Skeggs966a5b72010-11-24 10:49:02 +1000412}
413
414static void
415nvc0_graph_init_units(struct drm_device *dev)
416{
417 nv_wr32(dev, 0x409c24, 0x000f0000);
418 nv_wr32(dev, 0x404000, 0xc0000000); /* DISPATCH */
419 nv_wr32(dev, 0x404600, 0xc0000000); /* M2MF */
420 nv_wr32(dev, 0x408030, 0xc0000000);
421 nv_wr32(dev, 0x40601c, 0xc0000000);
422 nv_wr32(dev, 0x404490, 0xc0000000); /* MACRO */
423 nv_wr32(dev, 0x406018, 0xc0000000);
424 nv_wr32(dev, 0x405840, 0xc0000000);
425 nv_wr32(dev, 0x405844, 0x00ffffff);
426 nv_mask(dev, 0x419cc0, 0x00000008, 0x00000008);
427 nv_mask(dev, 0x419eb4, 0x00001000, 0x00001000);
428}
429
430static void
431nvc0_graph_init_gpc_1(struct drm_device *dev)
432{
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000433 struct nvc0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000434 int gpc, tp;
435
436 for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
437 nv_wr32(dev, GPC_UNIT(gpc, 0x0420), 0xc0000000);
438 nv_wr32(dev, GPC_UNIT(gpc, 0x0900), 0xc0000000);
439 nv_wr32(dev, GPC_UNIT(gpc, 0x1028), 0xc0000000);
440 nv_wr32(dev, GPC_UNIT(gpc, 0x0824), 0xc0000000);
441 for (tp = 0; tp < priv->tp_nr[gpc]; tp++) {
442 nv_wr32(dev, TP_UNIT(gpc, tp, 0x508), 0xffffffff);
443 nv_wr32(dev, TP_UNIT(gpc, tp, 0x50c), 0xffffffff);
444 nv_wr32(dev, TP_UNIT(gpc, tp, 0x224), 0xc0000000);
445 nv_wr32(dev, TP_UNIT(gpc, tp, 0x48c), 0xc0000000);
446 nv_wr32(dev, TP_UNIT(gpc, tp, 0x084), 0xc0000000);
Ben Skeggs0f1cb202011-01-21 11:15:16 +1000447 nv_wr32(dev, TP_UNIT(gpc, tp, 0x644), 0x001ffffe);
448 nv_wr32(dev, TP_UNIT(gpc, tp, 0x64c), 0x0000000f);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000449 }
450 nv_wr32(dev, GPC_UNIT(gpc, 0x2c90), 0xffffffff);
451 nv_wr32(dev, GPC_UNIT(gpc, 0x2c94), 0xffffffff);
452 }
453}
454
455static void
456nvc0_graph_init_rop(struct drm_device *dev)
457{
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000458 struct nvc0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000459 int rop;
460
461 for (rop = 0; rop < priv->rop_nr; rop++) {
462 nv_wr32(dev, ROP_UNIT(rop, 0x144), 0xc0000000);
463 nv_wr32(dev, ROP_UNIT(rop, 0x070), 0xc0000000);
464 nv_wr32(dev, ROP_UNIT(rop, 0x204), 0xffffffff);
465 nv_wr32(dev, ROP_UNIT(rop, 0x208), 0xffffffff);
466 }
467}
468
Ben Skeggsfe799112011-04-12 18:50:36 +1000469static void
470nvc0_graph_init_fuc(struct drm_device *dev, u32 fuc_base,
471 struct nvc0_graph_fuc *code, struct nvc0_graph_fuc *data)
Ben Skeggs966a5b72010-11-24 10:49:02 +1000472{
Ben Skeggsfe799112011-04-12 18:50:36 +1000473 int i;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000474
475 nv_wr32(dev, fuc_base + 0x01c0, 0x01000000);
Ben Skeggsfe799112011-04-12 18:50:36 +1000476 for (i = 0; i < data->size / 4; i++)
477 nv_wr32(dev, fuc_base + 0x01c4, data->data[i]);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000478
479 nv_wr32(dev, fuc_base + 0x0180, 0x01000000);
Ben Skeggsfe799112011-04-12 18:50:36 +1000480 for (i = 0; i < code->size / 4; i++) {
Ben Skeggs966a5b72010-11-24 10:49:02 +1000481 if ((i & 0x3f) == 0)
482 nv_wr32(dev, fuc_base + 0x0188, i >> 6);
Ben Skeggsfe799112011-04-12 18:50:36 +1000483 nv_wr32(dev, fuc_base + 0x0184, code->data[i]);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000484 }
Ben Skeggs966a5b72010-11-24 10:49:02 +1000485}
486
487static int
488nvc0_graph_init_ctxctl(struct drm_device *dev)
489{
Ben Skeggs0411de82011-05-25 18:32:44 +1000490 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000491 struct nvc0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000492 u32 r000260;
Ben Skeggs0411de82011-05-25 18:32:44 +1000493 int i;
494
495 if (!nouveau_ctxfw) {
496 /* load HUB microcode */
497 r000260 = nv_mask(dev, 0x000260, 0x00000001, 0x00000000);
498 nv_wr32(dev, 0x4091c0, 0x01000000);
499 for (i = 0; i < sizeof(nvc0_grhub_data) / 4; i++)
500 nv_wr32(dev, 0x4091c4, nvc0_grhub_data[i]);
501
502 nv_wr32(dev, 0x409180, 0x01000000);
503 for (i = 0; i < sizeof(nvc0_grhub_code) / 4; i++) {
504 if ((i & 0x3f) == 0)
505 nv_wr32(dev, 0x409188, i >> 6);
506 nv_wr32(dev, 0x409184, nvc0_grhub_code[i]);
507 }
508
509 /* load GPC microcode */
510 nv_wr32(dev, 0x41a1c0, 0x01000000);
511 for (i = 0; i < sizeof(nvc0_grgpc_data) / 4; i++)
512 nv_wr32(dev, 0x41a1c4, nvc0_grgpc_data[i]);
513
514 nv_wr32(dev, 0x41a180, 0x01000000);
515 for (i = 0; i < sizeof(nvc0_grgpc_code) / 4; i++) {
516 if ((i & 0x3f) == 0)
517 nv_wr32(dev, 0x41a188, i >> 6);
518 nv_wr32(dev, 0x41a184, nvc0_grgpc_code[i]);
519 }
520 nv_wr32(dev, 0x000260, r000260);
521
522 /* start HUB ucode running, it'll init the GPCs */
523 nv_wr32(dev, 0x409800, dev_priv->chipset);
524 nv_wr32(dev, 0x40910c, 0x00000000);
525 nv_wr32(dev, 0x409100, 0x00000002);
526 if (!nv_wait(dev, 0x409800, 0x80000000, 0x80000000)) {
527 NV_ERROR(dev, "PGRAPH: HUB_INIT timed out\n");
528 nvc0_graph_ctxctl_debug(dev);
529 return -EBUSY;
530 }
531
532 priv->grctx_size = nv_rd32(dev, 0x409804);
533 return 0;
534 }
Ben Skeggs966a5b72010-11-24 10:49:02 +1000535
536 /* load fuc microcode */
537 r000260 = nv_mask(dev, 0x000260, 0x00000001, 0x00000000);
Ben Skeggsfe799112011-04-12 18:50:36 +1000538 nvc0_graph_init_fuc(dev, 0x409000, &priv->fuc409c, &priv->fuc409d);
539 nvc0_graph_init_fuc(dev, 0x41a000, &priv->fuc41ac, &priv->fuc41ad);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000540 nv_wr32(dev, 0x000260, r000260);
541
Ben Skeggs966a5b72010-11-24 10:49:02 +1000542 /* start both of them running */
543 nv_wr32(dev, 0x409840, 0xffffffff);
544 nv_wr32(dev, 0x41a10c, 0x00000000);
545 nv_wr32(dev, 0x40910c, 0x00000000);
546 nv_wr32(dev, 0x41a100, 0x00000002);
547 nv_wr32(dev, 0x409100, 0x00000002);
548 if (!nv_wait(dev, 0x409800, 0x00000001, 0x00000001))
549 NV_INFO(dev, "0x409800 wait failed\n");
550
551 nv_wr32(dev, 0x409840, 0xffffffff);
552 nv_wr32(dev, 0x409500, 0x7fffffff);
553 nv_wr32(dev, 0x409504, 0x00000021);
554
555 nv_wr32(dev, 0x409840, 0xffffffff);
556 nv_wr32(dev, 0x409500, 0x00000000);
557 nv_wr32(dev, 0x409504, 0x00000010);
558 if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
559 NV_ERROR(dev, "fuc09 req 0x10 timeout\n");
560 return -EBUSY;
561 }
562 priv->grctx_size = nv_rd32(dev, 0x409800);
563
564 nv_wr32(dev, 0x409840, 0xffffffff);
565 nv_wr32(dev, 0x409500, 0x00000000);
566 nv_wr32(dev, 0x409504, 0x00000016);
567 if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
568 NV_ERROR(dev, "fuc09 req 0x16 timeout\n");
569 return -EBUSY;
570 }
571
572 nv_wr32(dev, 0x409840, 0xffffffff);
573 nv_wr32(dev, 0x409500, 0x00000000);
574 nv_wr32(dev, 0x409504, 0x00000025);
575 if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
576 NV_ERROR(dev, "fuc09 req 0x25 timeout\n");
577 return -EBUSY;
578 }
579
580 return 0;
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000581}
582
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000583static int
584nvc0_graph_init(struct drm_device *dev, int engine)
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000585{
Ben Skeggs966a5b72010-11-24 10:49:02 +1000586 int ret;
587
Ben Skeggs966a5b72010-11-24 10:49:02 +1000588 nv_mask(dev, 0x000200, 0x18001000, 0x00000000);
589 nv_mask(dev, 0x000200, 0x18001000, 0x18001000);
590
Ben Skeggs966a5b72010-11-24 10:49:02 +1000591 nvc0_graph_init_obj418880(dev);
592 nvc0_graph_init_regs(dev);
Emil Velikovf2129492011-03-19 23:31:52 +0000593 /*nvc0_graph_init_unitplemented_magics(dev);*/
Ben Skeggs966a5b72010-11-24 10:49:02 +1000594 nvc0_graph_init_gpc_0(dev);
Emil Velikovf2129492011-03-19 23:31:52 +0000595 /*nvc0_graph_init_unitplemented_c242(dev);*/
Ben Skeggs966a5b72010-11-24 10:49:02 +1000596
597 nv_wr32(dev, 0x400500, 0x00010001);
598 nv_wr32(dev, 0x400100, 0xffffffff);
599 nv_wr32(dev, 0x40013c, 0xffffffff);
600
601 nvc0_graph_init_units(dev);
602 nvc0_graph_init_gpc_1(dev);
603 nvc0_graph_init_rop(dev);
604
605 nv_wr32(dev, 0x400108, 0xffffffff);
606 nv_wr32(dev, 0x400138, 0xffffffff);
607 nv_wr32(dev, 0x400118, 0xffffffff);
608 nv_wr32(dev, 0x400130, 0xffffffff);
609 nv_wr32(dev, 0x40011c, 0xffffffff);
610 nv_wr32(dev, 0x400134, 0xffffffff);
611 nv_wr32(dev, 0x400054, 0x34ce3464);
612
613 ret = nvc0_graph_init_ctxctl(dev);
Ben Skeggsa82dd492011-04-01 13:56:05 +1000614 if (ret)
615 return ret;
616
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000617 return 0;
618}
619
Ben Skeggsd5a27372011-04-01 16:10:08 +1000620int
Ben Skeggs966a5b72010-11-24 10:49:02 +1000621nvc0_graph_isr_chid(struct drm_device *dev, u64 inst)
622{
623 struct drm_nouveau_private *dev_priv = dev->dev_private;
624 struct nouveau_channel *chan;
625 unsigned long flags;
626 int i;
627
628 spin_lock_irqsave(&dev_priv->channels.lock, flags);
629 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
630 chan = dev_priv->channels.ptr[i];
631 if (!chan || !chan->ramin)
632 continue;
633
634 if (inst == chan->ramin->vinst)
635 break;
636 }
637 spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
638 return i;
639}
640
641static void
Ben Skeggs0411de82011-05-25 18:32:44 +1000642nvc0_graph_ctxctl_isr(struct drm_device *dev)
643{
644 u32 ustat = nv_rd32(dev, 0x409c18);
645
646 if (ustat & 0x00000001)
647 NV_INFO(dev, "PGRAPH: CTXCTRL ucode error\n");
648 if (ustat & 0x00080000)
649 NV_INFO(dev, "PGRAPH: CTXCTRL watchdog timeout\n");
650 if (ustat & ~0x00080001)
651 NV_INFO(dev, "PGRAPH: CTXCTRL 0x%08x\n", ustat);
652
653 nvc0_graph_ctxctl_debug(dev);
654 nv_wr32(dev, 0x409c20, ustat);
655}
656
657static void
Ben Skeggs966a5b72010-11-24 10:49:02 +1000658nvc0_graph_isr(struct drm_device *dev)
659{
660 u64 inst = (u64)(nv_rd32(dev, 0x409b00) & 0x0fffffff) << 12;
661 u32 chid = nvc0_graph_isr_chid(dev, inst);
662 u32 stat = nv_rd32(dev, 0x400100);
663 u32 addr = nv_rd32(dev, 0x400704);
664 u32 mthd = (addr & 0x00003ffc);
665 u32 subc = (addr & 0x00070000) >> 16;
666 u32 data = nv_rd32(dev, 0x400708);
667 u32 code = nv_rd32(dev, 0x400110);
668 u32 class = nv_rd32(dev, 0x404200 + (subc * 4));
669
670 if (stat & 0x00000010) {
Ben Skeggsbd2f2032011-02-08 15:16:23 +1000671 if (nouveau_gpuobj_mthd_call2(dev, chid, class, mthd, data)) {
672 NV_INFO(dev, "PGRAPH: ILLEGAL_MTHD ch %d [0x%010llx] "
673 "subc %d class 0x%04x mthd 0x%04x "
674 "data 0x%08x\n",
675 chid, inst, subc, class, mthd, data);
676 }
Ben Skeggs966a5b72010-11-24 10:49:02 +1000677 nv_wr32(dev, 0x400100, 0x00000010);
678 stat &= ~0x00000010;
679 }
680
Ben Skeggseae5e7f2010-12-30 11:40:07 +1000681 if (stat & 0x00000020) {
682 NV_INFO(dev, "PGRAPH: ILLEGAL_CLASS ch %d [0x%010llx] subc %d "
683 "class 0x%04x mthd 0x%04x data 0x%08x\n",
684 chid, inst, subc, class, mthd, data);
685 nv_wr32(dev, 0x400100, 0x00000020);
686 stat &= ~0x00000020;
687 }
688
Ben Skeggs966a5b72010-11-24 10:49:02 +1000689 if (stat & 0x00100000) {
690 NV_INFO(dev, "PGRAPH: DATA_ERROR [");
Ben Skeggs6effe392010-12-30 11:48:03 +1000691 nouveau_enum_print(nv50_data_error_names, code);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000692 printk("] ch %d [0x%010llx] subc %d class 0x%04x "
693 "mthd 0x%04x data 0x%08x\n",
694 chid, inst, subc, class, mthd, data);
695 nv_wr32(dev, 0x400100, 0x00100000);
696 stat &= ~0x00100000;
697 }
698
Ben Skeggseae5e7f2010-12-30 11:40:07 +1000699 if (stat & 0x00200000) {
700 u32 trap = nv_rd32(dev, 0x400108);
701 NV_INFO(dev, "PGRAPH: TRAP ch %d status 0x%08x\n", chid, trap);
702 nv_wr32(dev, 0x400108, trap);
703 nv_wr32(dev, 0x400100, 0x00200000);
704 stat &= ~0x00200000;
705 }
706
Ben Skeggs966a5b72010-11-24 10:49:02 +1000707 if (stat & 0x00080000) {
Ben Skeggs0411de82011-05-25 18:32:44 +1000708 nvc0_graph_ctxctl_isr(dev);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000709 nv_wr32(dev, 0x400100, 0x00080000);
710 stat &= ~0x00080000;
711 }
712
713 if (stat) {
714 NV_INFO(dev, "PGRAPH: unknown stat 0x%08x\n", stat);
715 nv_wr32(dev, 0x400100, stat);
716 }
717
718 nv_wr32(dev, 0x400500, 0x00010001);
719}
Ben Skeggs51f73d62011-01-21 13:53:21 +1000720
Ben Skeggsfe799112011-04-12 18:50:36 +1000721static int
722nvc0_graph_create_fw(struct drm_device *dev, const char *fwname,
723 struct nvc0_graph_fuc *fuc)
724{
725 struct drm_nouveau_private *dev_priv = dev->dev_private;
726 const struct firmware *fw;
727 char f[32];
728 int ret;
729
730 snprintf(f, sizeof(f), "nouveau/nv%02x_%s", dev_priv->chipset, fwname);
731 ret = request_firmware(&fw, f, &dev->pdev->dev);
732 if (ret) {
733 snprintf(f, sizeof(f), "nouveau/%s", fwname);
734 ret = request_firmware(&fw, f, &dev->pdev->dev);
735 if (ret) {
736 NV_ERROR(dev, "failed to load %s\n", fwname);
737 return ret;
738 }
739 }
740
741 fuc->size = fw->size;
742 fuc->data = kmemdup(fw->data, fuc->size, GFP_KERNEL);
743 release_firmware(fw);
744 return (fuc->data != NULL) ? 0 : -ENOMEM;
745}
746
747static void
748nvc0_graph_destroy_fw(struct nvc0_graph_fuc *fuc)
749{
750 if (fuc->data) {
751 kfree(fuc->data);
752 fuc->data = NULL;
753 }
754}
755
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000756static void
757nvc0_graph_destroy(struct drm_device *dev, int engine)
758{
759 struct nvc0_graph_priv *priv = nv_engine(dev, engine);
760
Ben Skeggs0411de82011-05-25 18:32:44 +1000761 if (nouveau_ctxfw) {
762 nvc0_graph_destroy_fw(&priv->fuc409c);
763 nvc0_graph_destroy_fw(&priv->fuc409d);
764 nvc0_graph_destroy_fw(&priv->fuc41ac);
765 nvc0_graph_destroy_fw(&priv->fuc41ad);
766 }
Ben Skeggsfe799112011-04-12 18:50:36 +1000767
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000768 nouveau_irq_unregister(dev, 12);
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000769
770 nouveau_gpuobj_ref(NULL, &priv->unk4188b8);
771 nouveau_gpuobj_ref(NULL, &priv->unk4188b4);
772
773 if (priv->grctx_vals)
774 kfree(priv->grctx_vals);
775
776 NVOBJ_ENGINE_DEL(dev, GR);
777 kfree(priv);
778}
779
780int
781nvc0_graph_create(struct drm_device *dev)
782{
783 struct drm_nouveau_private *dev_priv = dev->dev_private;
784 struct nvc0_graph_priv *priv;
785 int ret, gpc, i;
Ben Skeggs847adea2011-05-24 14:37:41 +1000786 u32 fermi;
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000787
Ben Skeggs847adea2011-05-24 14:37:41 +1000788 fermi = nvc0_graph_class(dev);
789 if (!fermi) {
Ben Skeggsa82dd492011-04-01 13:56:05 +1000790 NV_ERROR(dev, "PGRAPH: unsupported chipset, please report!\n");
791 return 0;
792 }
793
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000794 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
795 if (!priv)
796 return -ENOMEM;
797
798 priv->base.destroy = nvc0_graph_destroy;
799 priv->base.init = nvc0_graph_init;
800 priv->base.fini = nvc0_graph_fini;
801 priv->base.context_new = nvc0_graph_context_new;
802 priv->base.context_del = nvc0_graph_context_del;
803 priv->base.object_new = nvc0_graph_object_new;
804
805 NVOBJ_ENGINE_ADD(dev, GR, &priv->base);
806 nouveau_irq_register(dev, 12, nvc0_graph_isr);
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000807
Ben Skeggs0411de82011-05-25 18:32:44 +1000808 if (nouveau_ctxfw) {
809 NV_INFO(dev, "PGRAPH: using external firmware\n");
810 if (nvc0_graph_create_fw(dev, "fuc409c", &priv->fuc409c) ||
811 nvc0_graph_create_fw(dev, "fuc409d", &priv->fuc409d) ||
812 nvc0_graph_create_fw(dev, "fuc41ac", &priv->fuc41ac) ||
813 nvc0_graph_create_fw(dev, "fuc41ad", &priv->fuc41ad)) {
814 ret = 0;
815 goto error;
816 }
Ben Skeggsfe799112011-04-12 18:50:36 +1000817 }
818
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000819 ret = nouveau_gpuobj_new(dev, NULL, 0x1000, 256, 0, &priv->unk4188b4);
820 if (ret)
821 goto error;
822
823 ret = nouveau_gpuobj_new(dev, NULL, 0x1000, 256, 0, &priv->unk4188b8);
824 if (ret)
825 goto error;
826
827 for (i = 0; i < 0x1000; i += 4) {
828 nv_wo32(priv->unk4188b4, i, 0x00000010);
829 nv_wo32(priv->unk4188b8, i, 0x00000010);
830 }
831
832 priv->gpc_nr = nv_rd32(dev, 0x409604) & 0x0000001f;
833 priv->rop_nr = (nv_rd32(dev, 0x409604) & 0x001f0000) >> 16;
834 for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
835 priv->tp_nr[gpc] = nv_rd32(dev, GPC_UNIT(gpc, 0x2608));
836 priv->tp_total += priv->tp_nr[gpc];
837 }
838
839 /*XXX: these need figuring out... */
840 switch (dev_priv->chipset) {
841 case 0xc0:
842 if (priv->tp_total == 11) { /* 465, 3/4/4/0, 4 */
843 priv->magic_not_rop_nr = 0x07;
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000844 } else
845 if (priv->tp_total == 14) { /* 470, 3/3/4/4, 5 */
846 priv->magic_not_rop_nr = 0x05;
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000847 } else
848 if (priv->tp_total == 15) { /* 480, 3/4/4/4, 6 */
849 priv->magic_not_rop_nr = 0x06;
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000850 }
851 break;
852 case 0xc3: /* 450, 4/0/0/0, 2 */
853 priv->magic_not_rop_nr = 0x03;
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000854 break;
855 case 0xc4: /* 460, 3/4/0/0, 4 */
856 priv->magic_not_rop_nr = 0x01;
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000857 break;
Ben Skeggsa2199972011-05-26 10:54:05 +1000858 case 0xc1: /* 2/0/0/0, 1 */
859 priv->magic_not_rop_nr = 0x01;
Ben Skeggsa2199972011-05-26 10:54:05 +1000860 break;
861 case 0xc8: /* 4/4/3/4, 5 */
862 priv->magic_not_rop_nr = 0x06;
Ben Skeggsa2199972011-05-26 10:54:05 +1000863 break;
864 case 0xce: /* 4/4/0/0, 4 */
865 priv->magic_not_rop_nr = 0x03;
Ben Skeggsa2199972011-05-26 10:54:05 +1000866 break;
Ben Skeggs3c23a7b2011-06-24 11:14:00 +1000867 case 0xcf: /* 4/0/0/0, 3 */
868 priv->magic_not_rop_nr = 0x03;
869 break;
Ben Skeggs06784092011-07-11 15:57:54 +1000870 case 0xd9: /* 1/0/0/0, 1 */
871 priv->magic_not_rop_nr = 0x01;
872 break;
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000873 }
874
875 if (!priv->magic_not_rop_nr) {
876 NV_ERROR(dev, "PGRAPH: unknown config: %d/%d/%d/%d, %d\n",
877 priv->tp_nr[0], priv->tp_nr[1], priv->tp_nr[2],
878 priv->tp_nr[3], priv->rop_nr);
Ben Skeggs06784092011-07-11 15:57:54 +1000879 priv->magic_not_rop_nr = 0x00;
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000880 }
881
882 NVOBJ_CLASS(dev, 0x902d, GR); /* 2D */
883 NVOBJ_CLASS(dev, 0x9039, GR); /* M2MF */
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000884 NVOBJ_CLASS(dev, 0x9097, GR); /* 3D */
Ben Skeggs847adea2011-05-24 14:37:41 +1000885 if (fermi >= 0x9197)
886 NVOBJ_CLASS(dev, 0x9197, GR); /* 3D (NVC1-) */
887 if (fermi >= 0x9297)
888 NVOBJ_CLASS(dev, 0x9297, GR); /* 3D (NVC8-) */
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000889 NVOBJ_CLASS(dev, 0x90c0, GR); /* COMPUTE */
890 return 0;
891
892error:
893 nvc0_graph_destroy(dev, NVOBJ_ENGINE_GR);
894 return ret;
895}