blob: c4b65fa7aaf1e4dc6bb8e59bdeac1951811cbdeb [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>
26
Ben Skeggs4b223ee2010-08-03 10:00:56 +100027#include "drmP.h"
28
29#include "nouveau_drv.h"
Ben Skeggs966a5b72010-11-24 10:49:02 +100030#include "nouveau_mm.h"
31#include "nvc0_graph.h"
32
Ben Skeggs966a5b72010-11-24 10:49:02 +100033static int
Ben Skeggs7a45cd12011-04-01 10:59:53 +100034nvc0_graph_load_context(struct nouveau_channel *chan)
35{
36 struct drm_device *dev = chan->dev;
37
38 nv_wr32(dev, 0x409840, 0x00000030);
39 nv_wr32(dev, 0x409500, 0x80000000 | chan->ramin->vinst >> 12);
40 nv_wr32(dev, 0x409504, 0x00000003);
41 if (!nv_wait(dev, 0x409800, 0x00000010, 0x00000010))
42 NV_ERROR(dev, "PGRAPH: load_ctx timeout\n");
43
44 return 0;
45}
46
47static int
48nvc0_graph_unload_context_to(struct drm_device *dev, u64 chan)
49{
50 nv_wr32(dev, 0x409840, 0x00000003);
51 nv_wr32(dev, 0x409500, 0x80000000 | chan >> 12);
52 nv_wr32(dev, 0x409504, 0x00000009);
53 if (!nv_wait(dev, 0x409800, 0x00000001, 0x00000000)) {
54 NV_ERROR(dev, "PGRAPH: unload_ctx timeout\n");
55 return -EBUSY;
56 }
57
58 return 0;
59}
60
61static int
Ben Skeggs966a5b72010-11-24 10:49:02 +100062nvc0_graph_construct_context(struct nouveau_channel *chan)
63{
64 struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
Ben Skeggs7a45cd12011-04-01 10:59:53 +100065 struct nvc0_graph_priv *priv = nv_engine(chan->dev, NVOBJ_ENGINE_GR);
66 struct nvc0_graph_chan *grch = chan->engctx[NVOBJ_ENGINE_GR];
Ben Skeggs966a5b72010-11-24 10:49:02 +100067 struct drm_device *dev = chan->dev;
68 int ret, i;
69 u32 *ctx;
70
71 ctx = kmalloc(priv->grctx_size, GFP_KERNEL);
72 if (!ctx)
73 return -ENOMEM;
74
75 nvc0_graph_load_context(chan);
76
77 nv_wo32(grch->grctx, 0x1c, 1);
78 nv_wo32(grch->grctx, 0x20, 0);
79 nv_wo32(grch->grctx, 0x28, 0);
80 nv_wo32(grch->grctx, 0x2c, 0);
81 dev_priv->engine.instmem.flush(dev);
82
83 ret = nvc0_grctx_generate(chan);
84 if (ret) {
85 kfree(ctx);
86 return ret;
87 }
88
89 ret = nvc0_graph_unload_context_to(dev, chan->ramin->vinst);
90 if (ret) {
91 kfree(ctx);
92 return ret;
93 }
94
95 for (i = 0; i < priv->grctx_size; i += 4)
96 ctx[i / 4] = nv_ro32(grch->grctx, i);
97
98 priv->grctx_vals = ctx;
99 return 0;
100}
101
102static int
103nvc0_graph_create_context_mmio_list(struct nouveau_channel *chan)
104{
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000105 struct nvc0_graph_priv *priv = nv_engine(chan->dev, NVOBJ_ENGINE_GR);
106 struct nvc0_graph_chan *grch = chan->engctx[NVOBJ_ENGINE_GR];
Ben Skeggs966a5b72010-11-24 10:49:02 +1000107 struct drm_device *dev = chan->dev;
108 int i = 0, gpc, tp, ret;
109 u32 magic;
110
111 ret = nouveau_gpuobj_new(dev, NULL, 0x2000, 256, NVOBJ_FLAG_VM,
112 &grch->unk408004);
113 if (ret)
114 return ret;
115
116 ret = nouveau_gpuobj_new(dev, NULL, 0x8000, 256, NVOBJ_FLAG_VM,
117 &grch->unk40800c);
118 if (ret)
119 return ret;
120
Ben Skeggsc906ca02011-01-14 10:27:02 +1000121 ret = nouveau_gpuobj_new(dev, NULL, 384 * 1024, 4096,
122 NVOBJ_FLAG_VM | NVOBJ_FLAG_VM_USER,
Ben Skeggs966a5b72010-11-24 10:49:02 +1000123 &grch->unk418810);
124 if (ret)
125 return ret;
126
127 ret = nouveau_gpuobj_new(dev, NULL, 0x1000, 0, NVOBJ_FLAG_VM,
128 &grch->mmio);
129 if (ret)
130 return ret;
131
132
133 nv_wo32(grch->mmio, i++ * 4, 0x00408004);
134 nv_wo32(grch->mmio, i++ * 4, grch->unk408004->vinst >> 8);
135 nv_wo32(grch->mmio, i++ * 4, 0x00408008);
136 nv_wo32(grch->mmio, i++ * 4, 0x80000018);
137
138 nv_wo32(grch->mmio, i++ * 4, 0x0040800c);
139 nv_wo32(grch->mmio, i++ * 4, grch->unk40800c->vinst >> 8);
140 nv_wo32(grch->mmio, i++ * 4, 0x00408010);
141 nv_wo32(grch->mmio, i++ * 4, 0x80000000);
142
143 nv_wo32(grch->mmio, i++ * 4, 0x00418810);
144 nv_wo32(grch->mmio, i++ * 4, 0x80000000 | grch->unk418810->vinst >> 12);
145 nv_wo32(grch->mmio, i++ * 4, 0x00419848);
146 nv_wo32(grch->mmio, i++ * 4, 0x10000000 | grch->unk418810->vinst >> 12);
147
148 nv_wo32(grch->mmio, i++ * 4, 0x00419004);
149 nv_wo32(grch->mmio, i++ * 4, grch->unk40800c->vinst >> 8);
150 nv_wo32(grch->mmio, i++ * 4, 0x00419008);
151 nv_wo32(grch->mmio, i++ * 4, 0x00000000);
152
153 nv_wo32(grch->mmio, i++ * 4, 0x00418808);
154 nv_wo32(grch->mmio, i++ * 4, grch->unk408004->vinst >> 8);
155 nv_wo32(grch->mmio, i++ * 4, 0x0041880c);
156 nv_wo32(grch->mmio, i++ * 4, 0x80000018);
157
158 magic = 0x02180000;
159 nv_wo32(grch->mmio, i++ * 4, 0x00405830);
160 nv_wo32(grch->mmio, i++ * 4, magic);
161 for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
162 for (tp = 0; tp < priv->tp_nr[gpc]; tp++, magic += 0x02fc) {
163 u32 reg = 0x504520 + (gpc * 0x8000) + (tp * 0x0800);
164 nv_wo32(grch->mmio, i++ * 4, reg);
165 nv_wo32(grch->mmio, i++ * 4, magic);
166 }
167 }
168
169 grch->mmio_nr = i / 2;
170 return 0;
171}
172
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000173static int
174nvc0_graph_context_new(struct nouveau_channel *chan, int engine)
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000175{
Ben Skeggs966a5b72010-11-24 10:49:02 +1000176 struct drm_device *dev = chan->dev;
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000177 struct drm_nouveau_private *dev_priv = dev->dev_private;
178 struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem;
179 struct nvc0_graph_priv *priv = nv_engine(dev, engine);
180 struct nvc0_graph_chan *grch;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000181 struct nouveau_gpuobj *grctx;
182 int ret, i;
183
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000184 grch = kzalloc(sizeof(*grch), GFP_KERNEL);
185 if (!grch)
Ben Skeggs966a5b72010-11-24 10:49:02 +1000186 return -ENOMEM;
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000187 chan->engctx[NVOBJ_ENGINE_GR] = grch;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000188
189 ret = nouveau_gpuobj_new(dev, NULL, priv->grctx_size, 256,
190 NVOBJ_FLAG_VM | NVOBJ_FLAG_ZERO_ALLOC,
191 &grch->grctx);
192 if (ret)
193 goto error;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000194 grctx = grch->grctx;
195
196 ret = nvc0_graph_create_context_mmio_list(chan);
197 if (ret)
198 goto error;
199
200 nv_wo32(chan->ramin, 0x0210, lower_32_bits(grctx->vinst) | 4);
201 nv_wo32(chan->ramin, 0x0214, upper_32_bits(grctx->vinst));
202 pinstmem->flush(dev);
203
204 if (!priv->grctx_vals) {
205 ret = nvc0_graph_construct_context(chan);
206 if (ret)
207 goto error;
208 }
209
210 for (i = 0; i < priv->grctx_size; i += 4)
211 nv_wo32(grctx, i, priv->grctx_vals[i / 4]);
212
Emil Velikov71298e22011-03-19 23:31:51 +0000213 nv_wo32(grctx, 0xf4, 0);
214 nv_wo32(grctx, 0xf8, 0);
215 nv_wo32(grctx, 0x10, grch->mmio_nr);
216 nv_wo32(grctx, 0x14, lower_32_bits(grch->mmio->vinst));
217 nv_wo32(grctx, 0x18, upper_32_bits(grch->mmio->vinst));
218 nv_wo32(grctx, 0x1c, 1);
219 nv_wo32(grctx, 0x20, 0);
220 nv_wo32(grctx, 0x28, 0);
221 nv_wo32(grctx, 0x2c, 0);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000222 pinstmem->flush(dev);
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000223 return 0;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000224
225error:
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000226 priv->base.context_del(chan, engine);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000227 return ret;
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000228}
229
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000230static void
231nvc0_graph_context_del(struct nouveau_channel *chan, int engine)
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000232{
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000233 struct nvc0_graph_chan *grch = chan->engctx[engine];
Ben Skeggs966a5b72010-11-24 10:49:02 +1000234
235 nouveau_gpuobj_ref(NULL, &grch->mmio);
236 nouveau_gpuobj_ref(NULL, &grch->unk418810);
237 nouveau_gpuobj_ref(NULL, &grch->unk40800c);
238 nouveau_gpuobj_ref(NULL, &grch->unk408004);
239 nouveau_gpuobj_ref(NULL, &grch->grctx);
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000240 chan->engctx[engine] = NULL;
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000241}
242
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000243static int
244nvc0_graph_object_new(struct nouveau_channel *chan, int engine,
245 u32 handle, u16 class)
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000246{
Ben Skeggs966a5b72010-11-24 10:49:02 +1000247 return 0;
248}
249
250static int
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000251nvc0_graph_fini(struct drm_device *dev, int engine)
Ben Skeggs966a5b72010-11-24 10:49:02 +1000252{
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000253 return 0;
254}
255
Ben Skeggs966a5b72010-11-24 10:49:02 +1000256static int
Ben Skeggsbd2f2032011-02-08 15:16:23 +1000257nvc0_graph_mthd_page_flip(struct nouveau_channel *chan,
258 u32 class, u32 mthd, u32 data)
259{
260 nouveau_finish_page_flip(chan, NULL);
261 return 0;
262}
263
Ben Skeggs966a5b72010-11-24 10:49:02 +1000264static void
265nvc0_graph_init_obj418880(struct drm_device *dev)
266{
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000267 struct nvc0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000268 int i;
269
270 nv_wr32(dev, GPC_BCAST(0x0880), 0x00000000);
271 nv_wr32(dev, GPC_BCAST(0x08a4), 0x00000000);
272 for (i = 0; i < 4; i++)
273 nv_wr32(dev, GPC_BCAST(0x0888) + (i * 4), 0x00000000);
274 nv_wr32(dev, GPC_BCAST(0x08b4), priv->unk4188b4->vinst >> 8);
275 nv_wr32(dev, GPC_BCAST(0x08b8), priv->unk4188b8->vinst >> 8);
276}
277
278static void
279nvc0_graph_init_regs(struct drm_device *dev)
280{
281 nv_wr32(dev, 0x400080, 0x003083c2);
282 nv_wr32(dev, 0x400088, 0x00006fe7);
283 nv_wr32(dev, 0x40008c, 0x00000000);
284 nv_wr32(dev, 0x400090, 0x00000030);
285 nv_wr32(dev, 0x40013c, 0x013901f7);
286 nv_wr32(dev, 0x400140, 0x00000100);
287 nv_wr32(dev, 0x400144, 0x00000000);
288 nv_wr32(dev, 0x400148, 0x00000110);
289 nv_wr32(dev, 0x400138, 0x00000000);
290 nv_wr32(dev, 0x400130, 0x00000000);
291 nv_wr32(dev, 0x400134, 0x00000000);
292 nv_wr32(dev, 0x400124, 0x00000002);
293}
294
295static void
296nvc0_graph_init_gpc_0(struct drm_device *dev)
297{
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000298 struct nvc0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000299 int gpc;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000300
Emil Velikovf2129492011-03-19 23:31:52 +0000301 /*
302 * TP ROP UNKVAL(magic_not_rop_nr)
303 * 450: 4/0/0/0 2 3
304 * 460: 3/4/0/0 4 1
305 * 465: 3/4/4/0 4 7
306 * 470: 3/3/4/4 5 5
307 * 480: 3/4/4/4 6 6
Ben Skeggs966a5b72010-11-24 10:49:02 +1000308
Emil Velikovf2129492011-03-19 23:31:52 +0000309 * magicgpc918
310 * 450: 00200000 00000000001000000000000000000000
311 * 460: 00124925 00000000000100100100100100100101
312 * 465: 000ba2e9 00000000000010111010001011101001
313 * 470: 00092493 00000000000010010010010010010011
314 * 480: 00088889 00000000000010001000100010001001
315
316 * filled values up to tp_total, remainder 0
317 * 450: 00003210 00000000 00000000 00000000
318 * 460: 02321100 00000000 00000000 00000000
319 * 465: 22111000 00000233 00000000 00000000
320 * 470: 11110000 00233222 00000000 00000000
321 * 480: 11110000 03332222 00000000 00000000
322 */
323
Ben Skeggs966a5b72010-11-24 10:49:02 +1000324 nv_wr32(dev, GPC_BCAST(0x0980), priv->magicgpc980[0]);
325 nv_wr32(dev, GPC_BCAST(0x0984), priv->magicgpc980[1]);
326 nv_wr32(dev, GPC_BCAST(0x0988), priv->magicgpc980[2]);
327 nv_wr32(dev, GPC_BCAST(0x098c), priv->magicgpc980[3]);
328
329 for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
330 nv_wr32(dev, GPC_UNIT(gpc, 0x0914), priv->magic_not_rop_nr << 8 |
331 priv->tp_nr[gpc]);
332 nv_wr32(dev, GPC_UNIT(gpc, 0x0910), 0x00040000 | priv->tp_total);
333 nv_wr32(dev, GPC_UNIT(gpc, 0x0918), priv->magicgpc918);
334 }
335
336 nv_wr32(dev, GPC_BCAST(0x1bd4), priv->magicgpc918);
337 nv_wr32(dev, GPC_BCAST(0x08ac), priv->rop_nr);
338}
339
340static void
341nvc0_graph_init_units(struct drm_device *dev)
342{
343 nv_wr32(dev, 0x409c24, 0x000f0000);
344 nv_wr32(dev, 0x404000, 0xc0000000); /* DISPATCH */
345 nv_wr32(dev, 0x404600, 0xc0000000); /* M2MF */
346 nv_wr32(dev, 0x408030, 0xc0000000);
347 nv_wr32(dev, 0x40601c, 0xc0000000);
348 nv_wr32(dev, 0x404490, 0xc0000000); /* MACRO */
349 nv_wr32(dev, 0x406018, 0xc0000000);
350 nv_wr32(dev, 0x405840, 0xc0000000);
351 nv_wr32(dev, 0x405844, 0x00ffffff);
352 nv_mask(dev, 0x419cc0, 0x00000008, 0x00000008);
353 nv_mask(dev, 0x419eb4, 0x00001000, 0x00001000);
354}
355
356static void
357nvc0_graph_init_gpc_1(struct drm_device *dev)
358{
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000359 struct nvc0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000360 int gpc, tp;
361
362 for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
363 nv_wr32(dev, GPC_UNIT(gpc, 0x0420), 0xc0000000);
364 nv_wr32(dev, GPC_UNIT(gpc, 0x0900), 0xc0000000);
365 nv_wr32(dev, GPC_UNIT(gpc, 0x1028), 0xc0000000);
366 nv_wr32(dev, GPC_UNIT(gpc, 0x0824), 0xc0000000);
367 for (tp = 0; tp < priv->tp_nr[gpc]; tp++) {
368 nv_wr32(dev, TP_UNIT(gpc, tp, 0x508), 0xffffffff);
369 nv_wr32(dev, TP_UNIT(gpc, tp, 0x50c), 0xffffffff);
370 nv_wr32(dev, TP_UNIT(gpc, tp, 0x224), 0xc0000000);
371 nv_wr32(dev, TP_UNIT(gpc, tp, 0x48c), 0xc0000000);
372 nv_wr32(dev, TP_UNIT(gpc, tp, 0x084), 0xc0000000);
Ben Skeggs0f1cb202011-01-21 11:15:16 +1000373 nv_wr32(dev, TP_UNIT(gpc, tp, 0x644), 0x001ffffe);
374 nv_wr32(dev, TP_UNIT(gpc, tp, 0x64c), 0x0000000f);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000375 }
376 nv_wr32(dev, GPC_UNIT(gpc, 0x2c90), 0xffffffff);
377 nv_wr32(dev, GPC_UNIT(gpc, 0x2c94), 0xffffffff);
378 }
379}
380
381static void
382nvc0_graph_init_rop(struct drm_device *dev)
383{
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000384 struct nvc0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000385 int rop;
386
387 for (rop = 0; rop < priv->rop_nr; rop++) {
388 nv_wr32(dev, ROP_UNIT(rop, 0x144), 0xc0000000);
389 nv_wr32(dev, ROP_UNIT(rop, 0x070), 0xc0000000);
390 nv_wr32(dev, ROP_UNIT(rop, 0x204), 0xffffffff);
391 nv_wr32(dev, ROP_UNIT(rop, 0x208), 0xffffffff);
392 }
393}
394
Ben Skeggsfe799112011-04-12 18:50:36 +1000395static void
396nvc0_graph_init_fuc(struct drm_device *dev, u32 fuc_base,
397 struct nvc0_graph_fuc *code, struct nvc0_graph_fuc *data)
Ben Skeggs966a5b72010-11-24 10:49:02 +1000398{
Ben Skeggsfe799112011-04-12 18:50:36 +1000399 int i;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000400
401 nv_wr32(dev, fuc_base + 0x01c0, 0x01000000);
Ben Skeggsfe799112011-04-12 18:50:36 +1000402 for (i = 0; i < data->size / 4; i++)
403 nv_wr32(dev, fuc_base + 0x01c4, data->data[i]);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000404
405 nv_wr32(dev, fuc_base + 0x0180, 0x01000000);
Ben Skeggsfe799112011-04-12 18:50:36 +1000406 for (i = 0; i < code->size / 4; i++) {
Ben Skeggs966a5b72010-11-24 10:49:02 +1000407 if ((i & 0x3f) == 0)
408 nv_wr32(dev, fuc_base + 0x0188, i >> 6);
Ben Skeggsfe799112011-04-12 18:50:36 +1000409 nv_wr32(dev, fuc_base + 0x0184, code->data[i]);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000410 }
Ben Skeggs966a5b72010-11-24 10:49:02 +1000411}
412
413static int
414nvc0_graph_init_ctxctl(struct drm_device *dev)
415{
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000416 struct nvc0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000417 u32 r000260;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000418
419 /* load fuc microcode */
420 r000260 = nv_mask(dev, 0x000260, 0x00000001, 0x00000000);
Ben Skeggsfe799112011-04-12 18:50:36 +1000421 nvc0_graph_init_fuc(dev, 0x409000, &priv->fuc409c, &priv->fuc409d);
422 nvc0_graph_init_fuc(dev, 0x41a000, &priv->fuc41ac, &priv->fuc41ad);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000423 nv_wr32(dev, 0x000260, r000260);
424
Ben Skeggs966a5b72010-11-24 10:49:02 +1000425 /* start both of them running */
426 nv_wr32(dev, 0x409840, 0xffffffff);
427 nv_wr32(dev, 0x41a10c, 0x00000000);
428 nv_wr32(dev, 0x40910c, 0x00000000);
429 nv_wr32(dev, 0x41a100, 0x00000002);
430 nv_wr32(dev, 0x409100, 0x00000002);
431 if (!nv_wait(dev, 0x409800, 0x00000001, 0x00000001))
432 NV_INFO(dev, "0x409800 wait failed\n");
433
434 nv_wr32(dev, 0x409840, 0xffffffff);
435 nv_wr32(dev, 0x409500, 0x7fffffff);
436 nv_wr32(dev, 0x409504, 0x00000021);
437
438 nv_wr32(dev, 0x409840, 0xffffffff);
439 nv_wr32(dev, 0x409500, 0x00000000);
440 nv_wr32(dev, 0x409504, 0x00000010);
441 if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
442 NV_ERROR(dev, "fuc09 req 0x10 timeout\n");
443 return -EBUSY;
444 }
445 priv->grctx_size = nv_rd32(dev, 0x409800);
446
447 nv_wr32(dev, 0x409840, 0xffffffff);
448 nv_wr32(dev, 0x409500, 0x00000000);
449 nv_wr32(dev, 0x409504, 0x00000016);
450 if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
451 NV_ERROR(dev, "fuc09 req 0x16 timeout\n");
452 return -EBUSY;
453 }
454
455 nv_wr32(dev, 0x409840, 0xffffffff);
456 nv_wr32(dev, 0x409500, 0x00000000);
457 nv_wr32(dev, 0x409504, 0x00000025);
458 if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
459 NV_ERROR(dev, "fuc09 req 0x25 timeout\n");
460 return -EBUSY;
461 }
462
463 return 0;
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000464}
465
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000466static int
467nvc0_graph_init(struct drm_device *dev, int engine)
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000468{
Ben Skeggs966a5b72010-11-24 10:49:02 +1000469 int ret;
470
Ben Skeggs966a5b72010-11-24 10:49:02 +1000471 nv_mask(dev, 0x000200, 0x18001000, 0x00000000);
472 nv_mask(dev, 0x000200, 0x18001000, 0x18001000);
473
Ben Skeggs966a5b72010-11-24 10:49:02 +1000474 nvc0_graph_init_obj418880(dev);
475 nvc0_graph_init_regs(dev);
Emil Velikovf2129492011-03-19 23:31:52 +0000476 /*nvc0_graph_init_unitplemented_magics(dev);*/
Ben Skeggs966a5b72010-11-24 10:49:02 +1000477 nvc0_graph_init_gpc_0(dev);
Emil Velikovf2129492011-03-19 23:31:52 +0000478 /*nvc0_graph_init_unitplemented_c242(dev);*/
Ben Skeggs966a5b72010-11-24 10:49:02 +1000479
480 nv_wr32(dev, 0x400500, 0x00010001);
481 nv_wr32(dev, 0x400100, 0xffffffff);
482 nv_wr32(dev, 0x40013c, 0xffffffff);
483
484 nvc0_graph_init_units(dev);
485 nvc0_graph_init_gpc_1(dev);
486 nvc0_graph_init_rop(dev);
487
488 nv_wr32(dev, 0x400108, 0xffffffff);
489 nv_wr32(dev, 0x400138, 0xffffffff);
490 nv_wr32(dev, 0x400118, 0xffffffff);
491 nv_wr32(dev, 0x400130, 0xffffffff);
492 nv_wr32(dev, 0x40011c, 0xffffffff);
493 nv_wr32(dev, 0x400134, 0xffffffff);
494 nv_wr32(dev, 0x400054, 0x34ce3464);
495
496 ret = nvc0_graph_init_ctxctl(dev);
Ben Skeggsa82dd492011-04-01 13:56:05 +1000497 if (ret)
498 return ret;
499
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000500 return 0;
501}
502
Ben Skeggsd5a27372011-04-01 16:10:08 +1000503int
Ben Skeggs966a5b72010-11-24 10:49:02 +1000504nvc0_graph_isr_chid(struct drm_device *dev, u64 inst)
505{
506 struct drm_nouveau_private *dev_priv = dev->dev_private;
507 struct nouveau_channel *chan;
508 unsigned long flags;
509 int i;
510
511 spin_lock_irqsave(&dev_priv->channels.lock, flags);
512 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
513 chan = dev_priv->channels.ptr[i];
514 if (!chan || !chan->ramin)
515 continue;
516
517 if (inst == chan->ramin->vinst)
518 break;
519 }
520 spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
521 return i;
522}
523
524static void
525nvc0_graph_isr(struct drm_device *dev)
526{
527 u64 inst = (u64)(nv_rd32(dev, 0x409b00) & 0x0fffffff) << 12;
528 u32 chid = nvc0_graph_isr_chid(dev, inst);
529 u32 stat = nv_rd32(dev, 0x400100);
530 u32 addr = nv_rd32(dev, 0x400704);
531 u32 mthd = (addr & 0x00003ffc);
532 u32 subc = (addr & 0x00070000) >> 16;
533 u32 data = nv_rd32(dev, 0x400708);
534 u32 code = nv_rd32(dev, 0x400110);
535 u32 class = nv_rd32(dev, 0x404200 + (subc * 4));
536
537 if (stat & 0x00000010) {
Ben Skeggsbd2f2032011-02-08 15:16:23 +1000538 if (nouveau_gpuobj_mthd_call2(dev, chid, class, mthd, data)) {
539 NV_INFO(dev, "PGRAPH: ILLEGAL_MTHD ch %d [0x%010llx] "
540 "subc %d class 0x%04x mthd 0x%04x "
541 "data 0x%08x\n",
542 chid, inst, subc, class, mthd, data);
543 }
Ben Skeggs966a5b72010-11-24 10:49:02 +1000544 nv_wr32(dev, 0x400100, 0x00000010);
545 stat &= ~0x00000010;
546 }
547
Ben Skeggseae5e7f2010-12-30 11:40:07 +1000548 if (stat & 0x00000020) {
549 NV_INFO(dev, "PGRAPH: ILLEGAL_CLASS ch %d [0x%010llx] subc %d "
550 "class 0x%04x mthd 0x%04x data 0x%08x\n",
551 chid, inst, subc, class, mthd, data);
552 nv_wr32(dev, 0x400100, 0x00000020);
553 stat &= ~0x00000020;
554 }
555
Ben Skeggs966a5b72010-11-24 10:49:02 +1000556 if (stat & 0x00100000) {
557 NV_INFO(dev, "PGRAPH: DATA_ERROR [");
Ben Skeggs6effe392010-12-30 11:48:03 +1000558 nouveau_enum_print(nv50_data_error_names, code);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000559 printk("] ch %d [0x%010llx] subc %d class 0x%04x "
560 "mthd 0x%04x data 0x%08x\n",
561 chid, inst, subc, class, mthd, data);
562 nv_wr32(dev, 0x400100, 0x00100000);
563 stat &= ~0x00100000;
564 }
565
Ben Skeggseae5e7f2010-12-30 11:40:07 +1000566 if (stat & 0x00200000) {
567 u32 trap = nv_rd32(dev, 0x400108);
568 NV_INFO(dev, "PGRAPH: TRAP ch %d status 0x%08x\n", chid, trap);
569 nv_wr32(dev, 0x400108, trap);
570 nv_wr32(dev, 0x400100, 0x00200000);
571 stat &= ~0x00200000;
572 }
573
Ben Skeggs966a5b72010-11-24 10:49:02 +1000574 if (stat & 0x00080000) {
575 u32 ustat = nv_rd32(dev, 0x409c18);
576
577 NV_INFO(dev, "PGRAPH: CTXCTRL ustat 0x%08x\n", ustat);
578
579 nv_wr32(dev, 0x409c20, ustat);
580 nv_wr32(dev, 0x400100, 0x00080000);
581 stat &= ~0x00080000;
582 }
583
584 if (stat) {
585 NV_INFO(dev, "PGRAPH: unknown stat 0x%08x\n", stat);
586 nv_wr32(dev, 0x400100, stat);
587 }
588
589 nv_wr32(dev, 0x400500, 0x00010001);
590}
Ben Skeggs51f73d62011-01-21 13:53:21 +1000591
592static void
593nvc0_runk140_isr(struct drm_device *dev)
594{
595 u32 units = nv_rd32(dev, 0x00017c) & 0x1f;
596
597 while (units) {
598 u32 unit = ffs(units) - 1;
599 u32 reg = 0x140000 + unit * 0x2000;
600 u32 st0 = nv_mask(dev, reg + 0x1020, 0, 0);
601 u32 st1 = nv_mask(dev, reg + 0x1420, 0, 0);
602
603 NV_INFO(dev, "PRUNK140: %d 0x%08x 0x%08x\n", unit, st0, st1);
604 units &= ~(1 << unit);
605 }
606}
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000607
Ben Skeggsfe799112011-04-12 18:50:36 +1000608static int
609nvc0_graph_create_fw(struct drm_device *dev, const char *fwname,
610 struct nvc0_graph_fuc *fuc)
611{
612 struct drm_nouveau_private *dev_priv = dev->dev_private;
613 const struct firmware *fw;
614 char f[32];
615 int ret;
616
617 snprintf(f, sizeof(f), "nouveau/nv%02x_%s", dev_priv->chipset, fwname);
618 ret = request_firmware(&fw, f, &dev->pdev->dev);
619 if (ret) {
620 snprintf(f, sizeof(f), "nouveau/%s", fwname);
621 ret = request_firmware(&fw, f, &dev->pdev->dev);
622 if (ret) {
623 NV_ERROR(dev, "failed to load %s\n", fwname);
624 return ret;
625 }
626 }
627
628 fuc->size = fw->size;
629 fuc->data = kmemdup(fw->data, fuc->size, GFP_KERNEL);
630 release_firmware(fw);
631 return (fuc->data != NULL) ? 0 : -ENOMEM;
632}
633
634static void
635nvc0_graph_destroy_fw(struct nvc0_graph_fuc *fuc)
636{
637 if (fuc->data) {
638 kfree(fuc->data);
639 fuc->data = NULL;
640 }
641}
642
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000643static void
644nvc0_graph_destroy(struct drm_device *dev, int engine)
645{
646 struct nvc0_graph_priv *priv = nv_engine(dev, engine);
647
Ben Skeggsfe799112011-04-12 18:50:36 +1000648 nvc0_graph_destroy_fw(&priv->fuc409c);
649 nvc0_graph_destroy_fw(&priv->fuc409d);
650 nvc0_graph_destroy_fw(&priv->fuc41ac);
651 nvc0_graph_destroy_fw(&priv->fuc41ad);
652
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000653 nouveau_irq_unregister(dev, 12);
654 nouveau_irq_unregister(dev, 25);
655
656 nouveau_gpuobj_ref(NULL, &priv->unk4188b8);
657 nouveau_gpuobj_ref(NULL, &priv->unk4188b4);
658
659 if (priv->grctx_vals)
660 kfree(priv->grctx_vals);
661
662 NVOBJ_ENGINE_DEL(dev, GR);
663 kfree(priv);
664}
665
666int
667nvc0_graph_create(struct drm_device *dev)
668{
669 struct drm_nouveau_private *dev_priv = dev->dev_private;
670 struct nvc0_graph_priv *priv;
671 int ret, gpc, i;
672
Ben Skeggsa82dd492011-04-01 13:56:05 +1000673 switch (dev_priv->chipset) {
674 case 0xc0:
675 case 0xc3:
676 case 0xc4:
677 break;
678 default:
679 NV_ERROR(dev, "PGRAPH: unsupported chipset, please report!\n");
680 return 0;
681 }
682
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000683 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
684 if (!priv)
685 return -ENOMEM;
686
687 priv->base.destroy = nvc0_graph_destroy;
688 priv->base.init = nvc0_graph_init;
689 priv->base.fini = nvc0_graph_fini;
690 priv->base.context_new = nvc0_graph_context_new;
691 priv->base.context_del = nvc0_graph_context_del;
692 priv->base.object_new = nvc0_graph_object_new;
693
694 NVOBJ_ENGINE_ADD(dev, GR, &priv->base);
695 nouveau_irq_register(dev, 12, nvc0_graph_isr);
696 nouveau_irq_register(dev, 25, nvc0_runk140_isr);
697
Ben Skeggsfe799112011-04-12 18:50:36 +1000698 if (nvc0_graph_create_fw(dev, "fuc409c", &priv->fuc409c) ||
699 nvc0_graph_create_fw(dev, "fuc409d", &priv->fuc409d) ||
700 nvc0_graph_create_fw(dev, "fuc41ac", &priv->fuc41ac) ||
701 nvc0_graph_create_fw(dev, "fuc41ad", &priv->fuc41ad)) {
702 ret = 0;
703 goto error;
704 }
705
706
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000707 ret = nouveau_gpuobj_new(dev, NULL, 0x1000, 256, 0, &priv->unk4188b4);
708 if (ret)
709 goto error;
710
711 ret = nouveau_gpuobj_new(dev, NULL, 0x1000, 256, 0, &priv->unk4188b8);
712 if (ret)
713 goto error;
714
715 for (i = 0; i < 0x1000; i += 4) {
716 nv_wo32(priv->unk4188b4, i, 0x00000010);
717 nv_wo32(priv->unk4188b8, i, 0x00000010);
718 }
719
720 priv->gpc_nr = nv_rd32(dev, 0x409604) & 0x0000001f;
721 priv->rop_nr = (nv_rd32(dev, 0x409604) & 0x001f0000) >> 16;
722 for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
723 priv->tp_nr[gpc] = nv_rd32(dev, GPC_UNIT(gpc, 0x2608));
724 priv->tp_total += priv->tp_nr[gpc];
725 }
726
727 /*XXX: these need figuring out... */
728 switch (dev_priv->chipset) {
729 case 0xc0:
730 if (priv->tp_total == 11) { /* 465, 3/4/4/0, 4 */
731 priv->magic_not_rop_nr = 0x07;
732 /* filled values up to tp_total, the rest 0 */
733 priv->magicgpc980[0] = 0x22111000;
734 priv->magicgpc980[1] = 0x00000233;
735 priv->magicgpc980[2] = 0x00000000;
736 priv->magicgpc980[3] = 0x00000000;
737 priv->magicgpc918 = 0x000ba2e9;
738 } else
739 if (priv->tp_total == 14) { /* 470, 3/3/4/4, 5 */
740 priv->magic_not_rop_nr = 0x05;
741 priv->magicgpc980[0] = 0x11110000;
742 priv->magicgpc980[1] = 0x00233222;
743 priv->magicgpc980[2] = 0x00000000;
744 priv->magicgpc980[3] = 0x00000000;
745 priv->magicgpc918 = 0x00092493;
746 } else
747 if (priv->tp_total == 15) { /* 480, 3/4/4/4, 6 */
748 priv->magic_not_rop_nr = 0x06;
749 priv->magicgpc980[0] = 0x11110000;
750 priv->magicgpc980[1] = 0x03332222;
751 priv->magicgpc980[2] = 0x00000000;
752 priv->magicgpc980[3] = 0x00000000;
753 priv->magicgpc918 = 0x00088889;
754 }
755 break;
756 case 0xc3: /* 450, 4/0/0/0, 2 */
757 priv->magic_not_rop_nr = 0x03;
758 priv->magicgpc980[0] = 0x00003210;
759 priv->magicgpc980[1] = 0x00000000;
760 priv->magicgpc980[2] = 0x00000000;
761 priv->magicgpc980[3] = 0x00000000;
762 priv->magicgpc918 = 0x00200000;
763 break;
764 case 0xc4: /* 460, 3/4/0/0, 4 */
765 priv->magic_not_rop_nr = 0x01;
766 priv->magicgpc980[0] = 0x02321100;
767 priv->magicgpc980[1] = 0x00000000;
768 priv->magicgpc980[2] = 0x00000000;
769 priv->magicgpc980[3] = 0x00000000;
770 priv->magicgpc918 = 0x00124925;
771 break;
772 }
773
774 if (!priv->magic_not_rop_nr) {
775 NV_ERROR(dev, "PGRAPH: unknown config: %d/%d/%d/%d, %d\n",
776 priv->tp_nr[0], priv->tp_nr[1], priv->tp_nr[2],
777 priv->tp_nr[3], priv->rop_nr);
778 /* use 0xc3's values... */
779 priv->magic_not_rop_nr = 0x03;
780 priv->magicgpc980[0] = 0x00003210;
781 priv->magicgpc980[1] = 0x00000000;
782 priv->magicgpc980[2] = 0x00000000;
783 priv->magicgpc980[3] = 0x00000000;
784 priv->magicgpc918 = 0x00200000;
785 }
786
787 NVOBJ_CLASS(dev, 0x902d, GR); /* 2D */
788 NVOBJ_CLASS(dev, 0x9039, GR); /* M2MF */
789 NVOBJ_MTHD (dev, 0x9039, 0x0500, nvc0_graph_mthd_page_flip);
790 NVOBJ_CLASS(dev, 0x9097, GR); /* 3D */
791 NVOBJ_CLASS(dev, 0x90c0, GR); /* COMPUTE */
792 return 0;
793
794error:
795 nvc0_graph_destroy(dev, NVOBJ_ENGINE_GR);
796 return ret;
797}
Ben Skeggsfe799112011-04-12 18:50:36 +1000798
799MODULE_FIRMWARE("nouveau/nvc0_fuc409c");
800MODULE_FIRMWARE("nouveau/nvc0_fuc409d");
801MODULE_FIRMWARE("nouveau/nvc0_fuc41ac");
802MODULE_FIRMWARE("nouveau/nvc0_fuc41ad");
803MODULE_FIRMWARE("nouveau/nvc3_fuc409c");
804MODULE_FIRMWARE("nouveau/nvc3_fuc409d");
805MODULE_FIRMWARE("nouveau/nvc3_fuc41ac");
806MODULE_FIRMWARE("nouveau/nvc3_fuc41ad");
807MODULE_FIRMWARE("nouveau/nvc4_fuc409c");
808MODULE_FIRMWARE("nouveau/nvc4_fuc409d");
809MODULE_FIRMWARE("nouveau/nvc4_fuc41ac");
810MODULE_FIRMWARE("nouveau/nvc4_fuc41ad");
811MODULE_FIRMWARE("nouveau/fuc409c");
812MODULE_FIRMWARE("nouveau/fuc409d");
813MODULE_FIRMWARE("nouveau/fuc41ac");
814MODULE_FIRMWARE("nouveau/fuc41ad");