blob: f6b3580c685aa8b7039d823da7af3449df994b33 [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 "nouveau_drv.h"
29#include "nouveau_drm.h"
Ben Skeggse05c5a32010-09-01 15:24:35 +100030#include "nouveau_ramht.h"
Ben Skeggs6ee73862009-12-11 19:24:15 +100031
Ben Skeggse05c5a32010-09-01 15:24:35 +100032#define NV40_RAMFC(c) (dev_priv->ramfc->pinst + ((c) * NV40_RAMFC__SIZE))
Ben Skeggs6ee73862009-12-11 19:24:15 +100033#define NV40_RAMFC__SIZE 128
34
35int
36nv40_fifo_create_context(struct nouveau_channel *chan)
37{
38 struct drm_device *dev = chan->dev;
39 struct drm_nouveau_private *dev_priv = dev->dev_private;
40 uint32_t fc = NV40_RAMFC(chan->id);
Maarten Maathuisff9e5272010-02-01 20:58:27 +010041 unsigned long flags;
Ben Skeggs6ee73862009-12-11 19:24:15 +100042 int ret;
43
44 ret = nouveau_gpuobj_new_fake(dev, NV40_RAMFC(chan->id), ~0,
45 NV40_RAMFC__SIZE, NVOBJ_FLAG_ZERO_ALLOC |
Ben Skeggsa8eaebc2010-09-01 15:24:31 +100046 NVOBJ_FLAG_ZERO_FREE, &chan->ramfc);
Ben Skeggs6ee73862009-12-11 19:24:15 +100047 if (ret)
48 return ret;
49
Maarten Maathuisff9e5272010-02-01 20:58:27 +010050 spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
51
Ben Skeggs6ee73862009-12-11 19:24:15 +100052 nv_wi32(dev, fc + 0, chan->pushbuf_base);
53 nv_wi32(dev, fc + 4, chan->pushbuf_base);
Ben Skeggsa8eaebc2010-09-01 15:24:31 +100054 nv_wi32(dev, fc + 12, chan->pushbuf->pinst >> 4);
Ben Skeggs6ee73862009-12-11 19:24:15 +100055 nv_wi32(dev, fc + 24, NV_PFIFO_CACHE1_DMA_FETCH_TRIG_128_BYTES |
56 NV_PFIFO_CACHE1_DMA_FETCH_SIZE_128_BYTES |
57 NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_8 |
58#ifdef __BIG_ENDIAN
59 NV_PFIFO_CACHE1_BIG_ENDIAN |
60#endif
61 0x30000000 /* no idea.. */);
Ben Skeggsa8eaebc2010-09-01 15:24:31 +100062 nv_wi32(dev, fc + 56, chan->ramin_grctx->pinst >> 4);
Ben Skeggs6ee73862009-12-11 19:24:15 +100063 nv_wi32(dev, fc + 60, 0x0001FFFF);
Ben Skeggs6ee73862009-12-11 19:24:15 +100064
65 /* enable the fifo dma operation */
66 nv_wr32(dev, NV04_PFIFO_MODE,
67 nv_rd32(dev, NV04_PFIFO_MODE) | (1 << chan->id));
Maarten Maathuisff9e5272010-02-01 20:58:27 +010068
69 spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
Ben Skeggs6ee73862009-12-11 19:24:15 +100070 return 0;
71}
72
Ben Skeggs6ee73862009-12-11 19:24:15 +100073static void
74nv40_fifo_do_load_context(struct drm_device *dev, int chid)
75{
76 struct drm_nouveau_private *dev_priv = dev->dev_private;
77 uint32_t fc = NV40_RAMFC(chid), tmp, tmp2;
78
Ben Skeggs6ee73862009-12-11 19:24:15 +100079 nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_PUT, nv_ri32(dev, fc + 0));
80 nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_GET, nv_ri32(dev, fc + 4));
81 nv_wr32(dev, NV10_PFIFO_CACHE1_REF_CNT, nv_ri32(dev, fc + 8));
82 nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_INSTANCE, nv_ri32(dev, fc + 12));
83 nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_DCOUNT, nv_ri32(dev, fc + 16));
84 nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_STATE, nv_ri32(dev, fc + 20));
85
86 /* No idea what 0x2058 is.. */
87 tmp = nv_ri32(dev, fc + 24);
88 tmp2 = nv_rd32(dev, 0x2058) & 0xFFF;
89 tmp2 |= (tmp & 0x30000000);
90 nv_wr32(dev, 0x2058, tmp2);
91 tmp &= ~0x30000000;
92 nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_FETCH, tmp);
93
94 nv_wr32(dev, NV04_PFIFO_CACHE1_ENGINE, nv_ri32(dev, fc + 28));
95 nv_wr32(dev, NV04_PFIFO_CACHE1_PULL1, nv_ri32(dev, fc + 32));
96 nv_wr32(dev, NV10_PFIFO_CACHE1_ACQUIRE_VALUE, nv_ri32(dev, fc + 36));
97 tmp = nv_ri32(dev, fc + 40);
98 nv_wr32(dev, NV10_PFIFO_CACHE1_ACQUIRE_TIMESTAMP, tmp);
99 nv_wr32(dev, NV10_PFIFO_CACHE1_ACQUIRE_TIMEOUT, nv_ri32(dev, fc + 44));
100 nv_wr32(dev, NV10_PFIFO_CACHE1_SEMAPHORE, nv_ri32(dev, fc + 48));
101 nv_wr32(dev, NV10_PFIFO_CACHE1_DMA_SUBROUTINE, nv_ri32(dev, fc + 52));
102 nv_wr32(dev, NV40_PFIFO_GRCTX_INSTANCE, nv_ri32(dev, fc + 56));
103
104 /* Don't clobber the TIMEOUT_ENABLED flag when restoring from RAMFC */
105 tmp = nv_rd32(dev, NV04_PFIFO_DMA_TIMESLICE) & ~0x1FFFF;
106 tmp |= nv_ri32(dev, fc + 60) & 0x1FFFF;
107 nv_wr32(dev, NV04_PFIFO_DMA_TIMESLICE, tmp);
108
109 nv_wr32(dev, 0x32e4, nv_ri32(dev, fc + 64));
110 /* NVIDIA does this next line twice... */
111 nv_wr32(dev, 0x32e8, nv_ri32(dev, fc + 68));
112 nv_wr32(dev, 0x2088, nv_ri32(dev, fc + 76));
113 nv_wr32(dev, 0x3300, nv_ri32(dev, fc + 80));
114
Ben Skeggs6ee73862009-12-11 19:24:15 +1000115 nv_wr32(dev, NV03_PFIFO_CACHE1_GET, 0);
116 nv_wr32(dev, NV03_PFIFO_CACHE1_PUT, 0);
117}
118
119int
120nv40_fifo_load_context(struct nouveau_channel *chan)
121{
122 struct drm_device *dev = chan->dev;
123 uint32_t tmp;
124
125 nv40_fifo_do_load_context(dev, chan->id);
126
127 /* Set channel active, and in DMA mode */
128 nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1,
129 NV40_PFIFO_CACHE1_PUSH1_DMA | chan->id);
130 nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_PUSH, 1);
131
132 /* Reset DMA_CTL_AT_INFO to INVALID */
133 tmp = nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_CTL) & ~(1 << 31);
134 nv_wr32(dev, NV04_PFIFO_CACHE1_DMA_CTL, tmp);
135
136 return 0;
137}
138
139int
140nv40_fifo_unload_context(struct drm_device *dev)
141{
142 struct drm_nouveau_private *dev_priv = dev->dev_private;
143 struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
144 uint32_t fc, tmp;
145 int chid;
146
147 chid = pfifo->channel_id(dev);
148 if (chid < 0 || chid >= dev_priv->engine.fifo.channels)
149 return 0;
150 fc = NV40_RAMFC(chid);
151
Ben Skeggs6ee73862009-12-11 19:24:15 +1000152 nv_wi32(dev, fc + 0, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_PUT));
153 nv_wi32(dev, fc + 4, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_GET));
154 nv_wi32(dev, fc + 8, nv_rd32(dev, NV10_PFIFO_CACHE1_REF_CNT));
155 nv_wi32(dev, fc + 12, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_INSTANCE));
156 nv_wi32(dev, fc + 16, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_DCOUNT));
157 nv_wi32(dev, fc + 20, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_STATE));
158 tmp = nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_FETCH);
159 tmp |= nv_rd32(dev, 0x2058) & 0x30000000;
160 nv_wi32(dev, fc + 24, tmp);
161 nv_wi32(dev, fc + 28, nv_rd32(dev, NV04_PFIFO_CACHE1_ENGINE));
162 nv_wi32(dev, fc + 32, nv_rd32(dev, NV04_PFIFO_CACHE1_PULL1));
163 nv_wi32(dev, fc + 36, nv_rd32(dev, NV10_PFIFO_CACHE1_ACQUIRE_VALUE));
164 tmp = nv_rd32(dev, NV10_PFIFO_CACHE1_ACQUIRE_TIMESTAMP);
165 nv_wi32(dev, fc + 40, tmp);
166 nv_wi32(dev, fc + 44, nv_rd32(dev, NV10_PFIFO_CACHE1_ACQUIRE_TIMEOUT));
167 nv_wi32(dev, fc + 48, nv_rd32(dev, NV10_PFIFO_CACHE1_SEMAPHORE));
168 /* NVIDIA read 0x3228 first, then write DMA_GET here.. maybe something
169 * more involved depending on the value of 0x3228?
170 */
171 nv_wi32(dev, fc + 52, nv_rd32(dev, NV04_PFIFO_CACHE1_DMA_GET));
172 nv_wi32(dev, fc + 56, nv_rd32(dev, NV40_PFIFO_GRCTX_INSTANCE));
173 nv_wi32(dev, fc + 60, nv_rd32(dev, NV04_PFIFO_DMA_TIMESLICE) & 0x1ffff);
174 /* No idea what the below is for exactly, ripped from a mmio-trace */
175 nv_wi32(dev, fc + 64, nv_rd32(dev, NV40_PFIFO_UNK32E4));
176 /* NVIDIA do this next line twice.. bug? */
177 nv_wi32(dev, fc + 68, nv_rd32(dev, 0x32e8));
178 nv_wi32(dev, fc + 76, nv_rd32(dev, 0x2088));
179 nv_wi32(dev, fc + 80, nv_rd32(dev, 0x3300));
180#if 0 /* no real idea which is PUT/GET in UNK_48.. */
181 tmp = nv_rd32(dev, NV04_PFIFO_CACHE1_GET);
182 tmp |= (nv_rd32(dev, NV04_PFIFO_CACHE1_PUT) << 16);
183 nv_wi32(dev, fc + 72, tmp);
184#endif
Ben Skeggs6ee73862009-12-11 19:24:15 +1000185
186 nv40_fifo_do_load_context(dev, pfifo->channels - 1);
187 nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1,
188 NV40_PFIFO_CACHE1_PUSH1_DMA | (pfifo->channels - 1));
189 return 0;
190}
191
192static void
193nv40_fifo_init_reset(struct drm_device *dev)
194{
195 int i;
196
197 nv_wr32(dev, NV03_PMC_ENABLE,
198 nv_rd32(dev, NV03_PMC_ENABLE) & ~NV_PMC_ENABLE_PFIFO);
199 nv_wr32(dev, NV03_PMC_ENABLE,
200 nv_rd32(dev, NV03_PMC_ENABLE) | NV_PMC_ENABLE_PFIFO);
201
202 nv_wr32(dev, 0x003224, 0x000f0078);
203 nv_wr32(dev, 0x003210, 0x00000000);
204 nv_wr32(dev, 0x003270, 0x00000000);
205 nv_wr32(dev, 0x003240, 0x00000000);
206 nv_wr32(dev, 0x003244, 0x00000000);
207 nv_wr32(dev, 0x003258, 0x00000000);
208 nv_wr32(dev, 0x002504, 0x00000000);
209 for (i = 0; i < 16; i++)
210 nv_wr32(dev, 0x002510 + (i * 4), 0x00000000);
211 nv_wr32(dev, 0x00250c, 0x0000ffff);
212 nv_wr32(dev, 0x002048, 0x00000000);
213 nv_wr32(dev, 0x003228, 0x00000000);
214 nv_wr32(dev, 0x0032e8, 0x00000000);
215 nv_wr32(dev, 0x002410, 0x00000000);
216 nv_wr32(dev, 0x002420, 0x00000000);
217 nv_wr32(dev, 0x002058, 0x00000001);
218 nv_wr32(dev, 0x00221c, 0x00000000);
219 /* something with 0x2084, read/modify/write, no change */
220 nv_wr32(dev, 0x002040, 0x000000ff);
221 nv_wr32(dev, 0x002500, 0x00000000);
222 nv_wr32(dev, 0x003200, 0x00000000);
223
224 nv_wr32(dev, NV04_PFIFO_DMA_TIMESLICE, 0x2101ffff);
225}
226
227static void
228nv40_fifo_init_ramxx(struct drm_device *dev)
229{
230 struct drm_nouveau_private *dev_priv = dev->dev_private;
231
232 nv_wr32(dev, NV03_PFIFO_RAMHT, (0x03 << 24) /* search 128 */ |
Ben Skeggse05c5a32010-09-01 15:24:35 +1000233 ((dev_priv->ramht->bits - 9) << 16) |
234 (dev_priv->ramht->gpuobj->pinst >> 8));
235 nv_wr32(dev, NV03_PFIFO_RAMRO, dev_priv->ramro->pinst >> 8);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000236
237 switch (dev_priv->chipset) {
238 case 0x47:
239 case 0x49:
240 case 0x4b:
241 nv_wr32(dev, 0x2230, 1);
242 break;
243 default:
244 break;
245 }
246
247 switch (dev_priv->chipset) {
248 case 0x40:
249 case 0x41:
250 case 0x42:
251 case 0x43:
252 case 0x45:
253 case 0x47:
254 case 0x48:
255 case 0x49:
256 case 0x4b:
257 nv_wr32(dev, NV40_PFIFO_RAMFC, 0x30002);
258 break;
259 default:
260 nv_wr32(dev, 0x2230, 0);
261 nv_wr32(dev, NV40_PFIFO_RAMFC,
Ben Skeggsa76fb4e2010-03-18 09:45:20 +1000262 ((dev_priv->vram_size - 512 * 1024 +
Ben Skeggse05c5a32010-09-01 15:24:35 +1000263 dev_priv->ramfc->pinst) >> 16) | (3 << 16));
Ben Skeggs6ee73862009-12-11 19:24:15 +1000264 break;
265 }
266}
267
268static void
269nv40_fifo_init_intr(struct drm_device *dev)
270{
Ben Skeggs5178d402010-11-03 10:56:05 +1000271 nouveau_irq_register(dev, 8, nv04_fifo_isr);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000272 nv_wr32(dev, 0x002100, 0xffffffff);
273 nv_wr32(dev, 0x002140, 0xffffffff);
274}
275
276int
277nv40_fifo_init(struct drm_device *dev)
278{
279 struct drm_nouveau_private *dev_priv = dev->dev_private;
280 struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
281 int i;
282
283 nv40_fifo_init_reset(dev);
284 nv40_fifo_init_ramxx(dev);
285
286 nv40_fifo_do_load_context(dev, pfifo->channels - 1);
287 nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1, pfifo->channels - 1);
288
289 nv40_fifo_init_intr(dev);
290 pfifo->enable(dev);
291 pfifo->reassign(dev, true);
292
293 for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
Ben Skeggscff5c132010-10-06 16:16:59 +1000294 if (dev_priv->channels.ptr[i]) {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000295 uint32_t mode = nv_rd32(dev, NV04_PFIFO_MODE);
296 nv_wr32(dev, NV04_PFIFO_MODE, mode | (1 << i));
297 }
298 }
299
300 return 0;
301}