2007-01-13 15:19:41 -07:00
|
|
|
/*
|
|
|
|
* Copyright 2007 Matthieu CASTET <castet.matthieu@free.fr>
|
|
|
|
* 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
|
|
|
|
* PRECISION INSIGHT 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"
|
|
|
|
#include "nouveau_drm.h"
|
|
|
|
|
2007-01-14 12:04:20 -07:00
|
|
|
#define NV20_GRCTX_SIZE (3529*4)
|
2007-01-13 15:19:41 -07:00
|
|
|
|
2007-07-12 23:09:31 -06:00
|
|
|
int nv20_graph_create_context(struct drm_device *dev, int channel) {
|
|
|
|
struct drm_nouveau_private *dev_priv =
|
|
|
|
(struct drm_nouveau_private *)dev->dev_private;
|
2007-07-04 08:12:33 -06:00
|
|
|
struct nouveau_fifo *chan = dev_priv->fifos[channel];
|
2007-01-13 15:19:41 -07:00
|
|
|
unsigned int ctx_size = NV20_GRCTX_SIZE;
|
2007-07-02 03:31:18 -06:00
|
|
|
int ret;
|
2007-01-13 15:19:41 -07:00
|
|
|
|
2007-07-02 03:31:18 -06:00
|
|
|
if ((ret = nouveau_gpuobj_new_ref(dev, channel, -1, 0, ctx_size, 16,
|
|
|
|
NVOBJ_FLAG_ZERO_ALLOC,
|
|
|
|
&chan->ramin_grctx)))
|
|
|
|
return ret;
|
2007-01-13 15:19:41 -07:00
|
|
|
|
|
|
|
/* Initialise default context values */
|
2007-07-02 03:31:18 -06:00
|
|
|
INSTANCE_WR(chan->ramin_grctx->gpuobj, 10, channel<<24); /* CTX_USER */
|
2007-01-13 15:19:41 -07:00
|
|
|
|
2007-07-02 03:31:18 -06:00
|
|
|
INSTANCE_WR(dev_priv->ctx_table->gpuobj, channel,
|
|
|
|
chan->ramin_grctx->instance >> 4);
|
2007-01-13 15:19:41 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-12 23:09:31 -06:00
|
|
|
void nv20_graph_destroy_context(struct drm_device *dev, int channel) {
|
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
2007-07-04 08:12:33 -06:00
|
|
|
struct nouveau_fifo *chan = dev_priv->fifos[channel];
|
2007-06-24 03:00:26 -06:00
|
|
|
|
2007-07-02 03:31:18 -06:00
|
|
|
if (chan->ramin_grctx)
|
|
|
|
nouveau_gpuobj_ref_del(dev, &chan->ramin_grctx);
|
2007-06-24 03:00:26 -06:00
|
|
|
|
2007-07-02 03:31:18 -06:00
|
|
|
INSTANCE_WR(dev_priv->ctx_table->gpuobj, channel, 0);
|
2007-06-24 03:00:26 -06:00
|
|
|
}
|
|
|
|
|
2007-07-12 23:09:31 -06:00
|
|
|
static void nv20_graph_rdi(struct drm_device *dev) {
|
|
|
|
struct drm_nouveau_private *dev_priv =
|
|
|
|
(struct drm_nouveau_private *)dev->dev_private;
|
2007-01-13 15:19:41 -07:00
|
|
|
int i;
|
|
|
|
|
2007-02-02 20:57:06 -07:00
|
|
|
NV_WRITE(NV10_PGRAPH_RDI_INDEX, 0x2c80000);
|
2007-01-13 15:19:41 -07:00
|
|
|
for (i = 0; i < 32; i++)
|
2007-02-02 20:57:06 -07:00
|
|
|
NV_WRITE(NV10_PGRAPH_RDI_DATA, 0);
|
2007-01-13 15:19:41 -07:00
|
|
|
|
|
|
|
nouveau_wait_for_idle(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save current context (from PGRAPH) into the channel's context
|
|
|
|
*/
|
2007-07-12 23:09:31 -06:00
|
|
|
int nv20_graph_save_context(struct drm_device *dev, int channel) {
|
|
|
|
struct drm_nouveau_private *dev_priv =
|
|
|
|
(struct drm_nouveau_private *)dev->dev_private;
|
2007-07-04 08:12:33 -06:00
|
|
|
struct nouveau_fifo *chan = dev_priv->fifos[channel];
|
2007-01-13 15:19:41 -07:00
|
|
|
uint32_t instance;
|
|
|
|
|
2007-07-02 03:31:18 -06:00
|
|
|
instance = INSTANCE_RD(dev_priv->ctx_table->gpuobj, channel);
|
2007-01-13 15:19:41 -07:00
|
|
|
if (!instance) {
|
2007-06-24 03:00:26 -06:00
|
|
|
return DRM_ERR(EINVAL);
|
2007-01-13 15:19:41 -07:00
|
|
|
}
|
2007-07-02 03:31:18 -06:00
|
|
|
if (instance != (chan->ramin_grctx->instance >> 4))
|
2007-06-24 03:00:26 -06:00
|
|
|
DRM_ERROR("nv20_graph_save_context : bad instance\n");
|
2007-01-13 15:19:41 -07:00
|
|
|
|
2007-02-02 20:57:06 -07:00
|
|
|
NV_WRITE(NV10_PGRAPH_CHANNEL_CTX_SIZE, instance);
|
|
|
|
NV_WRITE(NV10_PGRAPH_CHANNEL_CTX_POINTER, 2 /* save ctx */);
|
2007-06-24 03:00:26 -06:00
|
|
|
return 0;
|
2007-01-13 15:19:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Restore the context for a specific channel into PGRAPH
|
|
|
|
*/
|
2007-07-12 23:09:31 -06:00
|
|
|
int nv20_graph_load_context(struct drm_device *dev, int channel) {
|
|
|
|
struct drm_nouveau_private *dev_priv =
|
|
|
|
(struct drm_nouveau_private *)dev->dev_private;
|
2007-07-04 08:12:33 -06:00
|
|
|
struct nouveau_fifo *chan = dev_priv->fifos[channel];
|
2007-01-13 15:19:41 -07:00
|
|
|
uint32_t instance;
|
|
|
|
|
2007-07-02 03:31:18 -06:00
|
|
|
instance = INSTANCE_RD(dev_priv->ctx_table->gpuobj, channel);
|
2007-01-13 15:19:41 -07:00
|
|
|
if (!instance) {
|
2007-06-24 03:00:26 -06:00
|
|
|
return DRM_ERR(EINVAL);
|
2007-01-13 15:19:41 -07:00
|
|
|
}
|
2007-07-02 03:31:18 -06:00
|
|
|
if (instance != (chan->ramin_grctx->instance >> 4))
|
2007-06-24 03:00:26 -06:00
|
|
|
DRM_ERROR("nv20_graph_load_context_current : bad instance\n");
|
2007-01-13 15:19:41 -07:00
|
|
|
|
2007-02-02 20:57:06 -07:00
|
|
|
NV_WRITE(NV10_PGRAPH_CTX_USER, channel << 24);
|
|
|
|
NV_WRITE(NV10_PGRAPH_CHANNEL_CTX_SIZE, instance);
|
|
|
|
NV_WRITE(NV10_PGRAPH_CHANNEL_CTX_POINTER, 1 /* restore ctx */);
|
2007-06-24 03:00:26 -06:00
|
|
|
return 0;
|
2007-01-13 15:19:41 -07:00
|
|
|
}
|
|
|
|
|
2007-07-12 23:09:31 -06:00
|
|
|
void nouveau_nv20_context_switch(struct drm_device *dev)
|
2007-01-13 15:19:41 -07:00
|
|
|
{
|
2007-07-12 23:09:31 -06:00
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
2007-01-13 15:19:41 -07:00
|
|
|
int channel, channel_old;
|
|
|
|
|
2007-02-02 20:57:06 -07:00
|
|
|
channel=NV_READ(NV03_PFIFO_CACHE1_PUSH1)&(nouveau_fifo_number(dev)-1);
|
|
|
|
channel_old = (NV_READ(NV10_PGRAPH_CTX_USER) >> 24) & (nouveau_fifo_number(dev)-1);
|
2007-01-13 15:19:41 -07:00
|
|
|
|
2007-01-14 12:04:20 -07:00
|
|
|
DRM_DEBUG("NV: PGRAPH context switch interrupt channel %x -> %x\n",channel_old, channel);
|
2007-01-13 15:19:41 -07:00
|
|
|
|
2007-02-02 20:57:06 -07:00
|
|
|
NV_WRITE(NV04_PGRAPH_FIFO,0x0);
|
2007-01-13 15:19:41 -07:00
|
|
|
|
2007-06-24 03:00:26 -06:00
|
|
|
nv20_graph_save_context(dev, channel_old);
|
2007-01-13 15:19:41 -07:00
|
|
|
|
|
|
|
nouveau_wait_for_idle(dev);
|
|
|
|
|
2007-04-01 06:31:41 -06:00
|
|
|
NV_WRITE(NV10_PGRAPH_CTX_CONTROL, 0x10000000);
|
2007-01-13 15:19:41 -07:00
|
|
|
|
2007-06-24 03:00:26 -06:00
|
|
|
nv20_graph_load_context(dev, channel);
|
2007-01-13 15:19:41 -07:00
|
|
|
|
|
|
|
nouveau_wait_for_idle(dev);
|
|
|
|
|
2007-02-02 20:57:06 -07:00
|
|
|
if ((NV_READ(NV10_PGRAPH_CTX_USER) >> 24) != channel)
|
|
|
|
DRM_ERROR("nouveau_nv20_context_switch : wrong channel restored %x %x!!!\n", channel, NV_READ(NV10_PGRAPH_CTX_USER) >> 24);
|
2007-01-13 15:19:41 -07:00
|
|
|
|
2007-04-01 06:31:41 -06:00
|
|
|
NV_WRITE(NV10_PGRAPH_CTX_CONTROL, 0x10010100);
|
2007-02-02 20:57:06 -07:00
|
|
|
NV_WRITE(NV10_PGRAPH_FFINTFC_ST2, NV_READ(NV10_PGRAPH_FFINTFC_ST2)&0xCFFFFFFF);
|
2007-01-13 15:19:41 -07:00
|
|
|
|
2007-02-02 20:57:06 -07:00
|
|
|
NV_WRITE(NV04_PGRAPH_FIFO,0x1);
|
2007-01-13 15:19:41 -07:00
|
|
|
}
|
|
|
|
|
2007-07-12 23:09:31 -06:00
|
|
|
int nv20_graph_init(struct drm_device *dev) {
|
|
|
|
struct drm_nouveau_private *dev_priv =
|
|
|
|
(struct drm_nouveau_private *)dev->dev_private;
|
2007-03-26 03:43:48 -06:00
|
|
|
uint32_t tmp, vramsz;
|
2007-07-02 03:31:18 -06:00
|
|
|
int ret, i;
|
2007-03-26 03:43:48 -06:00
|
|
|
|
|
|
|
NV_WRITE(NV03_PMC_ENABLE, NV_READ(NV03_PMC_ENABLE) &
|
|
|
|
~NV_PMC_ENABLE_PGRAPH);
|
|
|
|
NV_WRITE(NV03_PMC_ENABLE, NV_READ(NV03_PMC_ENABLE) |
|
|
|
|
NV_PMC_ENABLE_PGRAPH);
|
2007-01-13 15:19:41 -07:00
|
|
|
|
|
|
|
/* Create Context Pointer Table */
|
|
|
|
dev_priv->ctx_table_size = 32 * 4;
|
2007-07-02 03:31:18 -06:00
|
|
|
if ((ret = nouveau_gpuobj_new_ref(dev, -1, -1, 0,
|
|
|
|
dev_priv->ctx_table_size, 16,
|
|
|
|
NVOBJ_FLAG_ZERO_ALLOC,
|
|
|
|
&dev_priv->ctx_table)))
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
NV_WRITE(NV10_PGRAPH_CHANNEL_CTX_TABLE,
|
|
|
|
dev_priv->ctx_table->instance >> 4);
|
2007-01-13 15:19:41 -07:00
|
|
|
|
|
|
|
//XXX need to be done and save/restore for each fifo ???
|
|
|
|
nv20_graph_rdi(dev);
|
|
|
|
|
2007-03-26 03:43:48 -06:00
|
|
|
NV_WRITE(NV03_PGRAPH_INTR_EN, 0x00000000);
|
|
|
|
NV_WRITE(NV03_PGRAPH_INTR , 0xFFFFFFFF);
|
|
|
|
|
|
|
|
NV_WRITE(NV04_PGRAPH_DEBUG_0, 0xFFFFFFFF);
|
|
|
|
NV_WRITE(NV04_PGRAPH_DEBUG_0, 0x00000000);
|
|
|
|
NV_WRITE(NV04_PGRAPH_DEBUG_1, 0x00118700);
|
|
|
|
NV_WRITE(NV04_PGRAPH_DEBUG_3, 0xF20E0431);
|
|
|
|
NV_WRITE(NV10_PGRAPH_DEBUG_4, 0x00000000);
|
|
|
|
NV_WRITE(0x40009C , 0x00000040);
|
|
|
|
|
|
|
|
if (dev_priv->chipset >= 0x25) {
|
|
|
|
NV_WRITE(0x400890, 0x00080000);
|
|
|
|
NV_WRITE(0x400610, 0x304B1FB6);
|
|
|
|
NV_WRITE(0x400B80, 0x18B82880);
|
|
|
|
NV_WRITE(0x400B84, 0x44000000);
|
|
|
|
NV_WRITE(0x400098, 0x40000080);
|
|
|
|
NV_WRITE(0x400B88, 0x000000ff);
|
|
|
|
} else {
|
|
|
|
NV_WRITE(0x400880, 0x00080000);
|
|
|
|
NV_WRITE(0x400094, 0x00000005);
|
|
|
|
NV_WRITE(0x400B80, 0x45CAA208);
|
|
|
|
NV_WRITE(0x400B84, 0x24000000);
|
|
|
|
NV_WRITE(0x400098, 0x00000040);
|
|
|
|
NV_WRITE(NV10_PGRAPH_RDI_INDEX, 0x00E00038);
|
|
|
|
NV_WRITE(NV10_PGRAPH_RDI_DATA , 0x00000030);
|
|
|
|
NV_WRITE(NV10_PGRAPH_RDI_INDEX, 0x00E10038);
|
|
|
|
NV_WRITE(NV10_PGRAPH_RDI_DATA , 0x00000030);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy tile info from PFB */
|
|
|
|
for (i=0; i<NV10_PFB_TILE__SIZE; i++) {
|
|
|
|
NV_WRITE(NV10_PGRAPH_TILE(i), NV_READ(NV10_PFB_TILE(i)));
|
|
|
|
NV_WRITE(NV10_PGRAPH_TLIMIT(i), NV_READ(NV10_PFB_TLIMIT(i)));
|
|
|
|
NV_WRITE(NV10_PGRAPH_TSIZE(i), NV_READ(NV10_PFB_TSIZE(i)));
|
|
|
|
NV_WRITE(NV10_PGRAPH_TSTATUS(i), NV_READ(NV10_PFB_TSTATUS(i)));
|
|
|
|
}
|
|
|
|
|
2007-04-01 06:31:41 -06:00
|
|
|
NV_WRITE(NV10_PGRAPH_CTX_CONTROL, 0x10010100);
|
2007-03-26 03:43:48 -06:00
|
|
|
NV_WRITE(NV10_PGRAPH_STATE , 0xFFFFFFFF);
|
|
|
|
NV_WRITE(NV04_PGRAPH_FIFO , 0x00000001);
|
|
|
|
|
|
|
|
tmp = NV_READ(NV10_PGRAPH_SURFACE) & 0x0007ff00;
|
|
|
|
NV_WRITE(NV10_PGRAPH_SURFACE, tmp);
|
|
|
|
tmp = NV_READ(NV10_PGRAPH_SURFACE) | 0x00020100;
|
|
|
|
NV_WRITE(NV10_PGRAPH_SURFACE, tmp);
|
|
|
|
|
|
|
|
/* begin RAM config */
|
|
|
|
vramsz = drm_get_resource_len(dev, 0) - 1;
|
|
|
|
NV_WRITE(0x4009A4, NV_READ(NV04_PFB_CFG0));
|
|
|
|
NV_WRITE(0x4009A8, NV_READ(NV04_PFB_CFG1));
|
|
|
|
NV_WRITE(NV10_PGRAPH_RDI_INDEX, 0x00EA0000);
|
|
|
|
NV_WRITE(NV10_PGRAPH_RDI_DATA , NV_READ(NV04_PFB_CFG0));
|
|
|
|
NV_WRITE(NV10_PGRAPH_RDI_INDEX, 0x00EA0004);
|
|
|
|
NV_WRITE(NV10_PGRAPH_RDI_DATA , NV_READ(NV04_PFB_CFG1));
|
|
|
|
NV_WRITE(0x400820, 0);
|
|
|
|
NV_WRITE(0x400824, 0);
|
|
|
|
NV_WRITE(0x400864, vramsz-1);
|
|
|
|
NV_WRITE(0x400868, vramsz-1);
|
|
|
|
|
|
|
|
/* interesting.. the below overwrites some of the tile setup above.. */
|
|
|
|
NV_WRITE(0x400B20, 0x00000000);
|
|
|
|
NV_WRITE(0x400B04, 0xFFFFFFFF);
|
|
|
|
|
|
|
|
NV_WRITE(NV03_PGRAPH_ABS_UCLIP_XMIN, 0);
|
|
|
|
NV_WRITE(NV03_PGRAPH_ABS_UCLIP_YMIN, 0);
|
|
|
|
NV_WRITE(NV03_PGRAPH_ABS_UCLIP_XMAX, 0x7fff);
|
|
|
|
NV_WRITE(NV03_PGRAPH_ABS_UCLIP_YMAX, 0x7fff);
|
|
|
|
|
2007-01-13 15:19:41 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2007-03-26 03:43:48 -06:00
|
|
|
|
2007-07-12 23:09:31 -06:00
|
|
|
void nv20_graph_takedown(struct drm_device *dev)
|
2007-03-26 03:43:48 -06:00
|
|
|
{
|
2007-07-16 22:06:05 -06:00
|
|
|
struct drm_nouveau_private *dev_priv = dev->dev_private;
|
|
|
|
|
|
|
|
nouveau_gpuobj_ref_del(dev, &dev_priv->ctx_table);
|
2007-03-26 03:43:48 -06:00
|
|
|
}
|
|
|
|
|