blob: f041b197dd779053199a7c6a3a51e416e57a6d64 [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 Skeggsa11c3192010-08-27 10:00:25 +100031#include "nouveau_vm.h"
Ben Skeggs6ee73862009-12-11 19:24:15 +100032
Ben Skeggs6ee73862009-12-11 19:24:15 +100033static void
Ben Skeggsac94a342010-07-08 15:28:48 +100034nv50_fifo_playlist_update(struct drm_device *dev)
Ben Skeggs6ee73862009-12-11 19:24:15 +100035{
36 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsac94a342010-07-08 15:28:48 +100037 struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
Ben Skeggsa8eaebc2010-09-01 15:24:31 +100038 struct nouveau_gpuobj *cur;
Ben Skeggs694931d2012-05-01 13:59:31 +100039 int i, p;
Ben Skeggs6ee73862009-12-11 19:24:15 +100040
41 NV_DEBUG(dev, "\n");
42
Ben Skeggsac94a342010-07-08 15:28:48 +100043 cur = pfifo->playlist[pfifo->cur_playlist];
44 pfifo->cur_playlist = !pfifo->cur_playlist;
Ben Skeggs6ee73862009-12-11 19:24:15 +100045
Ben Skeggs694931d2012-05-01 13:59:31 +100046 for (i = 0, p = 0; i < pfifo->channels; i++) {
47 if (nv_rd32(dev, 0x002600 + (i * 4)) & 0x80000000)
48 nv_wo32(cur, p++ * 4, i);
Ben Skeggs6ee73862009-12-11 19:24:15 +100049 }
Ben Skeggs694931d2012-05-01 13:59:31 +100050
Ben Skeggsf56cb862010-07-08 11:29:10 +100051 dev_priv->engine.instmem.flush(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +100052
Ben Skeggsa8eaebc2010-09-01 15:24:31 +100053 nv_wr32(dev, 0x32f4, cur->vinst >> 12);
Ben Skeggs694931d2012-05-01 13:59:31 +100054 nv_wr32(dev, 0x32ec, p);
Ben Skeggs6ee73862009-12-11 19:24:15 +100055 nv_wr32(dev, 0x2500, 0x101);
56}
57
Ben Skeggsac94a342010-07-08 15:28:48 +100058static void
59nv50_fifo_channel_enable(struct drm_device *dev, int channel)
Ben Skeggs6ee73862009-12-11 19:24:15 +100060{
61 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggscff5c132010-10-06 16:16:59 +100062 struct nouveau_channel *chan = dev_priv->channels.ptr[channel];
Ben Skeggs6ee73862009-12-11 19:24:15 +100063 uint32_t inst;
64
65 NV_DEBUG(dev, "ch%d\n", channel);
66
Ben Skeggsac94a342010-07-08 15:28:48 +100067 if (dev_priv->chipset == 0x50)
Ben Skeggsa8eaebc2010-09-01 15:24:31 +100068 inst = chan->ramfc->vinst >> 12;
Ben Skeggs6ee73862009-12-11 19:24:15 +100069 else
Ben Skeggsa8eaebc2010-09-01 15:24:31 +100070 inst = chan->ramfc->vinst >> 8;
Ben Skeggs6ee73862009-12-11 19:24:15 +100071
Ben Skeggsac94a342010-07-08 15:28:48 +100072 nv_wr32(dev, NV50_PFIFO_CTX_TABLE(channel), inst |
73 NV50_PFIFO_CTX_TABLE_CHANNEL_ENABLED);
Ben Skeggs6ee73862009-12-11 19:24:15 +100074}
75
76static void
Ben Skeggsac94a342010-07-08 15:28:48 +100077nv50_fifo_channel_disable(struct drm_device *dev, int channel)
Ben Skeggs6ee73862009-12-11 19:24:15 +100078{
79 struct drm_nouveau_private *dev_priv = dev->dev_private;
80 uint32_t inst;
81
Ben Skeggsac94a342010-07-08 15:28:48 +100082 NV_DEBUG(dev, "ch%d\n", channel);
Ben Skeggs6ee73862009-12-11 19:24:15 +100083
Ben Skeggsac94a342010-07-08 15:28:48 +100084 if (dev_priv->chipset == 0x50)
Ben Skeggs6ee73862009-12-11 19:24:15 +100085 inst = NV50_PFIFO_CTX_TABLE_INSTANCE_MASK_G80;
86 else
87 inst = NV50_PFIFO_CTX_TABLE_INSTANCE_MASK_G84;
88 nv_wr32(dev, NV50_PFIFO_CTX_TABLE(channel), inst);
Ben Skeggs6ee73862009-12-11 19:24:15 +100089}
90
91static void
92nv50_fifo_init_reset(struct drm_device *dev)
93{
94 uint32_t pmc_e = NV_PMC_ENABLE_PFIFO;
95
96 NV_DEBUG(dev, "\n");
97
98 nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) & ~pmc_e);
99 nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) | pmc_e);
100}
101
102static void
103nv50_fifo_init_intr(struct drm_device *dev)
104{
105 NV_DEBUG(dev, "\n");
106
Ben Skeggs5178d402010-11-03 10:56:05 +1000107 nouveau_irq_register(dev, 8, nv04_fifo_isr);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000108 nv_wr32(dev, NV03_PFIFO_INTR_0, 0xFFFFFFFF);
109 nv_wr32(dev, NV03_PFIFO_INTR_EN_0, 0xFFFFFFFF);
110}
111
112static void
113nv50_fifo_init_context_table(struct drm_device *dev)
114{
115 struct drm_nouveau_private *dev_priv = dev->dev_private;
116 int i;
117
118 NV_DEBUG(dev, "\n");
119
120 for (i = 0; i < NV50_PFIFO_CTX_TABLE__SIZE; i++) {
Ben Skeggscff5c132010-10-06 16:16:59 +1000121 if (dev_priv->channels.ptr[i])
Ben Skeggsac94a342010-07-08 15:28:48 +1000122 nv50_fifo_channel_enable(dev, i);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000123 else
Ben Skeggsac94a342010-07-08 15:28:48 +1000124 nv50_fifo_channel_disable(dev, i);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000125 }
126
Ben Skeggsac94a342010-07-08 15:28:48 +1000127 nv50_fifo_playlist_update(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000128}
129
130static void
131nv50_fifo_init_regs__nv(struct drm_device *dev)
132{
133 NV_DEBUG(dev, "\n");
134
135 nv_wr32(dev, 0x250c, 0x6f3cfc34);
136}
137
138static void
139nv50_fifo_init_regs(struct drm_device *dev)
140{
141 NV_DEBUG(dev, "\n");
142
143 nv_wr32(dev, 0x2500, 0);
144 nv_wr32(dev, 0x3250, 0);
145 nv_wr32(dev, 0x3220, 0);
146 nv_wr32(dev, 0x3204, 0);
147 nv_wr32(dev, 0x3210, 0);
148 nv_wr32(dev, 0x3270, 0);
Ben Skeggsec238022011-02-02 14:57:05 +1000149 nv_wr32(dev, 0x2044, 0x01003fff);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000150
151 /* Enable dummy channels setup by nv50_instmem.c */
Ben Skeggsac94a342010-07-08 15:28:48 +1000152 nv50_fifo_channel_enable(dev, 0);
153 nv50_fifo_channel_enable(dev, 127);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000154}
155
156int
157nv50_fifo_init(struct drm_device *dev)
158{
159 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsac94a342010-07-08 15:28:48 +1000160 struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000161 int ret;
162
163 NV_DEBUG(dev, "\n");
164
Ben Skeggsac94a342010-07-08 15:28:48 +1000165 if (pfifo->playlist[0]) {
166 pfifo->cur_playlist = !pfifo->cur_playlist;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000167 goto just_reset;
168 }
169
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000170 ret = nouveau_gpuobj_new(dev, NULL, 128*4, 0x1000,
171 NVOBJ_FLAG_ZERO_ALLOC,
172 &pfifo->playlist[0]);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000173 if (ret) {
Ben Skeggsac94a342010-07-08 15:28:48 +1000174 NV_ERROR(dev, "error creating playlist 0: %d\n", ret);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000175 return ret;
176 }
177
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000178 ret = nouveau_gpuobj_new(dev, NULL, 128*4, 0x1000,
179 NVOBJ_FLAG_ZERO_ALLOC,
180 &pfifo->playlist[1]);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000181 if (ret) {
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000182 nouveau_gpuobj_ref(NULL, &pfifo->playlist[0]);
Ben Skeggsac94a342010-07-08 15:28:48 +1000183 NV_ERROR(dev, "error creating playlist 1: %d\n", ret);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000184 return ret;
185 }
186
187just_reset:
188 nv50_fifo_init_reset(dev);
189 nv50_fifo_init_intr(dev);
190 nv50_fifo_init_context_table(dev);
191 nv50_fifo_init_regs__nv(dev);
192 nv50_fifo_init_regs(dev);
Ben Skeggs67b342e2012-05-01 10:14:07 +1000193 nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH0, 1);
194 nv_wr32(dev, NV04_PFIFO_CACHE1_PULL0, 1);
195 nv_wr32(dev, NV03_PFIFO_CACHES, 1);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000196
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
Ben Skeggs6ee73862009-12-11 19:24:15 +1000219nv50_fifo_create_context(struct nouveau_channel *chan)
220{
221 struct drm_device *dev = chan->dev;
222 struct drm_nouveau_private *dev_priv = dev->dev_private;
223 struct nouveau_gpuobj *ramfc = NULL;
Francisco Jerez4e03b4a2011-11-19 11:57:52 +0100224 uint64_t ib_offset = chan->pushbuf_base + chan->dma.ib_base * 4;
Maarten Maathuisff9e5272010-02-01 20:58:27 +0100225 unsigned long flags;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000226 int ret;
227
228 NV_DEBUG(dev, "ch%d\n", chan->id);
229
Ben Skeggsac94a342010-07-08 15:28:48 +1000230 if (dev_priv->chipset == 0x50) {
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000231 ret = nouveau_gpuobj_new_fake(dev, chan->ramin->pinst,
232 chan->ramin->vinst, 0x100,
Ben Skeggsde3a6c02010-09-01 15:24:30 +1000233 NVOBJ_FLAG_ZERO_ALLOC |
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000234 NVOBJ_FLAG_ZERO_FREE,
Ben Skeggs6ee73862009-12-11 19:24:15 +1000235 &chan->ramfc);
236 if (ret)
237 return ret;
238
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000239 ret = nouveau_gpuobj_new_fake(dev, chan->ramin->pinst + 0x0400,
240 chan->ramin->vinst + 0x0400,
241 4096, 0, &chan->cache);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000242 if (ret)
243 return ret;
244 } else {
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000245 ret = nouveau_gpuobj_new(dev, chan, 0x100, 256,
246 NVOBJ_FLAG_ZERO_ALLOC |
247 NVOBJ_FLAG_ZERO_FREE, &chan->ramfc);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000248 if (ret)
249 return ret;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000250
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000251 ret = nouveau_gpuobj_new(dev, chan, 4096, 1024,
252 0, &chan->cache);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000253 if (ret)
254 return ret;
255 }
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000256 ramfc = chan->ramfc;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000257
Ben Skeggsd9081752010-11-22 16:05:54 +1000258 chan->user = ioremap(pci_resource_start(dev->pdev, 0) +
259 NV50_USER(chan->id), PAGE_SIZE);
260 if (!chan->user)
261 return -ENOMEM;
262
Maarten Maathuisff9e5272010-02-01 20:58:27 +0100263 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
264
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000265 nv_wo32(ramfc, 0x48, chan->pushbuf->cinst >> 4);
Ben Skeggse05c5a32010-09-01 15:24:35 +1000266 nv_wo32(ramfc, 0x80, ((chan->ramht->bits - 9) << 27) |
Ben Skeggsb3beb162010-09-01 15:24:29 +1000267 (4 << 24) /* SEARCH_FULL */ |
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000268 (chan->ramht->gpuobj->cinst >> 4));
Ben Skeggsec238022011-02-02 14:57:05 +1000269 nv_wo32(ramfc, 0x44, 0x01003fff);
Ben Skeggsb3beb162010-09-01 15:24:29 +1000270 nv_wo32(ramfc, 0x60, 0x7fffffff);
271 nv_wo32(ramfc, 0x40, 0x00000000);
272 nv_wo32(ramfc, 0x7c, 0x30000001);
273 nv_wo32(ramfc, 0x78, 0x00000000);
274 nv_wo32(ramfc, 0x3c, 0x403f6078);
Francisco Jerez4e03b4a2011-11-19 11:57:52 +0100275 nv_wo32(ramfc, 0x50, lower_32_bits(ib_offset));
276 nv_wo32(ramfc, 0x54, upper_32_bits(ib_offset) |
277 drm_order(chan->dma.ib_max + 1) << 16);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000278
Ben Skeggsac94a342010-07-08 15:28:48 +1000279 if (dev_priv->chipset != 0x50) {
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000280 nv_wo32(chan->ramin, 0, chan->id);
281 nv_wo32(chan->ramin, 4, chan->ramfc->vinst >> 8);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000282
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000283 nv_wo32(ramfc, 0x88, chan->cache->vinst >> 10);
284 nv_wo32(ramfc, 0x98, chan->ramin->vinst >> 12);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000285 }
286
Ben Skeggsf56cb862010-07-08 11:29:10 +1000287 dev_priv->engine.instmem.flush(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000288
Ben Skeggsac94a342010-07-08 15:28:48 +1000289 nv50_fifo_channel_enable(dev, chan->id);
290 nv50_fifo_playlist_update(dev);
Maarten Maathuisff9e5272010-02-01 20:58:27 +0100291 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000292 return 0;
293}
294
295void
296nv50_fifo_destroy_context(struct nouveau_channel *chan)
297{
298 struct drm_device *dev = chan->dev;
Francisco Jerez3945e472010-10-18 03:53:39 +0200299 struct drm_nouveau_private *dev_priv = dev->dev_private;
300 struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
Francisco Jerez3945e472010-10-18 03:53:39 +0200301 unsigned long flags;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000302
303 NV_DEBUG(dev, "ch%d\n", chan->id);
304
Francisco Jerez3945e472010-10-18 03:53:39 +0200305 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
Ben Skeggs67b342e2012-05-01 10:14:07 +1000306 nv_wr32(dev, NV03_PFIFO_CACHES, 0);
Francisco Jerez3945e472010-10-18 03:53:39 +0200307
308 /* Unload the context if it's the currently active one */
Ben Skeggs67b342e2012-05-01 10:14:07 +1000309 if ((nv_rd32(dev, NV03_PFIFO_CACHE1_PUSH1) & 0x7f) == chan->id) {
310 nv_mask(dev, NV04_PFIFO_CACHE1_DMA_PUSH, 0x00000001, 0);
311 nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH0, 0);
312 nv_mask(dev, NV04_PFIFO_CACHE1_PULL0, 0x00000001, 0);
Francisco Jerez3945e472010-10-18 03:53:39 +0200313 pfifo->unload_context(dev);
Ben Skeggs67b342e2012-05-01 10:14:07 +1000314 nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH0, 1);
315 nv_wr32(dev, NV04_PFIFO_CACHE1_PULL0, 1);
Francisco Jerez3945e472010-10-18 03:53:39 +0200316 }
317
Ben Skeggsac94a342010-07-08 15:28:48 +1000318 nv50_fifo_channel_disable(dev, chan->id);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000319
320 /* Dummy channel, also used on ch 127 */
321 if (chan->id == 0)
Ben Skeggsac94a342010-07-08 15:28:48 +1000322 nv50_fifo_channel_disable(dev, 127);
323 nv50_fifo_playlist_update(dev);
Maarten Maathuisa87ff622010-02-01 18:47:52 +0100324
Ben Skeggs67b342e2012-05-01 10:14:07 +1000325 nv_wr32(dev, NV03_PFIFO_CACHES, 1);
Francisco Jerez3945e472010-10-18 03:53:39 +0200326 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
327
328 /* Free the channel resources */
Ben Skeggsd9081752010-11-22 16:05:54 +1000329 if (chan->user) {
330 iounmap(chan->user);
331 chan->user = NULL;
332 }
Ben Skeggs694931d2012-05-01 13:59:31 +1000333 nouveau_gpuobj_ref(NULL, &chan->ramfc);
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000334 nouveau_gpuobj_ref(NULL, &chan->cache);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000335}
336
337int
338nv50_fifo_load_context(struct nouveau_channel *chan)
339{
340 struct drm_device *dev = chan->dev;
341 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000342 struct nouveau_gpuobj *ramfc = chan->ramfc;
343 struct nouveau_gpuobj *cache = chan->cache;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000344 int ptr, cnt;
345
346 NV_DEBUG(dev, "ch%d\n", chan->id);
347
Ben Skeggsb3beb162010-09-01 15:24:29 +1000348 nv_wr32(dev, 0x3330, nv_ro32(ramfc, 0x00));
349 nv_wr32(dev, 0x3334, nv_ro32(ramfc, 0x04));
350 nv_wr32(dev, 0x3240, nv_ro32(ramfc, 0x08));
351 nv_wr32(dev, 0x3320, nv_ro32(ramfc, 0x0c));
352 nv_wr32(dev, 0x3244, nv_ro32(ramfc, 0x10));
353 nv_wr32(dev, 0x3328, nv_ro32(ramfc, 0x14));
354 nv_wr32(dev, 0x3368, nv_ro32(ramfc, 0x18));
355 nv_wr32(dev, 0x336c, nv_ro32(ramfc, 0x1c));
356 nv_wr32(dev, 0x3370, nv_ro32(ramfc, 0x20));
357 nv_wr32(dev, 0x3374, nv_ro32(ramfc, 0x24));
358 nv_wr32(dev, 0x3378, nv_ro32(ramfc, 0x28));
359 nv_wr32(dev, 0x337c, nv_ro32(ramfc, 0x2c));
360 nv_wr32(dev, 0x3228, nv_ro32(ramfc, 0x30));
361 nv_wr32(dev, 0x3364, nv_ro32(ramfc, 0x34));
362 nv_wr32(dev, 0x32a0, nv_ro32(ramfc, 0x38));
363 nv_wr32(dev, 0x3224, nv_ro32(ramfc, 0x3c));
364 nv_wr32(dev, 0x324c, nv_ro32(ramfc, 0x40));
365 nv_wr32(dev, 0x2044, nv_ro32(ramfc, 0x44));
366 nv_wr32(dev, 0x322c, nv_ro32(ramfc, 0x48));
367 nv_wr32(dev, 0x3234, nv_ro32(ramfc, 0x4c));
368 nv_wr32(dev, 0x3340, nv_ro32(ramfc, 0x50));
369 nv_wr32(dev, 0x3344, nv_ro32(ramfc, 0x54));
370 nv_wr32(dev, 0x3280, nv_ro32(ramfc, 0x58));
371 nv_wr32(dev, 0x3254, nv_ro32(ramfc, 0x5c));
372 nv_wr32(dev, 0x3260, nv_ro32(ramfc, 0x60));
373 nv_wr32(dev, 0x3264, nv_ro32(ramfc, 0x64));
374 nv_wr32(dev, 0x3268, nv_ro32(ramfc, 0x68));
375 nv_wr32(dev, 0x326c, nv_ro32(ramfc, 0x6c));
376 nv_wr32(dev, 0x32e4, nv_ro32(ramfc, 0x70));
377 nv_wr32(dev, 0x3248, nv_ro32(ramfc, 0x74));
378 nv_wr32(dev, 0x2088, nv_ro32(ramfc, 0x78));
379 nv_wr32(dev, 0x2058, nv_ro32(ramfc, 0x7c));
380 nv_wr32(dev, 0x2210, nv_ro32(ramfc, 0x80));
Ben Skeggs6ee73862009-12-11 19:24:15 +1000381
Ben Skeggsb3beb162010-09-01 15:24:29 +1000382 cnt = nv_ro32(ramfc, 0x84);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000383 for (ptr = 0; ptr < cnt; ptr++) {
384 nv_wr32(dev, NV40_PFIFO_CACHE1_METHOD(ptr),
Ben Skeggsb3beb162010-09-01 15:24:29 +1000385 nv_ro32(cache, (ptr * 8) + 0));
Ben Skeggs6ee73862009-12-11 19:24:15 +1000386 nv_wr32(dev, NV40_PFIFO_CACHE1_DATA(ptr),
Ben Skeggsb3beb162010-09-01 15:24:29 +1000387 nv_ro32(cache, (ptr * 8) + 4));
Ben Skeggs6ee73862009-12-11 19:24:15 +1000388 }
Ben Skeggs7fb8ec82010-01-05 09:41:05 +1000389 nv_wr32(dev, NV03_PFIFO_CACHE1_PUT, cnt << 2);
390 nv_wr32(dev, NV03_PFIFO_CACHE1_GET, 0);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000391
392 /* guessing that all the 0x34xx regs aren't on NV50 */
Ben Skeggsac94a342010-07-08 15:28:48 +1000393 if (dev_priv->chipset != 0x50) {
Ben Skeggsb3beb162010-09-01 15:24:29 +1000394 nv_wr32(dev, 0x340c, nv_ro32(ramfc, 0x88));
395 nv_wr32(dev, 0x3400, nv_ro32(ramfc, 0x8c));
396 nv_wr32(dev, 0x3404, nv_ro32(ramfc, 0x90));
397 nv_wr32(dev, 0x3408, nv_ro32(ramfc, 0x94));
398 nv_wr32(dev, 0x3410, nv_ro32(ramfc, 0x98));
Ben Skeggs6ee73862009-12-11 19:24:15 +1000399 }
400
Ben Skeggs6ee73862009-12-11 19:24:15 +1000401 nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1, chan->id | (1<<16));
402 return 0;
403}
404
405int
406nv50_fifo_unload_context(struct drm_device *dev)
407{
408 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000409 struct nouveau_gpuobj *ramfc, *cache;
410 struct nouveau_channel *chan = NULL;
411 int chid, get, put, ptr;
412
413 NV_DEBUG(dev, "\n");
414
Ben Skeggs67b342e2012-05-01 10:14:07 +1000415 chid = nv_rd32(dev, NV03_PFIFO_CACHE1_PUSH1) & 0x7f;
Ben Skeggs3c8868d2009-12-16 14:51:13 +1000416 if (chid < 1 || chid >= dev_priv->engine.fifo.channels - 1)
Ben Skeggs6ee73862009-12-11 19:24:15 +1000417 return 0;
418
Ben Skeggscff5c132010-10-06 16:16:59 +1000419 chan = dev_priv->channels.ptr[chid];
Ben Skeggs6ee73862009-12-11 19:24:15 +1000420 if (!chan) {
421 NV_ERROR(dev, "Inactive channel on PFIFO: %d\n", chid);
422 return -EINVAL;
423 }
424 NV_DEBUG(dev, "ch%d\n", chan->id);
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000425 ramfc = chan->ramfc;
426 cache = chan->cache;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000427
Ben Skeggsb3beb162010-09-01 15:24:29 +1000428 nv_wo32(ramfc, 0x00, nv_rd32(dev, 0x3330));
429 nv_wo32(ramfc, 0x04, nv_rd32(dev, 0x3334));
430 nv_wo32(ramfc, 0x08, nv_rd32(dev, 0x3240));
431 nv_wo32(ramfc, 0x0c, nv_rd32(dev, 0x3320));
432 nv_wo32(ramfc, 0x10, nv_rd32(dev, 0x3244));
433 nv_wo32(ramfc, 0x14, nv_rd32(dev, 0x3328));
434 nv_wo32(ramfc, 0x18, nv_rd32(dev, 0x3368));
435 nv_wo32(ramfc, 0x1c, nv_rd32(dev, 0x336c));
436 nv_wo32(ramfc, 0x20, nv_rd32(dev, 0x3370));
437 nv_wo32(ramfc, 0x24, nv_rd32(dev, 0x3374));
438 nv_wo32(ramfc, 0x28, nv_rd32(dev, 0x3378));
439 nv_wo32(ramfc, 0x2c, nv_rd32(dev, 0x337c));
440 nv_wo32(ramfc, 0x30, nv_rd32(dev, 0x3228));
441 nv_wo32(ramfc, 0x34, nv_rd32(dev, 0x3364));
442 nv_wo32(ramfc, 0x38, nv_rd32(dev, 0x32a0));
443 nv_wo32(ramfc, 0x3c, nv_rd32(dev, 0x3224));
444 nv_wo32(ramfc, 0x40, nv_rd32(dev, 0x324c));
445 nv_wo32(ramfc, 0x44, nv_rd32(dev, 0x2044));
446 nv_wo32(ramfc, 0x48, nv_rd32(dev, 0x322c));
447 nv_wo32(ramfc, 0x4c, nv_rd32(dev, 0x3234));
448 nv_wo32(ramfc, 0x50, nv_rd32(dev, 0x3340));
449 nv_wo32(ramfc, 0x54, nv_rd32(dev, 0x3344));
450 nv_wo32(ramfc, 0x58, nv_rd32(dev, 0x3280));
451 nv_wo32(ramfc, 0x5c, nv_rd32(dev, 0x3254));
452 nv_wo32(ramfc, 0x60, nv_rd32(dev, 0x3260));
453 nv_wo32(ramfc, 0x64, nv_rd32(dev, 0x3264));
454 nv_wo32(ramfc, 0x68, nv_rd32(dev, 0x3268));
455 nv_wo32(ramfc, 0x6c, nv_rd32(dev, 0x326c));
456 nv_wo32(ramfc, 0x70, nv_rd32(dev, 0x32e4));
457 nv_wo32(ramfc, 0x74, nv_rd32(dev, 0x3248));
458 nv_wo32(ramfc, 0x78, nv_rd32(dev, 0x2088));
459 nv_wo32(ramfc, 0x7c, nv_rd32(dev, 0x2058));
460 nv_wo32(ramfc, 0x80, nv_rd32(dev, 0x2210));
Ben Skeggs6ee73862009-12-11 19:24:15 +1000461
462 put = (nv_rd32(dev, NV03_PFIFO_CACHE1_PUT) & 0x7ff) >> 2;
463 get = (nv_rd32(dev, NV03_PFIFO_CACHE1_GET) & 0x7ff) >> 2;
464 ptr = 0;
465 while (put != get) {
Ben Skeggsb3beb162010-09-01 15:24:29 +1000466 nv_wo32(cache, ptr + 0,
467 nv_rd32(dev, NV40_PFIFO_CACHE1_METHOD(get)));
468 nv_wo32(cache, ptr + 4,
469 nv_rd32(dev, NV40_PFIFO_CACHE1_DATA(get)));
Ben Skeggs6ee73862009-12-11 19:24:15 +1000470 get = (get + 1) & 0x1ff;
Ben Skeggsb3beb162010-09-01 15:24:29 +1000471 ptr += 8;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000472 }
473
474 /* guessing that all the 0x34xx regs aren't on NV50 */
Ben Skeggsac94a342010-07-08 15:28:48 +1000475 if (dev_priv->chipset != 0x50) {
Ben Skeggsb3beb162010-09-01 15:24:29 +1000476 nv_wo32(ramfc, 0x84, ptr >> 3);
477 nv_wo32(ramfc, 0x88, nv_rd32(dev, 0x340c));
478 nv_wo32(ramfc, 0x8c, nv_rd32(dev, 0x3400));
479 nv_wo32(ramfc, 0x90, nv_rd32(dev, 0x3404));
480 nv_wo32(ramfc, 0x94, nv_rd32(dev, 0x3408));
481 nv_wo32(ramfc, 0x98, nv_rd32(dev, 0x3410));
Ben Skeggs6ee73862009-12-11 19:24:15 +1000482 }
483
Ben Skeggsf56cb862010-07-08 11:29:10 +1000484 dev_priv->engine.instmem.flush(dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000485
486 /*XXX: probably reload ch127 (NULL) state back too */
487 nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1, 127);
488 return 0;
489}
490
Ben Skeggs56ac7472010-10-22 10:26:24 +1000491void
492nv50_fifo_tlb_flush(struct drm_device *dev)
493{
Ben Skeggsa11c3192010-08-27 10:00:25 +1000494 nv50_vm_flush_engine(dev, 5);
Ben Skeggs56ac7472010-10-22 10:26:24 +1000495}