2
* Copyright (C) 2007 Ben Skeggs.
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:
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.
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.
29
#include "nouveau_drv.h"
32
struct nouveau_gpuobj_ref *thingo;
35
#define IS_G80 ((dev_priv->chipset & 0xf0) == 0x50)
38
nv50_fifo_init_thingo(struct drm_device *dev)
40
struct drm_nouveau_private *dev_priv = dev->dev_private;
41
nv50_fifo_priv *priv = dev_priv->Engine.fifo.priv;
42
struct nouveau_gpuobj_ref *thingo = priv->thingo;
47
INSTANCE_WR(thingo->gpuobj, 0, 0x7e);
48
INSTANCE_WR(thingo->gpuobj, 1, 0x7e);
49
for (i = 1; i < 127; i++, fi) {
50
if (dev_priv->fifos[i]) {
51
INSTANCE_WR(thingo->gpuobj, fi, i);
56
NV_WRITE(0x32f4, thingo->instance >> 12);
58
NV_WRITE(0x2500, 0x101);
62
nv50_fifo_channel_enable(struct drm_device *dev, int channel, int nt)
64
struct drm_nouveau_private *dev_priv = dev->dev_private;
65
struct nouveau_channel *chan = dev_priv->fifos[channel];
68
DRM_DEBUG("ch%d\n", channel);
73
if (IS_G80) inst = chan->ramfc->instance >> 12;
74
else inst = chan->ramfc->instance >> 8;
75
NV_WRITE(NV50_PFIFO_CTX_TABLE(channel),
76
inst | NV50_PFIFO_CTX_TABLE_CHANNEL_ENABLED);
78
if (!nt) nv50_fifo_init_thingo(dev);
83
nv50_fifo_channel_disable(struct drm_device *dev, int channel, int nt)
85
struct drm_nouveau_private *dev_priv = dev->dev_private;
88
DRM_DEBUG("ch%d, nt=%d\n", channel, nt);
90
if (IS_G80) inst = NV50_PFIFO_CTX_TABLE_INSTANCE_MASK_G80;
91
else inst = NV50_PFIFO_CTX_TABLE_INSTANCE_MASK_G84;
92
NV_WRITE(NV50_PFIFO_CTX_TABLE(channel), inst);
94
if (!nt) nv50_fifo_init_thingo(dev);
98
nv50_fifo_init_reset(struct drm_device *dev)
100
struct drm_nouveau_private *dev_priv = dev->dev_private;
105
pmc_e = NV_READ(NV03_PMC_ENABLE);
106
NV_WRITE(NV03_PMC_ENABLE, pmc_e & ~NV_PMC_ENABLE_PFIFO);
107
pmc_e = NV_READ(NV03_PMC_ENABLE);
108
NV_WRITE(NV03_PMC_ENABLE, pmc_e | NV_PMC_ENABLE_PFIFO);
112
nv50_fifo_init_intr(struct drm_device *dev)
114
struct drm_nouveau_private *dev_priv = dev->dev_private;
118
NV_WRITE(NV03_PFIFO_INTR_0, 0xFFFFFFFF);
119
NV_WRITE(NV03_PFIFO_INTR_EN_0, 0xFFFFFFFF);
123
nv50_fifo_init_context_table(struct drm_device *dev)
129
for (i = 0; i < NV50_PFIFO_CTX_TABLE__SIZE; i++)
130
nv50_fifo_channel_disable(dev, i, 1);
131
nv50_fifo_init_thingo(dev);
135
nv50_fifo_init_regs__nv(struct drm_device *dev)
137
struct drm_nouveau_private *dev_priv = dev->dev_private;
141
NV_WRITE(0x250c, 0x6f3cfc34);
145
nv50_fifo_init_regs(struct drm_device *dev)
147
struct drm_nouveau_private *dev_priv = dev->dev_private;
158
/* Enable dummy channels setup by nv50_instmem.c */
159
nv50_fifo_channel_enable(dev, 0, 1);
160
nv50_fifo_channel_enable(dev, 127, 1);
166
nv50_fifo_init(struct drm_device *dev)
168
struct drm_nouveau_private *dev_priv = dev->dev_private;
169
nv50_fifo_priv *priv;
174
priv = drm_calloc(1, sizeof(*priv), DRM_MEM_DRIVER);
177
dev_priv->Engine.fifo.priv = priv;
179
nv50_fifo_init_reset(dev);
180
nv50_fifo_init_intr(dev);
182
if ((ret = nouveau_gpuobj_new_ref(dev, NULL, NULL, 0, (128+2)*4, 0x1000,
183
NVOBJ_FLAG_ZERO_ALLOC,
185
DRM_ERROR("error creating thingo: %d\n", ret);
189
nv50_fifo_init_context_table(dev);
191
nv50_fifo_init_regs__nv(dev);
192
if ((ret = nv50_fifo_init_regs(dev)))
199
nv50_fifo_takedown(struct drm_device *dev)
201
struct drm_nouveau_private *dev_priv = dev->dev_private;
202
nv50_fifo_priv *priv = dev_priv->Engine.fifo.priv;
209
nouveau_gpuobj_ref_del(dev, &priv->thingo);
211
dev_priv->Engine.fifo.priv = NULL;
212
drm_free(priv, sizeof(*priv), DRM_MEM_DRIVER);
216
nv50_fifo_create_context(struct nouveau_channel *chan)
218
struct drm_device *dev = chan->dev;
219
struct drm_nouveau_private *dev_priv = dev->dev_private;
220
struct nouveau_gpuobj *ramfc = NULL;
223
DRM_DEBUG("ch%d\n", chan->id);
226
uint32_t ramfc_offset = chan->ramin->gpuobj->im_pramin->start;
227
uint32_t vram_offset = chan->ramin->gpuobj->im_backing->start;
228
if ((ret = nouveau_gpuobj_new_fake(dev, ramfc_offset,
230
NVOBJ_FLAG_ZERO_ALLOC |
231
NVOBJ_FLAG_ZERO_FREE,
232
&ramfc, &chan->ramfc)))
235
if ((ret = nouveau_gpuobj_new_ref(dev, chan, NULL, 0, 0x100,
237
NVOBJ_FLAG_ZERO_ALLOC |
238
NVOBJ_FLAG_ZERO_FREE,
241
ramfc = chan->ramfc->gpuobj;
244
INSTANCE_WR(ramfc, 0x48/4, chan->pushbuf->instance >> 4);
245
INSTANCE_WR(ramfc, 0x80/4, (0xc << 24) | (chan->ramht->instance >> 4));
246
INSTANCE_WR(ramfc, 0x3c/4, 0x000f0078); /* fetch? */
247
INSTANCE_WR(ramfc, 0x44/4, 0x2101ffff);
248
INSTANCE_WR(ramfc, 0x60/4, 0x7fffffff);
249
INSTANCE_WR(ramfc, 0x10/4, 0x00000000);
250
INSTANCE_WR(ramfc, 0x08/4, 0x00000000);
251
INSTANCE_WR(ramfc, 0x40/4, 0x00000000);
252
INSTANCE_WR(ramfc, 0x50/4, 0x2039b2e0);
253
INSTANCE_WR(ramfc, 0x54/4, 0x000f0000);
254
INSTANCE_WR(ramfc, 0x7c/4, 0x30000001);
255
INSTANCE_WR(ramfc, 0x78/4, 0x00000000);
256
INSTANCE_WR(ramfc, 0x4c/4, chan->pushbuf_mem->size - 1);
259
INSTANCE_WR(chan->ramin->gpuobj, 0, chan->id);
260
INSTANCE_WR(chan->ramin->gpuobj, 1, chan->ramfc->instance);
262
INSTANCE_WR(ramfc, 0x88/4, 0x3d520); /* some vram addy >> 10 */
263
INSTANCE_WR(ramfc, 0x98/4, chan->ramin->instance >> 12);
266
if ((ret = nv50_fifo_channel_enable(dev, chan->id, 0))) {
267
DRM_ERROR("error enabling ch%d: %d\n", chan->id, ret);
268
nouveau_gpuobj_ref_del(dev, &chan->ramfc);
276
nv50_fifo_destroy_context(struct nouveau_channel *chan)
278
struct drm_device *dev = chan->dev;
280
DRM_DEBUG("ch%d\n", chan->id);
282
nv50_fifo_channel_disable(dev, chan->id, 0);
284
/* Dummy channel, also used on ch 127 */
286
nv50_fifo_channel_disable(dev, 127, 0);
288
nouveau_gpuobj_ref_del(dev, &chan->ramfc);
292
nv50_fifo_load_context(struct nouveau_channel *chan)
294
struct drm_device *dev = chan->dev;
295
struct drm_nouveau_private *dev_priv = dev->dev_private;
296
struct nouveau_gpuobj *ramfc = chan->ramfc->gpuobj;
298
DRM_DEBUG("ch%d\n", chan->id);
300
/*XXX: incomplete, only touches the regs that NV does */
305
NV_WRITE(0x3224, INSTANCE_RD(ramfc, 0x3c/4));
306
NV_WRITE(NV04_PFIFO_CACHE1_DMA_INSTANCE, INSTANCE_RD(ramfc, 0x48/4));
307
NV_WRITE(0x3234, INSTANCE_RD(ramfc, 0x4c/4));
309
NV_WRITE(NV03_PFIFO_RAMHT, INSTANCE_RD(ramfc, 0x80/4));
312
NV_WRITE(0x340c, INSTANCE_RD(ramfc, 0x88/4));
313
NV_WRITE(0x3410, INSTANCE_RD(ramfc, 0x98/4));
316
NV_WRITE(NV03_PFIFO_CACHE1_PUSH1, chan->id | (1<<16));
321
nv50_fifo_save_context(struct nouveau_channel *chan)
323
DRM_DEBUG("ch%d\n", chan->id);
324
DRM_ERROR("stub!\n");