blob: dcb8d9a12120fd2da636ec14dbb108a6ce3e4b4c [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 Skeggs7a45cd12011-04-01 10:59:53 +1000253 u32 inst = nv_rd32(dev, 0x409b00);
254 if (inst & 0x80000000) {
255 inst &= 0x0fffffff;
256 nvc0_graph_unload_context_to(dev, (u64)inst << 12);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000257 }
258
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000259 return 0;
260}
261
Ben Skeggs966a5b72010-11-24 10:49:02 +1000262static int
Ben Skeggsbd2f2032011-02-08 15:16:23 +1000263nvc0_graph_mthd_page_flip(struct nouveau_channel *chan,
264 u32 class, u32 mthd, u32 data)
265{
266 nouveau_finish_page_flip(chan, NULL);
267 return 0;
268}
269
Ben Skeggs966a5b72010-11-24 10:49:02 +1000270static void
271nvc0_graph_init_obj418880(struct drm_device *dev)
272{
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000273 struct nvc0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000274 int i;
275
276 nv_wr32(dev, GPC_BCAST(0x0880), 0x00000000);
277 nv_wr32(dev, GPC_BCAST(0x08a4), 0x00000000);
278 for (i = 0; i < 4; i++)
279 nv_wr32(dev, GPC_BCAST(0x0888) + (i * 4), 0x00000000);
280 nv_wr32(dev, GPC_BCAST(0x08b4), priv->unk4188b4->vinst >> 8);
281 nv_wr32(dev, GPC_BCAST(0x08b8), priv->unk4188b8->vinst >> 8);
282}
283
284static void
285nvc0_graph_init_regs(struct drm_device *dev)
286{
287 nv_wr32(dev, 0x400080, 0x003083c2);
288 nv_wr32(dev, 0x400088, 0x00006fe7);
289 nv_wr32(dev, 0x40008c, 0x00000000);
290 nv_wr32(dev, 0x400090, 0x00000030);
291 nv_wr32(dev, 0x40013c, 0x013901f7);
292 nv_wr32(dev, 0x400140, 0x00000100);
293 nv_wr32(dev, 0x400144, 0x00000000);
294 nv_wr32(dev, 0x400148, 0x00000110);
295 nv_wr32(dev, 0x400138, 0x00000000);
296 nv_wr32(dev, 0x400130, 0x00000000);
297 nv_wr32(dev, 0x400134, 0x00000000);
298 nv_wr32(dev, 0x400124, 0x00000002);
299}
300
301static void
302nvc0_graph_init_gpc_0(struct drm_device *dev)
303{
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000304 struct nvc0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000305 int gpc;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000306
Emil Velikovf2129492011-03-19 23:31:52 +0000307 /*
308 * TP ROP UNKVAL(magic_not_rop_nr)
309 * 450: 4/0/0/0 2 3
310 * 460: 3/4/0/0 4 1
311 * 465: 3/4/4/0 4 7
312 * 470: 3/3/4/4 5 5
313 * 480: 3/4/4/4 6 6
Ben Skeggs966a5b72010-11-24 10:49:02 +1000314
Emil Velikovf2129492011-03-19 23:31:52 +0000315 * magicgpc918
316 * 450: 00200000 00000000001000000000000000000000
317 * 460: 00124925 00000000000100100100100100100101
318 * 465: 000ba2e9 00000000000010111010001011101001
319 * 470: 00092493 00000000000010010010010010010011
320 * 480: 00088889 00000000000010001000100010001001
321
322 * filled values up to tp_total, remainder 0
323 * 450: 00003210 00000000 00000000 00000000
324 * 460: 02321100 00000000 00000000 00000000
325 * 465: 22111000 00000233 00000000 00000000
326 * 470: 11110000 00233222 00000000 00000000
327 * 480: 11110000 03332222 00000000 00000000
328 */
329
Ben Skeggs966a5b72010-11-24 10:49:02 +1000330 nv_wr32(dev, GPC_BCAST(0x0980), priv->magicgpc980[0]);
331 nv_wr32(dev, GPC_BCAST(0x0984), priv->magicgpc980[1]);
332 nv_wr32(dev, GPC_BCAST(0x0988), priv->magicgpc980[2]);
333 nv_wr32(dev, GPC_BCAST(0x098c), priv->magicgpc980[3]);
334
335 for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
336 nv_wr32(dev, GPC_UNIT(gpc, 0x0914), priv->magic_not_rop_nr << 8 |
337 priv->tp_nr[gpc]);
338 nv_wr32(dev, GPC_UNIT(gpc, 0x0910), 0x00040000 | priv->tp_total);
339 nv_wr32(dev, GPC_UNIT(gpc, 0x0918), priv->magicgpc918);
340 }
341
342 nv_wr32(dev, GPC_BCAST(0x1bd4), priv->magicgpc918);
343 nv_wr32(dev, GPC_BCAST(0x08ac), priv->rop_nr);
344}
345
346static void
347nvc0_graph_init_units(struct drm_device *dev)
348{
349 nv_wr32(dev, 0x409c24, 0x000f0000);
350 nv_wr32(dev, 0x404000, 0xc0000000); /* DISPATCH */
351 nv_wr32(dev, 0x404600, 0xc0000000); /* M2MF */
352 nv_wr32(dev, 0x408030, 0xc0000000);
353 nv_wr32(dev, 0x40601c, 0xc0000000);
354 nv_wr32(dev, 0x404490, 0xc0000000); /* MACRO */
355 nv_wr32(dev, 0x406018, 0xc0000000);
356 nv_wr32(dev, 0x405840, 0xc0000000);
357 nv_wr32(dev, 0x405844, 0x00ffffff);
358 nv_mask(dev, 0x419cc0, 0x00000008, 0x00000008);
359 nv_mask(dev, 0x419eb4, 0x00001000, 0x00001000);
360}
361
362static void
363nvc0_graph_init_gpc_1(struct drm_device *dev)
364{
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000365 struct nvc0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000366 int gpc, tp;
367
368 for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
369 nv_wr32(dev, GPC_UNIT(gpc, 0x0420), 0xc0000000);
370 nv_wr32(dev, GPC_UNIT(gpc, 0x0900), 0xc0000000);
371 nv_wr32(dev, GPC_UNIT(gpc, 0x1028), 0xc0000000);
372 nv_wr32(dev, GPC_UNIT(gpc, 0x0824), 0xc0000000);
373 for (tp = 0; tp < priv->tp_nr[gpc]; tp++) {
374 nv_wr32(dev, TP_UNIT(gpc, tp, 0x508), 0xffffffff);
375 nv_wr32(dev, TP_UNIT(gpc, tp, 0x50c), 0xffffffff);
376 nv_wr32(dev, TP_UNIT(gpc, tp, 0x224), 0xc0000000);
377 nv_wr32(dev, TP_UNIT(gpc, tp, 0x48c), 0xc0000000);
378 nv_wr32(dev, TP_UNIT(gpc, tp, 0x084), 0xc0000000);
Ben Skeggs0f1cb202011-01-21 11:15:16 +1000379 nv_wr32(dev, TP_UNIT(gpc, tp, 0x644), 0x001ffffe);
380 nv_wr32(dev, TP_UNIT(gpc, tp, 0x64c), 0x0000000f);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000381 }
382 nv_wr32(dev, GPC_UNIT(gpc, 0x2c90), 0xffffffff);
383 nv_wr32(dev, GPC_UNIT(gpc, 0x2c94), 0xffffffff);
384 }
385}
386
387static void
388nvc0_graph_init_rop(struct drm_device *dev)
389{
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000390 struct nvc0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000391 int rop;
392
393 for (rop = 0; rop < priv->rop_nr; rop++) {
394 nv_wr32(dev, ROP_UNIT(rop, 0x144), 0xc0000000);
395 nv_wr32(dev, ROP_UNIT(rop, 0x070), 0xc0000000);
396 nv_wr32(dev, ROP_UNIT(rop, 0x204), 0xffffffff);
397 nv_wr32(dev, ROP_UNIT(rop, 0x208), 0xffffffff);
398 }
399}
400
Ben Skeggsfe799112011-04-12 18:50:36 +1000401static void
402nvc0_graph_init_fuc(struct drm_device *dev, u32 fuc_base,
403 struct nvc0_graph_fuc *code, struct nvc0_graph_fuc *data)
Ben Skeggs966a5b72010-11-24 10:49:02 +1000404{
Ben Skeggsfe799112011-04-12 18:50:36 +1000405 int i;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000406
407 nv_wr32(dev, fuc_base + 0x01c0, 0x01000000);
Ben Skeggsfe799112011-04-12 18:50:36 +1000408 for (i = 0; i < data->size / 4; i++)
409 nv_wr32(dev, fuc_base + 0x01c4, data->data[i]);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000410
411 nv_wr32(dev, fuc_base + 0x0180, 0x01000000);
Ben Skeggsfe799112011-04-12 18:50:36 +1000412 for (i = 0; i < code->size / 4; i++) {
Ben Skeggs966a5b72010-11-24 10:49:02 +1000413 if ((i & 0x3f) == 0)
414 nv_wr32(dev, fuc_base + 0x0188, i >> 6);
Ben Skeggsfe799112011-04-12 18:50:36 +1000415 nv_wr32(dev, fuc_base + 0x0184, code->data[i]);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000416 }
Ben Skeggs966a5b72010-11-24 10:49:02 +1000417}
418
419static int
420nvc0_graph_init_ctxctl(struct drm_device *dev)
421{
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000422 struct nvc0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000423 u32 r000260;
Ben Skeggs966a5b72010-11-24 10:49:02 +1000424
425 /* load fuc microcode */
426 r000260 = nv_mask(dev, 0x000260, 0x00000001, 0x00000000);
Ben Skeggsfe799112011-04-12 18:50:36 +1000427 nvc0_graph_init_fuc(dev, 0x409000, &priv->fuc409c, &priv->fuc409d);
428 nvc0_graph_init_fuc(dev, 0x41a000, &priv->fuc41ac, &priv->fuc41ad);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000429 nv_wr32(dev, 0x000260, r000260);
430
Ben Skeggs966a5b72010-11-24 10:49:02 +1000431 /* start both of them running */
432 nv_wr32(dev, 0x409840, 0xffffffff);
433 nv_wr32(dev, 0x41a10c, 0x00000000);
434 nv_wr32(dev, 0x40910c, 0x00000000);
435 nv_wr32(dev, 0x41a100, 0x00000002);
436 nv_wr32(dev, 0x409100, 0x00000002);
437 if (!nv_wait(dev, 0x409800, 0x00000001, 0x00000001))
438 NV_INFO(dev, "0x409800 wait failed\n");
439
440 nv_wr32(dev, 0x409840, 0xffffffff);
441 nv_wr32(dev, 0x409500, 0x7fffffff);
442 nv_wr32(dev, 0x409504, 0x00000021);
443
444 nv_wr32(dev, 0x409840, 0xffffffff);
445 nv_wr32(dev, 0x409500, 0x00000000);
446 nv_wr32(dev, 0x409504, 0x00000010);
447 if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
448 NV_ERROR(dev, "fuc09 req 0x10 timeout\n");
449 return -EBUSY;
450 }
451 priv->grctx_size = nv_rd32(dev, 0x409800);
452
453 nv_wr32(dev, 0x409840, 0xffffffff);
454 nv_wr32(dev, 0x409500, 0x00000000);
455 nv_wr32(dev, 0x409504, 0x00000016);
456 if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
457 NV_ERROR(dev, "fuc09 req 0x16 timeout\n");
458 return -EBUSY;
459 }
460
461 nv_wr32(dev, 0x409840, 0xffffffff);
462 nv_wr32(dev, 0x409500, 0x00000000);
463 nv_wr32(dev, 0x409504, 0x00000025);
464 if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
465 NV_ERROR(dev, "fuc09 req 0x25 timeout\n");
466 return -EBUSY;
467 }
468
469 return 0;
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000470}
471
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000472static int
473nvc0_graph_init(struct drm_device *dev, int engine)
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000474{
Ben Skeggs966a5b72010-11-24 10:49:02 +1000475 int ret;
476
Ben Skeggs966a5b72010-11-24 10:49:02 +1000477 nv_mask(dev, 0x000200, 0x18001000, 0x00000000);
478 nv_mask(dev, 0x000200, 0x18001000, 0x18001000);
479
Ben Skeggs966a5b72010-11-24 10:49:02 +1000480 nvc0_graph_init_obj418880(dev);
481 nvc0_graph_init_regs(dev);
Emil Velikovf2129492011-03-19 23:31:52 +0000482 /*nvc0_graph_init_unitplemented_magics(dev);*/
Ben Skeggs966a5b72010-11-24 10:49:02 +1000483 nvc0_graph_init_gpc_0(dev);
Emil Velikovf2129492011-03-19 23:31:52 +0000484 /*nvc0_graph_init_unitplemented_c242(dev);*/
Ben Skeggs966a5b72010-11-24 10:49:02 +1000485
486 nv_wr32(dev, 0x400500, 0x00010001);
487 nv_wr32(dev, 0x400100, 0xffffffff);
488 nv_wr32(dev, 0x40013c, 0xffffffff);
489
490 nvc0_graph_init_units(dev);
491 nvc0_graph_init_gpc_1(dev);
492 nvc0_graph_init_rop(dev);
493
494 nv_wr32(dev, 0x400108, 0xffffffff);
495 nv_wr32(dev, 0x400138, 0xffffffff);
496 nv_wr32(dev, 0x400118, 0xffffffff);
497 nv_wr32(dev, 0x400130, 0xffffffff);
498 nv_wr32(dev, 0x40011c, 0xffffffff);
499 nv_wr32(dev, 0x400134, 0xffffffff);
500 nv_wr32(dev, 0x400054, 0x34ce3464);
501
502 ret = nvc0_graph_init_ctxctl(dev);
Ben Skeggsa82dd492011-04-01 13:56:05 +1000503 if (ret)
504 return ret;
505
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000506 return 0;
507}
508
Ben Skeggsd5a27372011-04-01 16:10:08 +1000509int
Ben Skeggs966a5b72010-11-24 10:49:02 +1000510nvc0_graph_isr_chid(struct drm_device *dev, u64 inst)
511{
512 struct drm_nouveau_private *dev_priv = dev->dev_private;
513 struct nouveau_channel *chan;
514 unsigned long flags;
515 int i;
516
517 spin_lock_irqsave(&dev_priv->channels.lock, flags);
518 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
519 chan = dev_priv->channels.ptr[i];
520 if (!chan || !chan->ramin)
521 continue;
522
523 if (inst == chan->ramin->vinst)
524 break;
525 }
526 spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
527 return i;
528}
529
530static void
531nvc0_graph_isr(struct drm_device *dev)
532{
533 u64 inst = (u64)(nv_rd32(dev, 0x409b00) & 0x0fffffff) << 12;
534 u32 chid = nvc0_graph_isr_chid(dev, inst);
535 u32 stat = nv_rd32(dev, 0x400100);
536 u32 addr = nv_rd32(dev, 0x400704);
537 u32 mthd = (addr & 0x00003ffc);
538 u32 subc = (addr & 0x00070000) >> 16;
539 u32 data = nv_rd32(dev, 0x400708);
540 u32 code = nv_rd32(dev, 0x400110);
541 u32 class = nv_rd32(dev, 0x404200 + (subc * 4));
542
543 if (stat & 0x00000010) {
Ben Skeggsbd2f2032011-02-08 15:16:23 +1000544 if (nouveau_gpuobj_mthd_call2(dev, chid, class, mthd, data)) {
545 NV_INFO(dev, "PGRAPH: ILLEGAL_MTHD ch %d [0x%010llx] "
546 "subc %d class 0x%04x mthd 0x%04x "
547 "data 0x%08x\n",
548 chid, inst, subc, class, mthd, data);
549 }
Ben Skeggs966a5b72010-11-24 10:49:02 +1000550 nv_wr32(dev, 0x400100, 0x00000010);
551 stat &= ~0x00000010;
552 }
553
Ben Skeggseae5e7f2010-12-30 11:40:07 +1000554 if (stat & 0x00000020) {
555 NV_INFO(dev, "PGRAPH: ILLEGAL_CLASS ch %d [0x%010llx] subc %d "
556 "class 0x%04x mthd 0x%04x data 0x%08x\n",
557 chid, inst, subc, class, mthd, data);
558 nv_wr32(dev, 0x400100, 0x00000020);
559 stat &= ~0x00000020;
560 }
561
Ben Skeggs966a5b72010-11-24 10:49:02 +1000562 if (stat & 0x00100000) {
563 NV_INFO(dev, "PGRAPH: DATA_ERROR [");
Ben Skeggs6effe392010-12-30 11:48:03 +1000564 nouveau_enum_print(nv50_data_error_names, code);
Ben Skeggs966a5b72010-11-24 10:49:02 +1000565 printk("] ch %d [0x%010llx] subc %d class 0x%04x "
566 "mthd 0x%04x data 0x%08x\n",
567 chid, inst, subc, class, mthd, data);
568 nv_wr32(dev, 0x400100, 0x00100000);
569 stat &= ~0x00100000;
570 }
571
Ben Skeggseae5e7f2010-12-30 11:40:07 +1000572 if (stat & 0x00200000) {
573 u32 trap = nv_rd32(dev, 0x400108);
574 NV_INFO(dev, "PGRAPH: TRAP ch %d status 0x%08x\n", chid, trap);
575 nv_wr32(dev, 0x400108, trap);
576 nv_wr32(dev, 0x400100, 0x00200000);
577 stat &= ~0x00200000;
578 }
579
Ben Skeggs966a5b72010-11-24 10:49:02 +1000580 if (stat & 0x00080000) {
581 u32 ustat = nv_rd32(dev, 0x409c18);
582
583 NV_INFO(dev, "PGRAPH: CTXCTRL ustat 0x%08x\n", ustat);
584
585 nv_wr32(dev, 0x409c20, ustat);
586 nv_wr32(dev, 0x400100, 0x00080000);
587 stat &= ~0x00080000;
588 }
589
590 if (stat) {
591 NV_INFO(dev, "PGRAPH: unknown stat 0x%08x\n", stat);
592 nv_wr32(dev, 0x400100, stat);
593 }
594
595 nv_wr32(dev, 0x400500, 0x00010001);
596}
Ben Skeggs51f73d62011-01-21 13:53:21 +1000597
598static void
599nvc0_runk140_isr(struct drm_device *dev)
600{
601 u32 units = nv_rd32(dev, 0x00017c) & 0x1f;
602
603 while (units) {
604 u32 unit = ffs(units) - 1;
605 u32 reg = 0x140000 + unit * 0x2000;
606 u32 st0 = nv_mask(dev, reg + 0x1020, 0, 0);
607 u32 st1 = nv_mask(dev, reg + 0x1420, 0, 0);
608
609 NV_INFO(dev, "PRUNK140: %d 0x%08x 0x%08x\n", unit, st0, st1);
610 units &= ~(1 << unit);
611 }
612}
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000613
Ben Skeggsfe799112011-04-12 18:50:36 +1000614static int
615nvc0_graph_create_fw(struct drm_device *dev, const char *fwname,
616 struct nvc0_graph_fuc *fuc)
617{
618 struct drm_nouveau_private *dev_priv = dev->dev_private;
619 const struct firmware *fw;
620 char f[32];
621 int ret;
622
623 snprintf(f, sizeof(f), "nouveau/nv%02x_%s", dev_priv->chipset, fwname);
624 ret = request_firmware(&fw, f, &dev->pdev->dev);
625 if (ret) {
626 snprintf(f, sizeof(f), "nouveau/%s", fwname);
627 ret = request_firmware(&fw, f, &dev->pdev->dev);
628 if (ret) {
629 NV_ERROR(dev, "failed to load %s\n", fwname);
630 return ret;
631 }
632 }
633
634 fuc->size = fw->size;
635 fuc->data = kmemdup(fw->data, fuc->size, GFP_KERNEL);
636 release_firmware(fw);
637 return (fuc->data != NULL) ? 0 : -ENOMEM;
638}
639
640static void
641nvc0_graph_destroy_fw(struct nvc0_graph_fuc *fuc)
642{
643 if (fuc->data) {
644 kfree(fuc->data);
645 fuc->data = NULL;
646 }
647}
648
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000649static void
650nvc0_graph_destroy(struct drm_device *dev, int engine)
651{
652 struct nvc0_graph_priv *priv = nv_engine(dev, engine);
653
Ben Skeggsfe799112011-04-12 18:50:36 +1000654 nvc0_graph_destroy_fw(&priv->fuc409c);
655 nvc0_graph_destroy_fw(&priv->fuc409d);
656 nvc0_graph_destroy_fw(&priv->fuc41ac);
657 nvc0_graph_destroy_fw(&priv->fuc41ad);
658
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000659 nouveau_irq_unregister(dev, 12);
660 nouveau_irq_unregister(dev, 25);
661
662 nouveau_gpuobj_ref(NULL, &priv->unk4188b8);
663 nouveau_gpuobj_ref(NULL, &priv->unk4188b4);
664
665 if (priv->grctx_vals)
666 kfree(priv->grctx_vals);
667
668 NVOBJ_ENGINE_DEL(dev, GR);
669 kfree(priv);
670}
671
672int
673nvc0_graph_create(struct drm_device *dev)
674{
675 struct drm_nouveau_private *dev_priv = dev->dev_private;
676 struct nvc0_graph_priv *priv;
677 int ret, gpc, i;
678
Ben Skeggsa82dd492011-04-01 13:56:05 +1000679 switch (dev_priv->chipset) {
680 case 0xc0:
681 case 0xc3:
682 case 0xc4:
683 break;
684 default:
685 NV_ERROR(dev, "PGRAPH: unsupported chipset, please report!\n");
686 return 0;
687 }
688
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000689 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
690 if (!priv)
691 return -ENOMEM;
692
693 priv->base.destroy = nvc0_graph_destroy;
694 priv->base.init = nvc0_graph_init;
695 priv->base.fini = nvc0_graph_fini;
696 priv->base.context_new = nvc0_graph_context_new;
697 priv->base.context_del = nvc0_graph_context_del;
698 priv->base.object_new = nvc0_graph_object_new;
699
700 NVOBJ_ENGINE_ADD(dev, GR, &priv->base);
701 nouveau_irq_register(dev, 12, nvc0_graph_isr);
702 nouveau_irq_register(dev, 25, nvc0_runk140_isr);
703
Ben Skeggsfe799112011-04-12 18:50:36 +1000704 if (nvc0_graph_create_fw(dev, "fuc409c", &priv->fuc409c) ||
705 nvc0_graph_create_fw(dev, "fuc409d", &priv->fuc409d) ||
706 nvc0_graph_create_fw(dev, "fuc41ac", &priv->fuc41ac) ||
707 nvc0_graph_create_fw(dev, "fuc41ad", &priv->fuc41ad)) {
708 ret = 0;
709 goto error;
710 }
711
712
Ben Skeggs7a45cd12011-04-01 10:59:53 +1000713 ret = nouveau_gpuobj_new(dev, NULL, 0x1000, 256, 0, &priv->unk4188b4);
714 if (ret)
715 goto error;
716
717 ret = nouveau_gpuobj_new(dev, NULL, 0x1000, 256, 0, &priv->unk4188b8);
718 if (ret)
719 goto error;
720
721 for (i = 0; i < 0x1000; i += 4) {
722 nv_wo32(priv->unk4188b4, i, 0x00000010);
723 nv_wo32(priv->unk4188b8, i, 0x00000010);
724 }
725
726 priv->gpc_nr = nv_rd32(dev, 0x409604) & 0x0000001f;
727 priv->rop_nr = (nv_rd32(dev, 0x409604) & 0x001f0000) >> 16;
728 for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
729 priv->tp_nr[gpc] = nv_rd32(dev, GPC_UNIT(gpc, 0x2608));
730 priv->tp_total += priv->tp_nr[gpc];
731 }
732
733 /*XXX: these need figuring out... */
734 switch (dev_priv->chipset) {
735 case 0xc0:
736 if (priv->tp_total == 11) { /* 465, 3/4/4/0, 4 */
737 priv->magic_not_rop_nr = 0x07;
738 /* filled values up to tp_total, the rest 0 */
739 priv->magicgpc980[0] = 0x22111000;
740 priv->magicgpc980[1] = 0x00000233;
741 priv->magicgpc980[2] = 0x00000000;
742 priv->magicgpc980[3] = 0x00000000;
743 priv->magicgpc918 = 0x000ba2e9;
744 } else
745 if (priv->tp_total == 14) { /* 470, 3/3/4/4, 5 */
746 priv->magic_not_rop_nr = 0x05;
747 priv->magicgpc980[0] = 0x11110000;
748 priv->magicgpc980[1] = 0x00233222;
749 priv->magicgpc980[2] = 0x00000000;
750 priv->magicgpc980[3] = 0x00000000;
751 priv->magicgpc918 = 0x00092493;
752 } else
753 if (priv->tp_total == 15) { /* 480, 3/4/4/4, 6 */
754 priv->magic_not_rop_nr = 0x06;
755 priv->magicgpc980[0] = 0x11110000;
756 priv->magicgpc980[1] = 0x03332222;
757 priv->magicgpc980[2] = 0x00000000;
758 priv->magicgpc980[3] = 0x00000000;
759 priv->magicgpc918 = 0x00088889;
760 }
761 break;
762 case 0xc3: /* 450, 4/0/0/0, 2 */
763 priv->magic_not_rop_nr = 0x03;
764 priv->magicgpc980[0] = 0x00003210;
765 priv->magicgpc980[1] = 0x00000000;
766 priv->magicgpc980[2] = 0x00000000;
767 priv->magicgpc980[3] = 0x00000000;
768 priv->magicgpc918 = 0x00200000;
769 break;
770 case 0xc4: /* 460, 3/4/0/0, 4 */
771 priv->magic_not_rop_nr = 0x01;
772 priv->magicgpc980[0] = 0x02321100;
773 priv->magicgpc980[1] = 0x00000000;
774 priv->magicgpc980[2] = 0x00000000;
775 priv->magicgpc980[3] = 0x00000000;
776 priv->magicgpc918 = 0x00124925;
777 break;
778 }
779
780 if (!priv->magic_not_rop_nr) {
781 NV_ERROR(dev, "PGRAPH: unknown config: %d/%d/%d/%d, %d\n",
782 priv->tp_nr[0], priv->tp_nr[1], priv->tp_nr[2],
783 priv->tp_nr[3], priv->rop_nr);
784 /* use 0xc3's values... */
785 priv->magic_not_rop_nr = 0x03;
786 priv->magicgpc980[0] = 0x00003210;
787 priv->magicgpc980[1] = 0x00000000;
788 priv->magicgpc980[2] = 0x00000000;
789 priv->magicgpc980[3] = 0x00000000;
790 priv->magicgpc918 = 0x00200000;
791 }
792
793 NVOBJ_CLASS(dev, 0x902d, GR); /* 2D */
794 NVOBJ_CLASS(dev, 0x9039, GR); /* M2MF */
795 NVOBJ_MTHD (dev, 0x9039, 0x0500, nvc0_graph_mthd_page_flip);
796 NVOBJ_CLASS(dev, 0x9097, GR); /* 3D */
797 NVOBJ_CLASS(dev, 0x90c0, GR); /* COMPUTE */
798 return 0;
799
800error:
801 nvc0_graph_destroy(dev, NVOBJ_ENGINE_GR);
802 return ret;
803}
Ben Skeggsfe799112011-04-12 18:50:36 +1000804
805MODULE_FIRMWARE("nouveau/nvc0_fuc409c");
806MODULE_FIRMWARE("nouveau/nvc0_fuc409d");
807MODULE_FIRMWARE("nouveau/nvc0_fuc41ac");
808MODULE_FIRMWARE("nouveau/nvc0_fuc41ad");
809MODULE_FIRMWARE("nouveau/nvc3_fuc409c");
810MODULE_FIRMWARE("nouveau/nvc3_fuc409d");
811MODULE_FIRMWARE("nouveau/nvc3_fuc41ac");
812MODULE_FIRMWARE("nouveau/nvc3_fuc41ad");
813MODULE_FIRMWARE("nouveau/nvc4_fuc409c");
814MODULE_FIRMWARE("nouveau/nvc4_fuc409d");
815MODULE_FIRMWARE("nouveau/nvc4_fuc41ac");
816MODULE_FIRMWARE("nouveau/nvc4_fuc41ad");
817MODULE_FIRMWARE("nouveau/fuc409c");
818MODULE_FIRMWARE("nouveau/fuc409d");
819MODULE_FIRMWARE("nouveau/fuc41ac");
820MODULE_FIRMWARE("nouveau/fuc41ad");