blob: 7add3dfde3dff7f2c22f7713095f192a60c1924e [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"
Ben Skeggs6ee73862009-12-11 19:24:15 +100031
Ben Skeggs6ee73862009-12-11 19:24:15 +100032static void
Ben Skeggsac94a342010-07-08 15:28:48 +100033nv50_fifo_playlist_update(struct drm_device *dev)
Ben Skeggs6ee73862009-12-11 19:24:15 +100034{
35 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsac94a342010-07-08 15:28:48 +100036 struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
Ben Skeggsa8eaebc2010-09-01 15:24:31 +100037 struct nouveau_gpuobj *cur;
Ben Skeggs6ee73862009-12-11 19:24:15 +100038 int i, nr;
39
40 NV_DEBUG(dev, "\n");
41
Ben Skeggsac94a342010-07-08 15:28:48 +100042 cur = pfifo->playlist[pfifo->cur_playlist];
43 pfifo->cur_playlist = !pfifo->cur_playlist;
Ben Skeggs6ee73862009-12-11 19:24:15 +100044
45 /* We never schedule channel 0 or 127 */
Ben Skeggs6ee73862009-12-11 19:24:15 +100046 for (i = 1, nr = 0; i < 127; i++) {
Ben Skeggscff5c132010-10-06 16:16:59 +100047 if (dev_priv->channels.ptr[i] &&
48 dev_priv->channels.ptr[i]->ramfc) {
Ben Skeggsa8eaebc2010-09-01 15:24:31 +100049 nv_wo32(cur, (nr * 4), i);
Ben Skeggsb3beb162010-09-01 15:24:29 +100050 nr++;
51 }
Ben Skeggs6ee73862009-12-11 19:24:15 +100052 }
Ben Skeggsf56cb862010-07-08 11:29:10 +100053 dev_priv->engine.instmem.flush(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +100054
Ben Skeggsa8eaebc2010-09-01 15:24:31 +100055 nv_wr32(dev, 0x32f4, cur->vinst >> 12);
Ben Skeggs6ee73862009-12-11 19:24:15 +100056 nv_wr32(dev, 0x32ec, nr);
57 nv_wr32(dev, 0x2500, 0x101);
58}
59
Ben Skeggsac94a342010-07-08 15:28:48 +100060static void
61nv50_fifo_channel_enable(struct drm_device *dev, int channel)
Ben Skeggs6ee73862009-12-11 19:24:15 +100062{
63 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggscff5c132010-10-06 16:16:59 +100064 struct nouveau_channel *chan = dev_priv->channels.ptr[channel];
Ben Skeggs6ee73862009-12-11 19:24:15 +100065 uint32_t inst;
66
67 NV_DEBUG(dev, "ch%d\n", channel);
68
Ben Skeggsac94a342010-07-08 15:28:48 +100069 if (dev_priv->chipset == 0x50)
Ben Skeggsa8eaebc2010-09-01 15:24:31 +100070 inst = chan->ramfc->vinst >> 12;
Ben Skeggs6ee73862009-12-11 19:24:15 +100071 else
Ben Skeggsa8eaebc2010-09-01 15:24:31 +100072 inst = chan->ramfc->vinst >> 8;
Ben Skeggs6ee73862009-12-11 19:24:15 +100073
Ben Skeggsac94a342010-07-08 15:28:48 +100074 nv_wr32(dev, NV50_PFIFO_CTX_TABLE(channel), inst |
75 NV50_PFIFO_CTX_TABLE_CHANNEL_ENABLED);
Ben Skeggs6ee73862009-12-11 19:24:15 +100076}
77
78static void
Ben Skeggsac94a342010-07-08 15:28:48 +100079nv50_fifo_channel_disable(struct drm_device *dev, int channel)
Ben Skeggs6ee73862009-12-11 19:24:15 +100080{
81 struct drm_nouveau_private *dev_priv = dev->dev_private;
82 uint32_t inst;
83
Ben Skeggsac94a342010-07-08 15:28:48 +100084 NV_DEBUG(dev, "ch%d\n", channel);
Ben Skeggs6ee73862009-12-11 19:24:15 +100085
Ben Skeggsac94a342010-07-08 15:28:48 +100086 if (dev_priv->chipset == 0x50)
Ben Skeggs6ee73862009-12-11 19:24:15 +100087 inst = NV50_PFIFO_CTX_TABLE_INSTANCE_MASK_G80;
88 else
89 inst = NV50_PFIFO_CTX_TABLE_INSTANCE_MASK_G84;
90 nv_wr32(dev, NV50_PFIFO_CTX_TABLE(channel), inst);
Ben Skeggs6ee73862009-12-11 19:24:15 +100091}
92
93static void
94nv50_fifo_init_reset(struct drm_device *dev)
95{
96 uint32_t pmc_e = NV_PMC_ENABLE_PFIFO;
97
98 NV_DEBUG(dev, "\n");
99
100 nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) & ~pmc_e);
101 nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) | pmc_e);
102}
103
104static void
105nv50_fifo_init_intr(struct drm_device *dev)
106{
107 NV_DEBUG(dev, "\n");
108
Ben Skeggs5178d402010-11-03 10:56:05 +1000109 nouveau_irq_register(dev, 8, nv04_fifo_isr);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000110 nv_wr32(dev, NV03_PFIFO_INTR_0, 0xFFFFFFFF);
111 nv_wr32(dev, NV03_PFIFO_INTR_EN_0, 0xFFFFFFFF);
112}
113
114static void
115nv50_fifo_init_context_table(struct drm_device *dev)
116{
117 struct drm_nouveau_private *dev_priv = dev->dev_private;
118 int i;
119
120 NV_DEBUG(dev, "\n");
121
122 for (i = 0; i < NV50_PFIFO_CTX_TABLE__SIZE; i++) {
Ben Skeggscff5c132010-10-06 16:16:59 +1000123 if (dev_priv->channels.ptr[i])
Ben Skeggsac94a342010-07-08 15:28:48 +1000124 nv50_fifo_channel_enable(dev, i);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000125 else
Ben Skeggsac94a342010-07-08 15:28:48 +1000126 nv50_fifo_channel_disable(dev, i);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000127 }
128
Ben Skeggsac94a342010-07-08 15:28:48 +1000129 nv50_fifo_playlist_update(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000130}
131
132static void
133nv50_fifo_init_regs__nv(struct drm_device *dev)
134{
135 NV_DEBUG(dev, "\n");
136
137 nv_wr32(dev, 0x250c, 0x6f3cfc34);
138}
139
140static void
141nv50_fifo_init_regs(struct drm_device *dev)
142{
143 NV_DEBUG(dev, "\n");
144
145 nv_wr32(dev, 0x2500, 0);
146 nv_wr32(dev, 0x3250, 0);
147 nv_wr32(dev, 0x3220, 0);
148 nv_wr32(dev, 0x3204, 0);
149 nv_wr32(dev, 0x3210, 0);
150 nv_wr32(dev, 0x3270, 0);
151
152 /* Enable dummy channels setup by nv50_instmem.c */
Ben Skeggsac94a342010-07-08 15:28:48 +1000153 nv50_fifo_channel_enable(dev, 0);
154 nv50_fifo_channel_enable(dev, 127);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000155}
156
157int
158nv50_fifo_init(struct drm_device *dev)
159{
160 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsac94a342010-07-08 15:28:48 +1000161 struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000162 int ret;
163
164 NV_DEBUG(dev, "\n");
165
Ben Skeggsac94a342010-07-08 15:28:48 +1000166 if (pfifo->playlist[0]) {
167 pfifo->cur_playlist = !pfifo->cur_playlist;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000168 goto just_reset;
169 }
170
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000171 ret = nouveau_gpuobj_new(dev, NULL, 128*4, 0x1000,
172 NVOBJ_FLAG_ZERO_ALLOC,
173 &pfifo->playlist[0]);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000174 if (ret) {
Ben Skeggsac94a342010-07-08 15:28:48 +1000175 NV_ERROR(dev, "error creating playlist 0: %d\n", ret);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000176 return ret;
177 }
178
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000179 ret = nouveau_gpuobj_new(dev, NULL, 128*4, 0x1000,
180 NVOBJ_FLAG_ZERO_ALLOC,
181 &pfifo->playlist[1]);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000182 if (ret) {
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000183 nouveau_gpuobj_ref(NULL, &pfifo->playlist[0]);
Ben Skeggsac94a342010-07-08 15:28:48 +1000184 NV_ERROR(dev, "error creating playlist 1: %d\n", ret);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000185 return ret;
186 }
187
188just_reset:
189 nv50_fifo_init_reset(dev);
190 nv50_fifo_init_intr(dev);
191 nv50_fifo_init_context_table(dev);
192 nv50_fifo_init_regs__nv(dev);
193 nv50_fifo_init_regs(dev);
194 dev_priv->engine.fifo.enable(dev);
195 dev_priv->engine.fifo.reassign(dev, true);
196
197 return 0;
198}
199
200void
201nv50_fifo_takedown(struct drm_device *dev)
202{
203 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsac94a342010-07-08 15:28:48 +1000204 struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000205
206 NV_DEBUG(dev, "\n");
207
Ben Skeggsac94a342010-07-08 15:28:48 +1000208 if (!pfifo->playlist[0])
Ben Skeggs6ee73862009-12-11 19:24:15 +1000209 return;
210
Ben Skeggs5178d402010-11-03 10:56:05 +1000211 nv_wr32(dev, 0x2140, 0x00000000);
212 nouveau_irq_unregister(dev, 8);
213
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000214 nouveau_gpuobj_ref(NULL, &pfifo->playlist[0]);
215 nouveau_gpuobj_ref(NULL, &pfifo->playlist[1]);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000216}
217
218int
219nv50_fifo_channel_id(struct drm_device *dev)
220{
221 return nv_rd32(dev, NV03_PFIFO_CACHE1_PUSH1) &
222 NV50_PFIFO_CACHE1_PUSH1_CHID_MASK;
223}
224
225int
226nv50_fifo_create_context(struct nouveau_channel *chan)
227{
228 struct drm_device *dev = chan->dev;
229 struct drm_nouveau_private *dev_priv = dev->dev_private;
230 struct nouveau_gpuobj *ramfc = NULL;
Maarten Maathuisff9e5272010-02-01 20:58:27 +0100231 unsigned long flags;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000232 int ret;
233
234 NV_DEBUG(dev, "ch%d\n", chan->id);
235
Ben Skeggsac94a342010-07-08 15:28:48 +1000236 if (dev_priv->chipset == 0x50) {
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000237 ret = nouveau_gpuobj_new_fake(dev, chan->ramin->pinst,
238 chan->ramin->vinst, 0x100,
Ben Skeggsde3a6c02010-09-01 15:24:30 +1000239 NVOBJ_FLAG_ZERO_ALLOC |
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000240 NVOBJ_FLAG_ZERO_FREE,
Ben Skeggs6ee73862009-12-11 19:24:15 +1000241 &chan->ramfc);
242 if (ret)
243 return ret;
244
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000245 ret = nouveau_gpuobj_new_fake(dev, chan->ramin->pinst + 0x0400,
246 chan->ramin->vinst + 0x0400,
247 4096, 0, &chan->cache);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000248 if (ret)
249 return ret;
250 } else {
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000251 ret = nouveau_gpuobj_new(dev, chan, 0x100, 256,
252 NVOBJ_FLAG_ZERO_ALLOC |
253 NVOBJ_FLAG_ZERO_FREE, &chan->ramfc);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000254 if (ret)
255 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000256
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000257 ret = nouveau_gpuobj_new(dev, chan, 4096, 1024,
258 0, &chan->cache);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000259 if (ret)
260 return ret;
261 }
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000262 ramfc = chan->ramfc;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000263
Ben Skeggsd9081752010-11-22 16:05:54 +1000264 chan->user = ioremap(pci_resource_start(dev->pdev, 0) +
265 NV50_USER(chan->id), PAGE_SIZE);
266 if (!chan->user)
267 return -ENOMEM;
268
Maarten Maathuisff9e5272010-02-01 20:58:27 +0100269 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
270
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000271 nv_wo32(ramfc, 0x48, chan->pushbuf->cinst >> 4);
Ben Skeggse05c5a32010-09-01 15:24:35 +1000272 nv_wo32(ramfc, 0x80, ((chan->ramht->bits - 9) << 27) |
Ben Skeggsb3beb162010-09-01 15:24:29 +1000273 (4 << 24) /* SEARCH_FULL */ |
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000274 (chan->ramht->gpuobj->cinst >> 4));
Ben Skeggsb3beb162010-09-01 15:24:29 +1000275 nv_wo32(ramfc, 0x44, 0x2101ffff);
276 nv_wo32(ramfc, 0x60, 0x7fffffff);
277 nv_wo32(ramfc, 0x40, 0x00000000);
278 nv_wo32(ramfc, 0x7c, 0x30000001);
279 nv_wo32(ramfc, 0x78, 0x00000000);
280 nv_wo32(ramfc, 0x3c, 0x403f6078);
281 nv_wo32(ramfc, 0x50, chan->pushbuf_base + chan->dma.ib_base * 4);
282 nv_wo32(ramfc, 0x54, drm_order(chan->dma.ib_max + 1) << 16);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000283
Ben Skeggsac94a342010-07-08 15:28:48 +1000284 if (dev_priv->chipset != 0x50) {
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000285 nv_wo32(chan->ramin, 0, chan->id);
286 nv_wo32(chan->ramin, 4, chan->ramfc->vinst >> 8);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000287
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000288 nv_wo32(ramfc, 0x88, chan->cache->vinst >> 10);
289 nv_wo32(ramfc, 0x98, chan->ramin->vinst >> 12);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000290 }
291
Ben Skeggsf56cb862010-07-08 11:29:10 +1000292 dev_priv->engine.instmem.flush(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000293
Ben Skeggsac94a342010-07-08 15:28:48 +1000294 nv50_fifo_channel_enable(dev, chan->id);
295 nv50_fifo_playlist_update(dev);
Maarten Maathuisff9e5272010-02-01 20:58:27 +0100296 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000297 return 0;
298}
299
300void
301nv50_fifo_destroy_context(struct nouveau_channel *chan)
302{
303 struct drm_device *dev = chan->dev;
Francisco Jerez3945e472010-10-18 03:53:39 +0200304 struct drm_nouveau_private *dev_priv = dev->dev_private;
305 struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000306 struct nouveau_gpuobj *ramfc = NULL;
Francisco Jerez3945e472010-10-18 03:53:39 +0200307 unsigned long flags;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000308
309 NV_DEBUG(dev, "ch%d\n", chan->id);
310
Francisco Jerez3945e472010-10-18 03:53:39 +0200311 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
312 pfifo->reassign(dev, false);
313
314 /* Unload the context if it's the currently active one */
315 if (pfifo->channel_id(dev) == chan->id) {
316 pfifo->disable(dev);
317 pfifo->unload_context(dev);
318 pfifo->enable(dev);
319 }
320
Maarten Maathuisa87ff622010-02-01 18:47:52 +0100321 /* This will ensure the channel is seen as disabled. */
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000322 nouveau_gpuobj_ref(chan->ramfc, &ramfc);
323 nouveau_gpuobj_ref(NULL, &chan->ramfc);
Ben Skeggsac94a342010-07-08 15:28:48 +1000324 nv50_fifo_channel_disable(dev, chan->id);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000325
326 /* Dummy channel, also used on ch 127 */
327 if (chan->id == 0)
Ben Skeggsac94a342010-07-08 15:28:48 +1000328 nv50_fifo_channel_disable(dev, 127);
329 nv50_fifo_playlist_update(dev);
Maarten Maathuisa87ff622010-02-01 18:47:52 +0100330
Francisco Jerez3945e472010-10-18 03:53:39 +0200331 pfifo->reassign(dev, true);
332 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
333
334 /* Free the channel resources */
Ben Skeggsd9081752010-11-22 16:05:54 +1000335 if (chan->user) {
336 iounmap(chan->user);
337 chan->user = NULL;
338 }
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000339 nouveau_gpuobj_ref(NULL, &ramfc);
340 nouveau_gpuobj_ref(NULL, &chan->cache);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000341}
342
343int
344nv50_fifo_load_context(struct nouveau_channel *chan)
345{
346 struct drm_device *dev = chan->dev;
347 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000348 struct nouveau_gpuobj *ramfc = chan->ramfc;
349 struct nouveau_gpuobj *cache = chan->cache;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000350 int ptr, cnt;
351
352 NV_DEBUG(dev, "ch%d\n", chan->id);
353
Ben Skeggsb3beb162010-09-01 15:24:29 +1000354 nv_wr32(dev, 0x3330, nv_ro32(ramfc, 0x00));
355 nv_wr32(dev, 0x3334, nv_ro32(ramfc, 0x04));
356 nv_wr32(dev, 0x3240, nv_ro32(ramfc, 0x08));
357 nv_wr32(dev, 0x3320, nv_ro32(ramfc, 0x0c));
358 nv_wr32(dev, 0x3244, nv_ro32(ramfc, 0x10));
359 nv_wr32(dev, 0x3328, nv_ro32(ramfc, 0x14));
360 nv_wr32(dev, 0x3368, nv_ro32(ramfc, 0x18));
361 nv_wr32(dev, 0x336c, nv_ro32(ramfc, 0x1c));
362 nv_wr32(dev, 0x3370, nv_ro32(ramfc, 0x20));
363 nv_wr32(dev, 0x3374, nv_ro32(ramfc, 0x24));
364 nv_wr32(dev, 0x3378, nv_ro32(ramfc, 0x28));
365 nv_wr32(dev, 0x337c, nv_ro32(ramfc, 0x2c));
366 nv_wr32(dev, 0x3228, nv_ro32(ramfc, 0x30));
367 nv_wr32(dev, 0x3364, nv_ro32(ramfc, 0x34));
368 nv_wr32(dev, 0x32a0, nv_ro32(ramfc, 0x38));
369 nv_wr32(dev, 0x3224, nv_ro32(ramfc, 0x3c));
370 nv_wr32(dev, 0x324c, nv_ro32(ramfc, 0x40));
371 nv_wr32(dev, 0x2044, nv_ro32(ramfc, 0x44));
372 nv_wr32(dev, 0x322c, nv_ro32(ramfc, 0x48));
373 nv_wr32(dev, 0x3234, nv_ro32(ramfc, 0x4c));
374 nv_wr32(dev, 0x3340, nv_ro32(ramfc, 0x50));
375 nv_wr32(dev, 0x3344, nv_ro32(ramfc, 0x54));
376 nv_wr32(dev, 0x3280, nv_ro32(ramfc, 0x58));
377 nv_wr32(dev, 0x3254, nv_ro32(ramfc, 0x5c));
378 nv_wr32(dev, 0x3260, nv_ro32(ramfc, 0x60));
379 nv_wr32(dev, 0x3264, nv_ro32(ramfc, 0x64));
380 nv_wr32(dev, 0x3268, nv_ro32(ramfc, 0x68));
381 nv_wr32(dev, 0x326c, nv_ro32(ramfc, 0x6c));
382 nv_wr32(dev, 0x32e4, nv_ro32(ramfc, 0x70));
383 nv_wr32(dev, 0x3248, nv_ro32(ramfc, 0x74));
384 nv_wr32(dev, 0x2088, nv_ro32(ramfc, 0x78));
385 nv_wr32(dev, 0x2058, nv_ro32(ramfc, 0x7c));
386 nv_wr32(dev, 0x2210, nv_ro32(ramfc, 0x80));
Ben Skeggs6ee73862009-12-11 19:24:15 +1000387
Ben Skeggsb3beb162010-09-01 15:24:29 +1000388 cnt = nv_ro32(ramfc, 0x84);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000389 for (ptr = 0; ptr < cnt; ptr++) {
390 nv_wr32(dev, NV40_PFIFO_CACHE1_METHOD(ptr),
Ben Skeggsb3beb162010-09-01 15:24:29 +1000391 nv_ro32(cache, (ptr * 8) + 0));
Ben Skeggs6ee73862009-12-11 19:24:15 +1000392 nv_wr32(dev, NV40_PFIFO_CACHE1_DATA(ptr),
Ben Skeggsb3beb162010-09-01 15:24:29 +1000393 nv_ro32(cache, (ptr * 8) + 4));
Ben Skeggs6ee73862009-12-11 19:24:15 +1000394 }
Ben Skeggs7fb8ec82010-01-05 09:41:05 +1000395 nv_wr32(dev, NV03_PFIFO_CACHE1_PUT, cnt << 2);
396 nv_wr32(dev, NV03_PFIFO_CACHE1_GET, 0);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000397
398 /* guessing that all the 0x34xx regs aren't on NV50 */
Ben Skeggsac94a342010-07-08 15:28:48 +1000399 if (dev_priv->chipset != 0x50) {
Ben Skeggsb3beb162010-09-01 15:24:29 +1000400 nv_wr32(dev, 0x340c, nv_ro32(ramfc, 0x88));
401 nv_wr32(dev, 0x3400, nv_ro32(ramfc, 0x8c));
402 nv_wr32(dev, 0x3404, nv_ro32(ramfc, 0x90));
403 nv_wr32(dev, 0x3408, nv_ro32(ramfc, 0x94));
404 nv_wr32(dev, 0x3410, nv_ro32(ramfc, 0x98));
Ben Skeggs6ee73862009-12-11 19:24:15 +1000405 }
406
Ben Skeggs6ee73862009-12-11 19:24:15 +1000407 nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1, chan->id | (1<<16));
408 return 0;
409}
410
411int
412nv50_fifo_unload_context(struct drm_device *dev)
413{
414 struct drm_nouveau_private *dev_priv = dev->dev_private;
415 struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
416 struct nouveau_gpuobj *ramfc, *cache;
417 struct nouveau_channel *chan = NULL;
418 int chid, get, put, ptr;
419
420 NV_DEBUG(dev, "\n");
421
422 chid = pfifo->channel_id(dev);
Ben Skeggs3c8868d2009-12-16 14:51:13 +1000423 if (chid < 1 || chid >= dev_priv->engine.fifo.channels - 1)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000424 return 0;
425
Ben Skeggscff5c132010-10-06 16:16:59 +1000426 chan = dev_priv->channels.ptr[chid];
Ben Skeggs6ee73862009-12-11 19:24:15 +1000427 if (!chan) {
428 NV_ERROR(dev, "Inactive channel on PFIFO: %d\n", chid);
429 return -EINVAL;
430 }
431 NV_DEBUG(dev, "ch%d\n", chan->id);
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000432 ramfc = chan->ramfc;
433 cache = chan->cache;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000434
Ben Skeggsb3beb162010-09-01 15:24:29 +1000435 nv_wo32(ramfc, 0x00, nv_rd32(dev, 0x3330));
436 nv_wo32(ramfc, 0x04, nv_rd32(dev, 0x3334));
437 nv_wo32(ramfc, 0x08, nv_rd32(dev, 0x3240));
438 nv_wo32(ramfc, 0x0c, nv_rd32(dev, 0x3320));
439 nv_wo32(ramfc, 0x10, nv_rd32(dev, 0x3244));
440 nv_wo32(ramfc, 0x14, nv_rd32(dev, 0x3328));
441 nv_wo32(ramfc, 0x18, nv_rd32(dev, 0x3368));
442 nv_wo32(ramfc, 0x1c, nv_rd32(dev, 0x336c));
443 nv_wo32(ramfc, 0x20, nv_rd32(dev, 0x3370));
444 nv_wo32(ramfc, 0x24, nv_rd32(dev, 0x3374));
445 nv_wo32(ramfc, 0x28, nv_rd32(dev, 0x3378));
446 nv_wo32(ramfc, 0x2c, nv_rd32(dev, 0x337c));
447 nv_wo32(ramfc, 0x30, nv_rd32(dev, 0x3228));
448 nv_wo32(ramfc, 0x34, nv_rd32(dev, 0x3364));
449 nv_wo32(ramfc, 0x38, nv_rd32(dev, 0x32a0));
450 nv_wo32(ramfc, 0x3c, nv_rd32(dev, 0x3224));
451 nv_wo32(ramfc, 0x40, nv_rd32(dev, 0x324c));
452 nv_wo32(ramfc, 0x44, nv_rd32(dev, 0x2044));
453 nv_wo32(ramfc, 0x48, nv_rd32(dev, 0x322c));
454 nv_wo32(ramfc, 0x4c, nv_rd32(dev, 0x3234));
455 nv_wo32(ramfc, 0x50, nv_rd32(dev, 0x3340));
456 nv_wo32(ramfc, 0x54, nv_rd32(dev, 0x3344));
457 nv_wo32(ramfc, 0x58, nv_rd32(dev, 0x3280));
458 nv_wo32(ramfc, 0x5c, nv_rd32(dev, 0x3254));
459 nv_wo32(ramfc, 0x60, nv_rd32(dev, 0x3260));
460 nv_wo32(ramfc, 0x64, nv_rd32(dev, 0x3264));
461 nv_wo32(ramfc, 0x68, nv_rd32(dev, 0x3268));
462 nv_wo32(ramfc, 0x6c, nv_rd32(dev, 0x326c));
463 nv_wo32(ramfc, 0x70, nv_rd32(dev, 0x32e4));
464 nv_wo32(ramfc, 0x74, nv_rd32(dev, 0x3248));
465 nv_wo32(ramfc, 0x78, nv_rd32(dev, 0x2088));
466 nv_wo32(ramfc, 0x7c, nv_rd32(dev, 0x2058));
467 nv_wo32(ramfc, 0x80, nv_rd32(dev, 0x2210));
Ben Skeggs6ee73862009-12-11 19:24:15 +1000468
469 put = (nv_rd32(dev, NV03_PFIFO_CACHE1_PUT) & 0x7ff) >> 2;
470 get = (nv_rd32(dev, NV03_PFIFO_CACHE1_GET) & 0x7ff) >> 2;
471 ptr = 0;
472 while (put != get) {
Ben Skeggsb3beb162010-09-01 15:24:29 +1000473 nv_wo32(cache, ptr + 0,
474 nv_rd32(dev, NV40_PFIFO_CACHE1_METHOD(get)));
475 nv_wo32(cache, ptr + 4,
476 nv_rd32(dev, NV40_PFIFO_CACHE1_DATA(get)));
Ben Skeggs6ee73862009-12-11 19:24:15 +1000477 get = (get + 1) & 0x1ff;
Ben Skeggsb3beb162010-09-01 15:24:29 +1000478 ptr += 8;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000479 }
480
481 /* guessing that all the 0x34xx regs aren't on NV50 */
Ben Skeggsac94a342010-07-08 15:28:48 +1000482 if (dev_priv->chipset != 0x50) {
Ben Skeggsb3beb162010-09-01 15:24:29 +1000483 nv_wo32(ramfc, 0x84, ptr >> 3);
484 nv_wo32(ramfc, 0x88, nv_rd32(dev, 0x340c));
485 nv_wo32(ramfc, 0x8c, nv_rd32(dev, 0x3400));
486 nv_wo32(ramfc, 0x90, nv_rd32(dev, 0x3404));
487 nv_wo32(ramfc, 0x94, nv_rd32(dev, 0x3408));
488 nv_wo32(ramfc, 0x98, nv_rd32(dev, 0x3410));
Ben Skeggs6ee73862009-12-11 19:24:15 +1000489 }
490
Ben Skeggsf56cb862010-07-08 11:29:10 +1000491 dev_priv->engine.instmem.flush(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000492
493 /*XXX: probably reload ch127 (NULL) state back too */
494 nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1, 127);
495 return 0;
496}
497
Ben Skeggs56ac7472010-10-22 10:26:24 +1000498void
499nv50_fifo_tlb_flush(struct drm_device *dev)
500{
501 nv50_vm_flush(dev, 5);
502}