blob: 6d81f4dab37d45fa76aa5975c02260d460b05d8b [file] [log] [blame]
Ben Skeggs6ee73862009-12-11 19:24:15 +10001/*
2 * Copyright (C) 2007 Ben Skeggs.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26
27#include "drmP.h"
28#include "drm.h"
29#include "nouveau_drv.h"
Ben Skeggsa8eaebc2010-09-01 15:24:31 +100030#include "nouveau_ramht.h"
Marcin Kościelnickid5f3c902010-02-25 00:54:02 +000031#include "nouveau_grctx.h"
Francisco Jerez332b2422010-10-20 23:35:40 +020032#include "nouveau_dma.h"
33#include "nv50_evo.h"
Ben Skeggs6ee73862009-12-11 19:24:15 +100034
Ben Skeggsb8c157d2010-10-20 10:39:35 +100035static int nv50_graph_register(struct drm_device *);
36
Ben Skeggs6ee73862009-12-11 19:24:15 +100037static void
38nv50_graph_init_reset(struct drm_device *dev)
39{
40 uint32_t pmc_e = NV_PMC_ENABLE_PGRAPH | (1 << 21);
41
42 NV_DEBUG(dev, "\n");
43
44 nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) & ~pmc_e);
45 nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) | pmc_e);
46}
47
48static void
49nv50_graph_init_intr(struct drm_device *dev)
50{
51 NV_DEBUG(dev, "\n");
52
53 nv_wr32(dev, NV03_PGRAPH_INTR, 0xffffffff);
54 nv_wr32(dev, 0x400138, 0xffffffff);
55 nv_wr32(dev, NV40_PGRAPH_INTR_EN, 0xffffffff);
56}
57
58static void
59nv50_graph_init_regs__nv(struct drm_device *dev)
60{
Marcin Kościelnicki304424e2010-03-01 00:18:39 +000061 struct drm_nouveau_private *dev_priv = dev->dev_private;
62 uint32_t units = nv_rd32(dev, 0x1540);
63 int i;
64
Ben Skeggs6ee73862009-12-11 19:24:15 +100065 NV_DEBUG(dev, "\n");
66
67 nv_wr32(dev, 0x400804, 0xc0000000);
68 nv_wr32(dev, 0x406800, 0xc0000000);
69 nv_wr32(dev, 0x400c04, 0xc0000000);
Marcin Kościelnicki716abaa2010-01-12 18:21:56 +000070 nv_wr32(dev, 0x401800, 0xc0000000);
Ben Skeggs6ee73862009-12-11 19:24:15 +100071 nv_wr32(dev, 0x405018, 0xc0000000);
72 nv_wr32(dev, 0x402000, 0xc0000000);
73
Marcin Kościelnicki304424e2010-03-01 00:18:39 +000074 for (i = 0; i < 16; i++) {
75 if (units & 1 << i) {
76 if (dev_priv->chipset < 0xa0) {
77 nv_wr32(dev, 0x408900 + (i << 12), 0xc0000000);
78 nv_wr32(dev, 0x408e08 + (i << 12), 0xc0000000);
79 nv_wr32(dev, 0x408314 + (i << 12), 0xc0000000);
80 } else {
81 nv_wr32(dev, 0x408600 + (i << 11), 0xc0000000);
82 nv_wr32(dev, 0x408708 + (i << 11), 0xc0000000);
83 nv_wr32(dev, 0x40831c + (i << 11), 0xc0000000);
84 }
85 }
86 }
87
Ben Skeggs6ee73862009-12-11 19:24:15 +100088 nv_wr32(dev, 0x400108, 0xffffffff);
89
90 nv_wr32(dev, 0x400824, 0x00004000);
91 nv_wr32(dev, 0x400500, 0x00010001);
92}
93
94static void
95nv50_graph_init_regs(struct drm_device *dev)
96{
97 NV_DEBUG(dev, "\n");
98
99 nv_wr32(dev, NV04_PGRAPH_DEBUG_3,
100 (1 << 2) /* HW_CONTEXT_SWITCH_ENABLED */);
101 nv_wr32(dev, 0x402ca8, 0x800);
102}
103
104static int
105nv50_graph_init_ctxctl(struct drm_device *dev)
106{
Ben Skeggs054b93e2009-12-15 22:02:47 +1000107 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsec91db22010-07-08 11:53:19 +1000108 struct nouveau_grctx ctx = {};
109 uint32_t *cp;
110 int i;
Ben Skeggs054b93e2009-12-15 22:02:47 +1000111
Ben Skeggs6ee73862009-12-11 19:24:15 +1000112 NV_DEBUG(dev, "\n");
113
Ben Skeggsec91db22010-07-08 11:53:19 +1000114 cp = kmalloc(512 * 4, GFP_KERNEL);
115 if (!cp) {
116 NV_ERROR(dev, "failed to allocate ctxprog\n");
117 dev_priv->engine.graph.accel_blocked = true;
118 return 0;
Marcin Kościelnickid5f3c902010-02-25 00:54:02 +0000119 }
Marcin Kościelnickid5f3c902010-02-25 00:54:02 +0000120
Ben Skeggsec91db22010-07-08 11:53:19 +1000121 ctx.dev = dev;
122 ctx.mode = NOUVEAU_GRCTX_PROG;
123 ctx.data = cp;
124 ctx.ctxprog_max = 512;
125 if (!nv50_grctx_init(&ctx)) {
126 dev_priv->engine.graph.grctx_size = ctx.ctxvals_pos * 4;
127
128 nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0);
129 for (i = 0; i < ctx.ctxprog_len; i++)
130 nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_DATA, cp[i]);
131 } else {
132 dev_priv->engine.graph.accel_blocked = true;
Marcin Kościelnickid5f3c902010-02-25 00:54:02 +0000133 }
Ben Skeggsec91db22010-07-08 11:53:19 +1000134 kfree(cp);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000135
136 nv_wr32(dev, 0x400320, 4);
137 nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, 0);
138 nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, 0);
139 return 0;
140}
141
142int
143nv50_graph_init(struct drm_device *dev)
144{
145 int ret;
146
147 NV_DEBUG(dev, "\n");
148
149 nv50_graph_init_reset(dev);
150 nv50_graph_init_regs__nv(dev);
151 nv50_graph_init_regs(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000152
153 ret = nv50_graph_init_ctxctl(dev);
154 if (ret)
155 return ret;
156
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000157 ret = nv50_graph_register(dev);
158 if (ret)
159 return ret;
160 nv50_graph_init_intr(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000161 return 0;
162}
163
164void
165nv50_graph_takedown(struct drm_device *dev)
166{
167 NV_DEBUG(dev, "\n");
Ben Skeggs6ee73862009-12-11 19:24:15 +1000168}
169
170void
171nv50_graph_fifo_access(struct drm_device *dev, bool enabled)
172{
173 const uint32_t mask = 0x00010001;
174
175 if (enabled)
176 nv_wr32(dev, 0x400500, nv_rd32(dev, 0x400500) | mask);
177 else
178 nv_wr32(dev, 0x400500, nv_rd32(dev, 0x400500) & ~mask);
179}
180
181struct nouveau_channel *
182nv50_graph_channel(struct drm_device *dev)
183{
184 struct drm_nouveau_private *dev_priv = dev->dev_private;
185 uint32_t inst;
186 int i;
187
Maarten Maathuisa51a3bf2010-02-01 18:32:09 +0100188 /* Be sure we're not in the middle of a context switch or bad things
189 * will happen, such as unloading the wrong pgraph context.
190 */
Francisco Jerez4b5c1522010-09-07 17:34:44 +0200191 if (!nv_wait(dev, 0x400300, 0x00000001, 0x00000000))
Maarten Maathuisa51a3bf2010-02-01 18:32:09 +0100192 NV_ERROR(dev, "Ctxprog is still running\n");
193
Ben Skeggs6ee73862009-12-11 19:24:15 +1000194 inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_CUR);
195 if (!(inst & NV50_PGRAPH_CTXCTL_CUR_LOADED))
196 return NULL;
197 inst = (inst & NV50_PGRAPH_CTXCTL_CUR_INSTANCE) << 12;
198
199 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
Ben Skeggscff5c132010-10-06 16:16:59 +1000200 struct nouveau_channel *chan = dev_priv->channels.ptr[i];
Ben Skeggs6ee73862009-12-11 19:24:15 +1000201
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000202 if (chan && chan->ramin && chan->ramin->vinst == inst)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000203 return chan;
204 }
205
206 return NULL;
207}
208
209int
210nv50_graph_create_context(struct nouveau_channel *chan)
211{
212 struct drm_device *dev = chan->dev;
213 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000214 struct nouveau_gpuobj *ramin = chan->ramin;
Marcin Kościelnickid5f3c902010-02-25 00:54:02 +0000215 struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
Ben Skeggsec91db22010-07-08 11:53:19 +1000216 struct nouveau_grctx ctx = {};
Ben Skeggs6ee73862009-12-11 19:24:15 +1000217 int hdr, ret;
218
219 NV_DEBUG(dev, "ch%d\n", chan->id);
220
Ben Skeggs3052be22010-10-20 11:46:38 +1000221 ret = nouveau_gpuobj_new(dev, chan, pgraph->grctx_size, 0,
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000222 NVOBJ_FLAG_ZERO_ALLOC |
223 NVOBJ_FLAG_ZERO_FREE, &chan->ramin_grctx);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000224 if (ret)
225 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000226
Ben Skeggsac94a342010-07-08 15:28:48 +1000227 hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
Ben Skeggsb3beb162010-09-01 15:24:29 +1000228 nv_wo32(ramin, hdr + 0x00, 0x00190002);
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000229 nv_wo32(ramin, hdr + 0x04, chan->ramin_grctx->vinst +
Ben Skeggsb3beb162010-09-01 15:24:29 +1000230 pgraph->grctx_size - 1);
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000231 nv_wo32(ramin, hdr + 0x08, chan->ramin_grctx->vinst);
Ben Skeggsb3beb162010-09-01 15:24:29 +1000232 nv_wo32(ramin, hdr + 0x0c, 0);
233 nv_wo32(ramin, hdr + 0x10, 0);
234 nv_wo32(ramin, hdr + 0x14, 0x00010000);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000235
Ben Skeggsec91db22010-07-08 11:53:19 +1000236 ctx.dev = chan->dev;
237 ctx.mode = NOUVEAU_GRCTX_VALS;
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000238 ctx.data = chan->ramin_grctx;
Ben Skeggsec91db22010-07-08 11:53:19 +1000239 nv50_grctx_init(&ctx);
240
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000241 nv_wo32(chan->ramin_grctx, 0x00000, chan->ramin->vinst >> 12);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000242
Ben Skeggsf56cb862010-07-08 11:29:10 +1000243 dev_priv->engine.instmem.flush(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000244 return 0;
245}
246
247void
248nv50_graph_destroy_context(struct nouveau_channel *chan)
249{
250 struct drm_device *dev = chan->dev;
251 struct drm_nouveau_private *dev_priv = dev->dev_private;
Francisco Jerez3945e472010-10-18 03:53:39 +0200252 struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
Ben Skeggsac94a342010-07-08 15:28:48 +1000253 int i, hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
Francisco Jerez3945e472010-10-18 03:53:39 +0200254 unsigned long flags;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000255
256 NV_DEBUG(dev, "ch%d\n", chan->id);
257
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000258 if (!chan->ramin)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000259 return;
260
Francisco Jerez3945e472010-10-18 03:53:39 +0200261 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
262 pgraph->fifo_access(dev, false);
263
264 if (pgraph->channel(dev) == chan)
265 pgraph->unload_context(dev);
266
Ben Skeggs6ee73862009-12-11 19:24:15 +1000267 for (i = hdr; i < hdr + 24; i += 4)
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000268 nv_wo32(chan->ramin, i, 0);
Ben Skeggsf56cb862010-07-08 11:29:10 +1000269 dev_priv->engine.instmem.flush(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000270
Francisco Jerez3945e472010-10-18 03:53:39 +0200271 pgraph->fifo_access(dev, true);
272 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
273
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000274 nouveau_gpuobj_ref(NULL, &chan->ramin_grctx);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000275}
276
277static int
278nv50_graph_do_load_context(struct drm_device *dev, uint32_t inst)
279{
280 uint32_t fifo = nv_rd32(dev, 0x400500);
281
282 nv_wr32(dev, 0x400500, fifo & ~1);
283 nv_wr32(dev, 0x400784, inst);
284 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) | 0x40);
285 nv_wr32(dev, 0x400320, nv_rd32(dev, 0x400320) | 0x11);
286 nv_wr32(dev, 0x400040, 0xffffffff);
287 (void)nv_rd32(dev, 0x400040);
288 nv_wr32(dev, 0x400040, 0x00000000);
289 nv_wr32(dev, 0x400304, nv_rd32(dev, 0x400304) | 1);
290
291 if (nouveau_wait_for_idle(dev))
292 nv_wr32(dev, 0x40032c, inst | (1<<31));
293 nv_wr32(dev, 0x400500, fifo);
294
295 return 0;
296}
297
298int
299nv50_graph_load_context(struct nouveau_channel *chan)
300{
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000301 uint32_t inst = chan->ramin->vinst >> 12;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000302
303 NV_DEBUG(chan->dev, "ch%d\n", chan->id);
304 return nv50_graph_do_load_context(chan->dev, inst);
305}
306
307int
308nv50_graph_unload_context(struct drm_device *dev)
309{
Maarten Maathuisa51a3bf2010-02-01 18:32:09 +0100310 uint32_t inst;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000311
312 inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_CUR);
313 if (!(inst & NV50_PGRAPH_CTXCTL_CUR_LOADED))
314 return 0;
315 inst &= NV50_PGRAPH_CTXCTL_CUR_INSTANCE;
316
Maarten Maathuis0a90dc512010-01-11 21:18:53 +0100317 nouveau_wait_for_idle(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000318 nv_wr32(dev, 0x400784, inst);
319 nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) | 0x20);
320 nv_wr32(dev, 0x400304, nv_rd32(dev, 0x400304) | 0x01);
321 nouveau_wait_for_idle(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000322
323 nv_wr32(dev, NV50_PGRAPH_CTXCTL_CUR, inst);
324 return 0;
325}
326
327void
328nv50_graph_context_switch(struct drm_device *dev)
329{
330 uint32_t inst;
331
332 nv50_graph_unload_context(dev);
333
334 inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_NEXT);
335 inst &= NV50_PGRAPH_CTXCTL_NEXT_INSTANCE;
336 nv50_graph_do_load_context(dev, inst);
337
338 nv_wr32(dev, NV40_PGRAPH_INTR_EN, nv_rd32(dev,
339 NV40_PGRAPH_INTR_EN) | NV_PGRAPH_INTR_CONTEXT_SWITCH);
340}
341
342static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000343nv50_graph_nvsw_dma_vblsem(struct nouveau_channel *chan,
344 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000345{
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000346 struct nouveau_gpuobj *gpuobj;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000347
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000348 gpuobj = nouveau_ramht_find(chan, data);
349 if (!gpuobj)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000350 return -ENOENT;
351
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000352 if (nouveau_notifier_offset(gpuobj, NULL))
Ben Skeggs6ee73862009-12-11 19:24:15 +1000353 return -EINVAL;
354
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000355 chan->nvsw.vblsem = gpuobj;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000356 chan->nvsw.vblsem_offset = ~0;
357 return 0;
358}
359
360static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000361nv50_graph_nvsw_vblsem_offset(struct nouveau_channel *chan,
362 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000363{
364 if (nouveau_notifier_offset(chan->nvsw.vblsem, &data))
365 return -ERANGE;
366
367 chan->nvsw.vblsem_offset = data >> 2;
368 return 0;
369}
370
371static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000372nv50_graph_nvsw_vblsem_release_val(struct nouveau_channel *chan,
373 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000374{
375 chan->nvsw.vblsem_rval = data;
376 return 0;
377}
378
379static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000380nv50_graph_nvsw_vblsem_release(struct nouveau_channel *chan,
381 u32 class, u32 mthd, u32 data)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000382{
383 struct drm_device *dev = chan->dev;
384 struct drm_nouveau_private *dev_priv = dev->dev_private;
385
386 if (!chan->nvsw.vblsem || chan->nvsw.vblsem_offset == ~0 || data > 1)
387 return -EINVAL;
388
Francisco Jerez042206c2010-10-21 18:19:29 +0200389 drm_vblank_get(dev, data);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000390 list_add(&chan->nvsw.vbl_wait, &dev_priv->vbl_waiting);
391 return 0;
392}
393
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000394static int
Francisco Jerez332b2422010-10-20 23:35:40 +0200395nv50_graph_nvsw_mthd_page_flip(struct nouveau_channel *chan,
396 u32 class, u32 mthd, u32 data)
397{
398 struct nouveau_page_flip_state s;
399
400 if (!nouveau_finish_page_flip(chan, &s)) {
401 /* XXX - Do something here */
402 }
403
404 return 0;
405}
406
407static int
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000408nv50_graph_register(struct drm_device *dev)
409{
410 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000411
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000412 if (dev_priv->engine.graph.registered)
413 return 0;
414
415 NVOBJ_CLASS(dev, 0x506e, SW); /* nvsw */
416 NVOBJ_MTHD (dev, 0x506e, 0x018c, nv50_graph_nvsw_dma_vblsem);
417 NVOBJ_MTHD (dev, 0x506e, 0x0400, nv50_graph_nvsw_vblsem_offset);
418 NVOBJ_MTHD (dev, 0x506e, 0x0404, nv50_graph_nvsw_vblsem_release_val);
419 NVOBJ_MTHD (dev, 0x506e, 0x0408, nv50_graph_nvsw_vblsem_release);
Francisco Jerez332b2422010-10-20 23:35:40 +0200420 NVOBJ_MTHD (dev, 0x506e, 0x0500, nv50_graph_nvsw_mthd_page_flip);
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000421
422 NVOBJ_CLASS(dev, 0x0030, GR); /* null */
423 NVOBJ_CLASS(dev, 0x5039, GR); /* m2mf */
424 NVOBJ_CLASS(dev, 0x502d, GR); /* 2d */
425 NVOBJ_CLASS(dev, 0x50c0, GR); /* compute */
426 NVOBJ_CLASS(dev, 0x85c0, GR); /* compute (nva3, nva5, nva8) */
427
428 /* tesla */
429 if (dev_priv->chipset == 0x50)
430 NVOBJ_CLASS(dev, 0x5097, GR); /* tesla (nv50) */
431 else
432 if (dev_priv->chipset < 0xa0)
433 NVOBJ_CLASS(dev, 0x8297, GR); /* tesla (nv8x/nv9x) */
434 else {
435 switch (dev_priv->chipset) {
436 case 0xa0:
437 case 0xaa:
438 case 0xac:
439 NVOBJ_CLASS(dev, 0x8397, GR);
440 break;
441 case 0xa3:
442 case 0xa5:
443 case 0xa8:
444 NVOBJ_CLASS(dev, 0x8597, GR);
445 break;
446 case 0xaf:
447 NVOBJ_CLASS(dev, 0x8697, GR);
448 break;
449 }
450 }
451
452 dev_priv->engine.graph.registered = true;
453 return 0;
454}
Ben Skeggs56ac7472010-10-22 10:26:24 +1000455
456void
457nv50_graph_tlb_flush(struct drm_device *dev)
458{
459 nv50_vm_flush(dev, 0);
460}
461
462void
463nv86_graph_tlb_flush(struct drm_device *dev)
464{
465 struct drm_nouveau_private *dev_priv = dev->dev_private;
466 struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer;
467 bool idle, timeout = false;
468 unsigned long flags;
469 u64 start;
470 u32 tmp;
471
472 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
473 nv_mask(dev, 0x400500, 0x00000001, 0x00000000);
474
475 start = ptimer->read(dev);
476 do {
477 idle = true;
478
479 for (tmp = nv_rd32(dev, 0x400380); tmp && idle; tmp >>= 3) {
480 if ((tmp & 7) == 1)
481 idle = false;
482 }
483
484 for (tmp = nv_rd32(dev, 0x400384); tmp && idle; tmp >>= 3) {
485 if ((tmp & 7) == 1)
486 idle = false;
487 }
488
489 for (tmp = nv_rd32(dev, 0x400388); tmp && idle; tmp >>= 3) {
490 if ((tmp & 7) == 1)
491 idle = false;
492 }
493 } while (!idle && !(timeout = ptimer->read(dev) - start > 2000000000));
494
495 if (timeout) {
496 NV_ERROR(dev, "PGRAPH TLB flush idle timeout fail: "
497 "0x%08x 0x%08x 0x%08x 0x%08x\n",
498 nv_rd32(dev, 0x400700), nv_rd32(dev, 0x400380),
499 nv_rd32(dev, 0x400384), nv_rd32(dev, 0x400388));
500 }
501
502 nv50_vm_flush(dev, 0);
503
504 nv_mask(dev, 0x400500, 0x00000001, 0x00000001);
505 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
506}