2007-06-24 04:49:19 -06:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 Ben Skeggs.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "drmP.h"
|
|
|
|
#include "drm.h"
|
|
|
|
#include "nouveau_drv.h"
|
2008-10-27 18:38:30 -06:00
|
|
|
#include "nv50_grctx.h"
|
2007-06-24 04:49:19 -06:00
|
|
|
|
2007-07-04 08:12:33 -06:00
|
|
|
#define IS_G80 ((dev_priv->chipset & 0xf0) == 0x50)
|
|
|
|
|
2007-06-24 04:49:19 -06:00
|
|
|
static void
|
2007-07-12 23:09:31 -06:00
|
|
|
nv50_graph_init_reset(struct drm_device *dev)
|
2007-06-24 04:49:19 -06:00
|
|
|
{
|
2007-07-12 23:09:31 -06:00
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
2008-01-06 22:52:47 -07:00
|
|
|
uint32_t pmc_e = NV_PMC_ENABLE_PGRAPH | (1 << 21);
|
2007-06-24 04:49:19 -06:00
|
|
|
|
2007-07-04 08:12:33 -06:00
|
|
|
DRM_DEBUG("\n");
|
|
|
|
|
2008-01-06 22:52:47 -07:00
|
|
|
NV_WRITE(NV03_PMC_ENABLE, NV_READ(NV03_PMC_ENABLE) & ~pmc_e);
|
|
|
|
NV_WRITE(NV03_PMC_ENABLE, NV_READ(NV03_PMC_ENABLE) | pmc_e);
|
2007-06-24 04:49:19 -06:00
|
|
|
}
|
|
|
|
|
2007-08-07 18:42:12 -06:00
|
|
|
static void
|
|
|
|
nv50_graph_init_intr(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
|
|
|
|
|
|
|
DRM_DEBUG("\n");
|
|
|
|
NV_WRITE(NV03_PGRAPH_INTR, 0xffffffff);
|
2008-01-07 00:56:44 -07:00
|
|
|
NV_WRITE(0x400138, 0xffffffff);
|
2007-08-07 18:42:12 -06:00
|
|
|
NV_WRITE(NV40_PGRAPH_INTR_EN, 0xffffffff);
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:12:33 -06:00
|
|
|
static void
|
2007-07-12 23:09:31 -06:00
|
|
|
nv50_graph_init_regs__nv(struct drm_device *dev)
|
2007-07-04 08:12:33 -06:00
|
|
|
{
|
2007-07-12 23:09:31 -06:00
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
2007-07-04 08:12:33 -06:00
|
|
|
|
|
|
|
DRM_DEBUG("\n");
|
|
|
|
|
|
|
|
NV_WRITE(0x400804, 0xc0000000);
|
|
|
|
NV_WRITE(0x406800, 0xc0000000);
|
|
|
|
NV_WRITE(0x400c04, 0xc0000000);
|
|
|
|
NV_WRITE(0x401804, 0xc0000000);
|
|
|
|
NV_WRITE(0x405018, 0xc0000000);
|
|
|
|
NV_WRITE(0x402000, 0xc0000000);
|
|
|
|
|
|
|
|
NV_WRITE(0x400108, 0xffffffff);
|
|
|
|
|
|
|
|
NV_WRITE(0x400824, 0x00004000);
|
|
|
|
NV_WRITE(0x400500, 0x00010001);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-07-12 23:09:31 -06:00
|
|
|
nv50_graph_init_regs(struct drm_device *dev)
|
2007-07-04 08:12:33 -06:00
|
|
|
{
|
2007-07-12 23:09:31 -06:00
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
2007-07-04 08:12:33 -06:00
|
|
|
|
|
|
|
DRM_DEBUG("\n");
|
|
|
|
|
|
|
|
NV_WRITE(NV04_PGRAPH_DEBUG_3, (1<<2) /* HW_CONTEXT_SWITCH_ENABLED */);
|
|
|
|
}
|
|
|
|
|
2008-01-06 23:10:36 -07:00
|
|
|
static int
|
2007-07-12 23:09:31 -06:00
|
|
|
nv50_graph_init_ctxctl(struct drm_device *dev)
|
2007-07-04 08:12:33 -06:00
|
|
|
{
|
2007-07-12 23:09:31 -06:00
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
2008-01-06 08:09:47 -07:00
|
|
|
uint32_t *voodoo = NULL;
|
2007-07-04 08:12:33 -06:00
|
|
|
|
|
|
|
DRM_DEBUG("\n");
|
|
|
|
|
|
|
|
switch (dev_priv->chipset) {
|
2008-09-16 23:13:27 -06:00
|
|
|
case 0x50:
|
2008-10-27 18:38:30 -06:00
|
|
|
voodoo = nv50_ctxprog;
|
2008-09-16 23:13:27 -06:00
|
|
|
break;
|
2007-07-04 08:12:33 -06:00
|
|
|
case 0x84:
|
2008-10-27 18:38:30 -06:00
|
|
|
voodoo = nv84_ctxprog;
|
2007-07-04 08:12:33 -06:00
|
|
|
break;
|
2008-01-06 08:09:47 -07:00
|
|
|
case 0x86:
|
2008-10-27 18:38:30 -06:00
|
|
|
voodoo = nv86_ctxprog;
|
2008-01-06 08:09:47 -07:00
|
|
|
break;
|
2008-09-16 22:49:04 -06:00
|
|
|
case 0x92:
|
2008-10-27 18:38:30 -06:00
|
|
|
voodoo = nv92_ctxprog;
|
2008-09-16 22:49:04 -06:00
|
|
|
break;
|
2008-11-23 00:49:09 -07:00
|
|
|
case 0x94:
|
2009-01-26 15:36:33 -07:00
|
|
|
case 0x96:
|
2008-11-23 00:49:09 -07:00
|
|
|
voodoo = nv94_ctxprog;
|
|
|
|
break;
|
2009-02-10 17:12:43 -07:00
|
|
|
case 0x98:
|
|
|
|
voodoo = nv98_ctxprog;
|
|
|
|
break;
|
2009-02-15 04:52:19 -07:00
|
|
|
case 0xa0:
|
|
|
|
voodoo = nva0_ctxprog;
|
|
|
|
break;
|
2008-09-16 23:02:54 -06:00
|
|
|
case 0xaa:
|
2008-10-27 18:38:30 -06:00
|
|
|
voodoo = nvaa_ctxprog;
|
2008-09-16 23:02:54 -06:00
|
|
|
break;
|
2007-07-04 08:12:33 -06:00
|
|
|
default:
|
2008-10-27 18:38:30 -06:00
|
|
|
DRM_ERROR("no ctxprog for chipset NV%02x\n", dev_priv->chipset);
|
2008-01-06 23:10:36 -07:00
|
|
|
return -EINVAL;
|
2007-07-04 08:12:33 -06:00
|
|
|
}
|
|
|
|
|
2008-01-06 23:10:36 -07:00
|
|
|
NV_WRITE(NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0);
|
|
|
|
while (*voodoo != ~0) {
|
|
|
|
NV_WRITE(NV40_PGRAPH_CTXCTL_UCODE_DATA, *voodoo);
|
|
|
|
voodoo++;
|
2007-07-04 08:12:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
NV_WRITE(0x400320, 4);
|
|
|
|
NV_WRITE(NV40_PGRAPH_CTXCTL_CUR, 0);
|
|
|
|
NV_WRITE(NV20_PGRAPH_CHANNEL_CTX_POINTER, 0);
|
2008-01-06 23:10:36 -07:00
|
|
|
|
|
|
|
return 0;
|
2007-07-04 08:12:33 -06:00
|
|
|
}
|
|
|
|
|
2007-11-04 19:42:22 -07:00
|
|
|
int
|
2007-07-12 23:09:31 -06:00
|
|
|
nv50_graph_init(struct drm_device *dev)
|
2007-06-24 04:49:19 -06:00
|
|
|
{
|
2008-01-06 23:10:36 -07:00
|
|
|
int ret;
|
|
|
|
|
2007-07-04 08:12:33 -06:00
|
|
|
DRM_DEBUG("\n");
|
|
|
|
|
2007-06-24 04:49:19 -06:00
|
|
|
nv50_graph_init_reset(dev);
|
2007-08-07 18:42:12 -06:00
|
|
|
nv50_graph_init_intr(dev);
|
2007-07-04 08:12:33 -06:00
|
|
|
nv50_graph_init_regs__nv(dev);
|
|
|
|
nv50_graph_init_regs(dev);
|
2008-01-06 23:10:36 -07:00
|
|
|
|
|
|
|
ret = nv50_graph_init_ctxctl(dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2007-06-24 04:49:19 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-07-12 23:09:31 -06:00
|
|
|
nv50_graph_takedown(struct drm_device *dev)
|
2007-06-24 04:49:19 -06:00
|
|
|
{
|
2007-07-04 08:12:33 -06:00
|
|
|
DRM_DEBUG("\n");
|
2007-06-24 04:49:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-08-05 11:40:43 -06:00
|
|
|
nv50_graph_create_context(struct nouveau_channel *chan)
|
2007-06-24 04:49:19 -06:00
|
|
|
{
|
2007-08-05 11:40:43 -06:00
|
|
|
struct drm_device *dev = chan->dev;
|
2007-07-12 23:09:31 -06:00
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
|
|
|
struct nouveau_gpuobj *ramin = chan->ramin->gpuobj;
|
2008-10-27 18:38:30 -06:00
|
|
|
struct nouveau_gpuobj *ctx;
|
2008-05-01 07:47:42 -06:00
|
|
|
struct nouveau_engine *engine = &dev_priv->Engine;
|
2008-10-27 18:38:30 -06:00
|
|
|
uint32_t *ctxvals = NULL;
|
2008-09-16 22:49:04 -06:00
|
|
|
int grctx_size = 0x70000, hdr;
|
2007-07-04 08:12:33 -06:00
|
|
|
int ret;
|
|
|
|
|
2007-08-05 11:40:43 -06:00
|
|
|
DRM_DEBUG("ch%d\n", chan->id);
|
2007-07-04 08:12:33 -06:00
|
|
|
|
2008-01-06 22:52:47 -07:00
|
|
|
ret = nouveau_gpuobj_new_ref(dev, chan, NULL, 0, grctx_size, 0x1000,
|
|
|
|
NVOBJ_FLAG_ZERO_ALLOC |
|
|
|
|
NVOBJ_FLAG_ZERO_FREE, &chan->ramin_grctx);
|
|
|
|
if (ret)
|
2007-07-04 08:12:33 -06:00
|
|
|
return ret;
|
2008-10-27 18:38:30 -06:00
|
|
|
ctx = chan->ramin_grctx->gpuobj;
|
2007-07-04 08:12:33 -06:00
|
|
|
|
|
|
|
hdr = IS_G80 ? 0x200 : 0x20;
|
|
|
|
INSTANCE_WR(ramin, (hdr + 0x00)/4, 0x00190002);
|
|
|
|
INSTANCE_WR(ramin, (hdr + 0x04)/4, chan->ramin_grctx->instance +
|
|
|
|
grctx_size - 1);
|
|
|
|
INSTANCE_WR(ramin, (hdr + 0x08)/4, chan->ramin_grctx->instance);
|
|
|
|
INSTANCE_WR(ramin, (hdr + 0x0c)/4, 0);
|
|
|
|
INSTANCE_WR(ramin, (hdr + 0x10)/4, 0);
|
|
|
|
INSTANCE_WR(ramin, (hdr + 0x14)/4, 0x00010000);
|
|
|
|
|
2008-05-01 07:47:42 -06:00
|
|
|
switch (dev_priv->chipset) {
|
2008-09-17 06:03:38 -06:00
|
|
|
case 0x50:
|
2008-10-27 18:38:30 -06:00
|
|
|
ctxvals = nv50_ctxvals;
|
2008-09-17 06:03:38 -06:00
|
|
|
break;
|
2008-05-01 07:47:42 -06:00
|
|
|
case 0x84:
|
2008-10-27 18:38:30 -06:00
|
|
|
ctxvals = nv84_ctxvals;
|
2008-05-01 07:47:42 -06:00
|
|
|
break;
|
|
|
|
case 0x86:
|
2008-10-27 18:38:30 -06:00
|
|
|
ctxvals = nv86_ctxvals;
|
2008-05-01 07:47:42 -06:00
|
|
|
break;
|
2008-09-16 22:49:04 -06:00
|
|
|
case 0x92:
|
2008-10-27 18:38:30 -06:00
|
|
|
ctxvals = nv92_ctxvals;
|
2008-09-16 22:49:04 -06:00
|
|
|
break;
|
2008-11-23 00:49:09 -07:00
|
|
|
case 0x94:
|
|
|
|
ctxvals = nv94_ctxvals;
|
|
|
|
break;
|
2009-02-09 16:05:09 -07:00
|
|
|
case 0x96:
|
|
|
|
ctxvals = nv96_ctxvals;
|
|
|
|
break;
|
2009-02-10 17:12:43 -07:00
|
|
|
case 0x98:
|
|
|
|
ctxvals = nv98_ctxvals;
|
|
|
|
break;
|
2009-02-15 04:52:19 -07:00
|
|
|
case 0xa0:
|
|
|
|
ctxvals = nva0_ctxvals;
|
|
|
|
break;
|
2008-09-17 06:18:03 -06:00
|
|
|
case 0xaa:
|
2008-10-27 18:38:30 -06:00
|
|
|
ctxvals = nvaa_ctxvals;
|
2008-09-17 06:18:03 -06:00
|
|
|
break;
|
2008-05-01 07:47:42 -06:00
|
|
|
default:
|
2008-10-27 18:38:30 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctxvals) {
|
|
|
|
int pos = 0;
|
|
|
|
|
|
|
|
while (*ctxvals) {
|
|
|
|
int cnt = *ctxvals++;
|
|
|
|
|
|
|
|
while (cnt--)
|
|
|
|
INSTANCE_WR(ctx, pos++, *ctxvals);
|
|
|
|
ctxvals++;
|
|
|
|
}
|
|
|
|
} else {
|
2008-05-01 07:47:42 -06:00
|
|
|
/* This is complete crack, it accidently used to make at
|
|
|
|
* least some G8x cards work partially somehow, though there's
|
|
|
|
* no good reason why - and it stopped working as the rest
|
|
|
|
* of the code got off the drugs..
|
|
|
|
*/
|
|
|
|
ret = engine->graph.load_context(chan);
|
|
|
|
if (ret) {
|
|
|
|
DRM_ERROR("Error hacking up context: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-27 18:38:30 -06:00
|
|
|
INSTANCE_WR(ctx, 0x00000/4, chan->ramin->instance >> 12);
|
2009-02-15 04:52:19 -07:00
|
|
|
if ((dev_priv->chipset & 0xf0) == 0xa0)
|
2008-10-27 18:38:30 -06:00
|
|
|
INSTANCE_WR(ctx, 0x00004/4, 0x00000002);
|
|
|
|
else
|
|
|
|
INSTANCE_WR(ctx, 0x0011c/4, 0x00000002);
|
|
|
|
|
2007-06-24 04:49:19 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-08-05 11:40:43 -06:00
|
|
|
nv50_graph_destroy_context(struct nouveau_channel *chan)
|
2007-06-24 04:49:19 -06:00
|
|
|
{
|
2007-08-05 11:40:43 -06:00
|
|
|
struct drm_device *dev = chan->dev;
|
2007-07-12 23:09:31 -06:00
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
2007-07-04 08:12:33 -06:00
|
|
|
int i, hdr;
|
|
|
|
|
2007-08-05 11:40:43 -06:00
|
|
|
DRM_DEBUG("ch%d\n", chan->id);
|
2007-07-04 08:12:33 -06:00
|
|
|
|
|
|
|
hdr = IS_G80 ? 0x200 : 0x20;
|
|
|
|
for (i=hdr; i<hdr+24; i+=4)
|
|
|
|
INSTANCE_WR(chan->ramin->gpuobj, i/4, 0);
|
|
|
|
|
|
|
|
nouveau_gpuobj_ref_del(dev, &chan->ramin_grctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-07-12 23:09:31 -06:00
|
|
|
nv50_graph_transfer_context(struct drm_device *dev, uint32_t inst, int save)
|
2007-07-04 08:12:33 -06:00
|
|
|
{
|
2007-07-12 23:09:31 -06:00
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
2007-07-04 08:12:33 -06:00
|
|
|
uint32_t old_cp, tv = 20000;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
DRM_DEBUG("inst=0x%08x, save=%d\n", inst, save);
|
|
|
|
|
|
|
|
old_cp = NV_READ(NV20_PGRAPH_CHANNEL_CTX_POINTER);
|
2008-01-07 00:56:44 -07:00
|
|
|
NV_WRITE(NV20_PGRAPH_CHANNEL_CTX_POINTER, inst);
|
2007-07-04 08:12:33 -06:00
|
|
|
NV_WRITE(0x400824, NV_READ(0x400824) |
|
|
|
|
(save ? NV40_PGRAPH_CTXCTL_0310_XFER_SAVE :
|
2007-11-04 19:42:22 -07:00
|
|
|
NV40_PGRAPH_CTXCTL_0310_XFER_LOAD));
|
2007-07-04 08:12:33 -06:00
|
|
|
NV_WRITE(NV40_PGRAPH_CTXCTL_0304, NV40_PGRAPH_CTXCTL_0304_XFER_CTX);
|
|
|
|
|
|
|
|
for (i = 0; i < tv; i++) {
|
|
|
|
if (NV_READ(NV40_PGRAPH_CTXCTL_030C) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
NV_WRITE(NV20_PGRAPH_CHANNEL_CTX_POINTER, old_cp);
|
|
|
|
|
|
|
|
if (i == tv) {
|
|
|
|
DRM_ERROR("failed: inst=0x%08x save=%d\n", inst, save);
|
|
|
|
DRM_ERROR("0x40030C = 0x%08x\n",
|
|
|
|
NV_READ(NV40_PGRAPH_CTXCTL_030C));
|
2007-07-19 18:00:17 -06:00
|
|
|
return -EBUSY;
|
2007-07-04 08:12:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-06-24 04:49:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-08-05 11:40:43 -06:00
|
|
|
nv50_graph_load_context(struct nouveau_channel *chan)
|
2007-06-24 04:49:19 -06:00
|
|
|
{
|
2007-08-05 11:40:43 -06:00
|
|
|
struct drm_device *dev = chan->dev;
|
2007-07-12 23:09:31 -06:00
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
2008-01-07 00:56:44 -07:00
|
|
|
uint32_t inst = chan->ramin->instance >> 12;
|
2007-07-15 01:18:15 -06:00
|
|
|
int ret; (void)ret;
|
2007-07-04 08:12:33 -06:00
|
|
|
|
2007-08-05 11:40:43 -06:00
|
|
|
DRM_DEBUG("ch%d\n", chan->id);
|
2007-07-04 08:12:33 -06:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
if ((ret = nv50_graph_transfer_context(dev, inst, 0)))
|
|
|
|
return ret;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NV_WRITE(NV20_PGRAPH_CHANNEL_CTX_POINTER, inst);
|
|
|
|
NV_WRITE(0x400320, 4);
|
2008-01-07 00:56:44 -07:00
|
|
|
NV_WRITE(NV40_PGRAPH_CTXCTL_CUR, inst | (1<<31));
|
2007-07-04 08:12:33 -06:00
|
|
|
|
2007-06-24 04:49:19 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-08-05 11:40:43 -06:00
|
|
|
nv50_graph_save_context(struct nouveau_channel *chan)
|
2007-06-24 04:49:19 -06:00
|
|
|
{
|
2007-08-05 11:40:43 -06:00
|
|
|
struct drm_device *dev = chan->dev;
|
2008-01-07 00:56:44 -07:00
|
|
|
uint32_t inst = chan->ramin->instance >> 12;
|
2007-07-04 08:12:33 -06:00
|
|
|
|
2007-08-05 11:40:43 -06:00
|
|
|
DRM_DEBUG("ch%d\n", chan->id);
|
2007-07-04 08:12:33 -06:00
|
|
|
|
|
|
|
return nv50_graph_transfer_context(dev, inst, 1);
|
2007-06-24 04:49:19 -06:00
|
|
|
}
|