drm/shared-core/mga_dma.c

734 lines
18 KiB
C
Raw Normal View History

2000-02-22 08:43:59 -07:00
/* mga_dma.c -- DMA support for mga g200/g400 -*- linux-c -*-
* Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
*
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
2000-06-08 08:38:22 -06:00
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
2000-02-22 08:43:59 -07:00
* 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:
2000-09-06 14:56:34 -06:00
*
2000-02-22 08:43:59 -07:00
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
2000-09-06 14:56:34 -06:00
*
2000-02-22 08:43:59 -07:00
* 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.
*
2001-02-15 01:12:14 -07:00
* Authors:
* Rickard E. (Rik) Faith <faith@valinux.com>
* Jeff Hartmann <jhartmann@valinux.com>
* Keith Whitwell <keith@tungstengraphics.com>
2000-02-22 08:43:59 -07:00
*
2001-02-15 01:12:14 -07:00
* Rewritten by:
* Gareth Hughes <gareth@valinux.com>
2000-02-22 08:43:59 -07:00
*/
#include "drmP.h"
2002-04-09 15:54:56 -06:00
#include "drm.h"
#include "mga_drm.h"
2000-02-22 08:43:59 -07:00
#include "mga_drv.h"
2001-02-15 01:12:14 -07:00
#define MGA_DEFAULT_USEC_TIMEOUT 10000
#define MGA_FREELIST_DEBUG 0
2000-02-22 08:43:59 -07:00
static int mga_do_cleanup_dma(drm_device_t * dev);
2001-02-15 01:12:14 -07:00
/* ================================================================
* Engine control
*/
2000-02-22 08:43:59 -07:00
int mga_do_wait_for_idle(drm_mga_private_t * dev_priv)
2000-04-04 16:08:14 -06:00
{
2001-02-15 01:12:14 -07:00
u32 status = 0;
int i;
DRM_DEBUG("\n");
2000-09-06 14:56:34 -06:00
for (i = 0; i < dev_priv->usec_timeout; i++) {
status = MGA_READ(MGA_STATUS) & MGA_ENGINE_IDLE_MASK;
if (status == MGA_ENDPRDMASTS) {
MGA_WRITE8(MGA_CRTC_INDEX, 0);
return 0;
}
DRM_UDELAY(1);
2000-04-04 16:08:14 -06:00
}
2000-09-06 14:56:34 -06:00
#if MGA_DMA_DEBUG
DRM_ERROR("failed!\n");
DRM_INFO(" status=0x%08x\n", status);
#endif
2002-07-05 02:31:11 -06:00
return DRM_ERR(EBUSY);
2000-04-04 16:08:14 -06:00
}
static int mga_do_dma_reset(drm_mga_private_t * dev_priv)
2000-02-22 08:43:59 -07:00
{
2001-02-15 01:12:14 -07:00
drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
drm_mga_primary_buffer_t *primary = &dev_priv->prim;
2000-02-22 08:43:59 -07:00
DRM_DEBUG("\n");
2000-04-04 16:08:14 -06:00
2001-02-15 01:12:14 -07:00
/* The primary DMA stream should look like new right about now.
*/
primary->tail = 0;
primary->space = primary->size;
primary->last_flush = 0;
2000-09-06 14:56:34 -06:00
2001-02-15 01:12:14 -07:00
sarea_priv->last_wrap = 0;
2000-02-22 08:43:59 -07:00
2001-02-15 01:12:14 -07:00
/* FIXME: Reset counters, buffer ages etc...
*/
2000-09-06 14:56:34 -06:00
2001-02-15 01:12:14 -07:00
/* FIXME: What else do we need to reinitialize? WARP stuff?
*/
return 0;
2000-04-04 16:08:14 -06:00
}
2000-02-22 08:43:59 -07:00
2001-02-15 01:12:14 -07:00
/* ================================================================
* Primary DMA stream
*/
void mga_do_dma_flush(drm_mga_private_t * dev_priv)
2000-02-22 08:43:59 -07:00
{
2001-02-15 01:12:14 -07:00
drm_mga_primary_buffer_t *primary = &dev_priv->prim;
u32 head, tail;
2002-10-10 02:25:40 -06:00
u32 status = 0;
int i;
DMA_LOCALS;
DRM_DEBUG("\n");
/* We need to wait so that we can do an safe flush */
for (i = 0; i < dev_priv->usec_timeout; i++) {
status = MGA_READ(MGA_STATUS) & MGA_ENGINE_IDLE_MASK;
if (status == MGA_ENDPRDMASTS)
break;
DRM_UDELAY(1);
2002-10-10 02:25:40 -06:00
}
if (primary->tail == primary->last_flush) {
DRM_DEBUG(" bailing out...\n");
2001-02-15 01:12:14 -07:00
return;
}
2001-02-15 01:12:14 -07:00
tail = primary->tail + dev_priv->primary->offset;
2000-02-22 08:43:59 -07:00
2001-02-15 01:12:14 -07:00
/* We need to pad the stream between flushes, as the card
* actually (partially?) reads the first of these commands.
* See page 4-16 in the G400 manual, middle of the page or so.
*/
BEGIN_DMA(1);
2001-02-15 01:12:14 -07:00
DMA_BLOCK(MGA_DMAPAD, 0x00000000,
MGA_DMAPAD, 0x00000000,
MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
2001-02-15 01:12:14 -07:00
ADVANCE_DMA();
primary->last_flush = primary->tail;
head = MGA_READ(MGA_PRIMADDRESS);
2001-02-15 01:12:14 -07:00
if (head <= tail) {
2001-02-15 01:12:14 -07:00
primary->space = primary->size - primary->tail;
2000-02-22 08:43:59 -07:00
} else {
2001-02-15 01:12:14 -07:00
primary->space = head - tail;
2000-04-04 16:08:14 -06:00
}
2000-09-06 14:56:34 -06:00
DRM_DEBUG(" head = 0x%06lx\n", head - dev_priv->primary->offset);
DRM_DEBUG(" tail = 0x%06lx\n", tail - dev_priv->primary->offset);
DRM_DEBUG(" space = 0x%06x\n", primary->space);
2001-02-15 01:12:14 -07:00
mga_flush_write_combine();
MGA_WRITE(MGA_PRIMEND, tail | MGA_PAGPXFER);
2001-02-15 01:12:14 -07:00
DRM_DEBUG("done.\n");
2000-02-22 08:43:59 -07:00
}
void mga_do_dma_wrap_start(drm_mga_private_t * dev_priv)
2000-02-22 08:43:59 -07:00
{
2001-02-15 01:12:14 -07:00
drm_mga_primary_buffer_t *primary = &dev_priv->prim;
u32 head, tail;
DMA_LOCALS;
DRM_DEBUG("\n");
2000-09-06 14:56:34 -06:00
2001-02-15 01:12:14 -07:00
BEGIN_DMA_WRAP();
2000-09-06 14:56:34 -06:00
DMA_BLOCK(MGA_DMAPAD, 0x00000000,
MGA_DMAPAD, 0x00000000,
MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
2000-02-22 08:43:59 -07:00
2001-02-15 01:12:14 -07:00
ADVANCE_DMA();
tail = primary->tail + dev_priv->primary->offset;
primary->tail = 0;
primary->last_flush = 0;
primary->last_wrap++;
head = MGA_READ(MGA_PRIMADDRESS);
2001-02-15 01:12:14 -07:00
if (head == dev_priv->primary->offset) {
2001-02-15 01:12:14 -07:00
primary->space = primary->size;
2000-02-22 08:43:59 -07:00
} else {
2001-02-15 01:12:14 -07:00
primary->space = head - dev_priv->primary->offset;
2000-02-22 08:43:59 -07:00
}
DRM_DEBUG(" head = 0x%06lx\n", head - dev_priv->primary->offset);
DRM_DEBUG(" tail = 0x%06x\n", primary->tail);
DRM_DEBUG(" wrap = %d\n", primary->last_wrap);
DRM_DEBUG(" space = 0x%06x\n", primary->space);
2001-02-15 01:12:14 -07:00
mga_flush_write_combine();
MGA_WRITE(MGA_PRIMEND, tail | MGA_PAGPXFER);
2001-02-15 01:12:14 -07:00
set_bit(0, &primary->wrapped);
DRM_DEBUG("done.\n");
2000-02-22 08:43:59 -07:00
}
void mga_do_dma_wrap_end(drm_mga_private_t * dev_priv)
2000-02-22 08:43:59 -07:00
{
drm_mga_primary_buffer_t *primary = &dev_priv->prim;
2001-02-15 01:12:14 -07:00
drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
u32 head = dev_priv->primary->offset;
DRM_DEBUG("\n");
2001-02-15 01:12:14 -07:00
sarea_priv->last_wrap++;
DRM_DEBUG(" wrap = %d\n", sarea_priv->last_wrap);
2001-02-15 01:12:14 -07:00
mga_flush_write_combine();
MGA_WRITE(MGA_PRIMADDRESS, head | MGA_DMA_GENERAL);
clear_bit(0, &primary->wrapped);
DRM_DEBUG("done.\n");
2001-02-15 01:12:14 -07:00
}
2000-02-22 08:43:59 -07:00
2001-02-15 01:12:14 -07:00
/* ================================================================
* Freelist management
*/
2000-09-06 14:56:34 -06:00
2001-02-15 01:12:14 -07:00
#define MGA_BUFFER_USED ~0
#define MGA_BUFFER_FREE 0
2000-02-22 08:43:59 -07:00
#if MGA_FREELIST_DEBUG
static void mga_freelist_print(drm_device_t * dev)
2001-02-15 01:12:14 -07:00
{
drm_mga_private_t *dev_priv = dev->dev_private;
drm_mga_freelist_t *entry;
2000-02-22 08:43:59 -07:00
DRM_INFO("\n");
DRM_INFO("current dispatch: last=0x%x done=0x%x\n",
dev_priv->sarea_priv->last_dispatch,
(unsigned int)(MGA_READ(MGA_PRIMADDRESS) -
dev_priv->primary->offset));
DRM_INFO("current freelist:\n");
for (entry = dev_priv->head->next; entry; entry = entry->next) {
DRM_INFO(" %p idx=%2d age=0x%x 0x%06lx\n",
entry, entry->buf->idx, entry->age.head,
entry->age.head - dev_priv->primary->offset);
2001-02-15 01:12:14 -07:00
}
DRM_INFO("\n");
2000-02-22 08:43:59 -07:00
}
#endif
2000-02-22 08:43:59 -07:00
static int mga_freelist_init(drm_device_t * dev, drm_mga_private_t * dev_priv)
2000-02-22 08:43:59 -07:00
{
2001-02-15 01:12:14 -07:00
drm_device_dma_t *dma = dev->dma;
drm_buf_t *buf;
drm_mga_buf_priv_t *buf_priv;
drm_mga_freelist_t *entry;
int i;
DRM_DEBUG("count=%d\n", dma->buf_count);
2000-09-06 14:56:34 -06:00
dev_priv->head = drm_alloc(sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
if (dev_priv->head == NULL)
2002-07-05 02:31:11 -06:00
return DRM_ERR(ENOMEM);
2000-09-06 14:56:34 -06:00
memset(dev_priv->head, 0, sizeof(drm_mga_freelist_t));
SET_AGE(&dev_priv->head->age, MGA_BUFFER_USED, 0);
2000-02-22 08:43:59 -07:00
for (i = 0; i < dma->buf_count; i++) {
2001-02-15 01:12:14 -07:00
buf = dma->buflist[i];
buf_priv = buf->dev_private;
2000-09-06 14:56:34 -06:00
entry = drm_alloc(sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
if (entry == NULL)
2002-07-05 02:31:11 -06:00
return DRM_ERR(ENOMEM);
2000-02-22 08:43:59 -07:00
memset(entry, 0, sizeof(drm_mga_freelist_t));
2001-02-15 01:12:14 -07:00
entry->next = dev_priv->head->next;
entry->prev = dev_priv->head;
SET_AGE(&entry->age, MGA_BUFFER_FREE, 0);
2001-02-15 01:12:14 -07:00
entry->buf = buf;
if (dev_priv->head->next != NULL)
2001-02-15 01:12:14 -07:00
dev_priv->head->next->prev = entry;
if (entry->next == NULL)
2001-02-15 01:12:14 -07:00
dev_priv->tail = entry;
buf_priv->list_entry = entry;
buf_priv->discard = 0;
buf_priv->dispatched = 0;
2000-04-04 16:08:14 -06:00
2001-02-15 01:12:14 -07:00
dev_priv->head->next = entry;
}
2001-02-15 01:12:14 -07:00
return 0;
2000-02-22 08:43:59 -07:00
}
static void mga_freelist_cleanup(drm_device_t * dev)
2000-02-22 08:43:59 -07:00
{
2001-02-15 01:12:14 -07:00
drm_mga_private_t *dev_priv = dev->dev_private;
drm_mga_freelist_t *entry;
drm_mga_freelist_t *next;
DRM_DEBUG("\n");
2001-02-15 01:12:14 -07:00
entry = dev_priv->head;
while (entry) {
2001-02-15 01:12:14 -07:00
next = entry->next;
drm_free(entry, sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
2001-02-15 01:12:14 -07:00
entry = next;
}
dev_priv->head = dev_priv->tail = NULL;
2000-02-22 08:43:59 -07:00
}
#if 0
/* FIXME: Still needed?
*/
static void mga_freelist_reset(drm_device_t * dev)
2000-02-22 08:43:59 -07:00
{
2001-02-15 01:12:14 -07:00
drm_device_dma_t *dma = dev->dma;
drm_buf_t *buf;
drm_mga_buf_priv_t *buf_priv;
int i;
for (i = 0; i < dma->buf_count; i++) {
2001-02-15 01:12:14 -07:00
buf = dma->buflist[i];
buf_priv = buf->dev_private;
SET_AGE(&buf_priv->list_entry->age, MGA_BUFFER_FREE, 0);
2001-02-15 01:12:14 -07:00
}
2000-02-22 08:43:59 -07:00
}
#endif
2000-02-22 08:43:59 -07:00
static drm_buf_t *mga_freelist_get(drm_device_t * dev)
2000-02-22 08:43:59 -07:00
{
2001-02-15 01:12:14 -07:00
drm_mga_private_t *dev_priv = dev->dev_private;
drm_mga_freelist_t *next;
drm_mga_freelist_t *prev;
drm_mga_freelist_t *tail = dev_priv->tail;
u32 head, wrap;
DRM_DEBUG("\n");
2000-09-06 14:56:34 -06:00
head = MGA_READ(MGA_PRIMADDRESS);
2001-02-15 01:12:14 -07:00
wrap = dev_priv->sarea_priv->last_wrap;
DRM_DEBUG(" tail=0x%06lx %d\n",
tail->age.head ?
tail->age.head - dev_priv->primary->offset : 0,
tail->age.wrap);
DRM_DEBUG(" head=0x%06lx %d\n",
head - dev_priv->primary->offset, wrap);
2000-02-22 08:43:59 -07:00
if (TEST_AGE(&tail->age, head, wrap)) {
2001-02-15 01:12:14 -07:00
prev = dev_priv->tail->prev;
next = dev_priv->tail;
prev->next = NULL;
next->prev = next->next = NULL;
dev_priv->tail = prev;
SET_AGE(&next->age, MGA_BUFFER_USED, 0);
2001-02-15 01:12:14 -07:00
return next->buf;
}
2000-04-04 16:08:14 -06:00
DRM_DEBUG("returning NULL!\n");
2001-02-15 01:12:14 -07:00
return NULL;
}
2000-04-04 16:08:14 -06:00
int mga_freelist_put(drm_device_t * dev, drm_buf_t * buf)
2001-02-15 01:12:14 -07:00
{
drm_mga_private_t *dev_priv = dev->dev_private;
drm_mga_buf_priv_t *buf_priv = buf->dev_private;
2001-03-12 11:18:06 -07:00
drm_mga_freelist_t *head, *entry, *prev;
2001-02-15 01:12:14 -07:00
DRM_DEBUG("age=0x%06lx wrap=%d\n",
buf_priv->list_entry->age.head -
dev_priv->primary->offset, buf_priv->list_entry->age.wrap);
2001-02-15 01:12:14 -07:00
2001-03-12 11:18:06 -07:00
entry = buf_priv->list_entry;
2001-02-15 01:12:14 -07:00
head = dev_priv->head;
if (buf_priv->list_entry->age.head == MGA_BUFFER_USED) {
SET_AGE(&entry->age, MGA_BUFFER_FREE, 0);
2001-03-12 11:18:06 -07:00
prev = dev_priv->tail;
prev->next = entry;
entry->prev = prev;
entry->next = NULL;
} else {
prev = head->next;
head->next = entry;
prev->prev = entry;
entry->prev = head;
entry->next = prev;
}
2000-04-04 16:08:14 -06:00
return 0;
}
2001-02-15 01:12:14 -07:00
/* ================================================================
* DMA initialization, cleanup
*/
int mga_driver_preinit(drm_device_t *dev, unsigned long flags)
2001-02-15 01:12:14 -07:00
{
drm_mga_private_t * dev_priv;
dev_priv = drm_alloc(sizeof(drm_mga_private_t), DRM_MEM_DRIVER);
if (!dev_priv)
2002-07-05 02:31:11 -06:00
return DRM_ERR(ENOMEM);
2000-04-04 16:08:14 -06:00
dev->dev_private = (void *)dev_priv;
memset(dev_priv, 0, sizeof(drm_mga_private_t));
2000-04-04 16:08:14 -06:00
2001-02-15 01:12:14 -07:00
dev_priv->usec_timeout = MGA_DEFAULT_USEC_TIMEOUT;
dev_priv->chipset = flags;
return 0;
}
static int mga_do_init_dma(drm_device_t * dev, drm_mga_init_t * init)
{
drm_mga_private_t *dev_priv;
int ret;
DRM_DEBUG("\n");
dev_priv = dev->dev_private;
2001-02-15 01:12:14 -07:00
if (init->sgram) {
2001-02-15 01:12:14 -07:00
dev_priv->clear_cmd = MGA_DWGCTL_CLEAR | MGA_ATYPE_BLK;
} else {
dev_priv->clear_cmd = MGA_DWGCTL_CLEAR | MGA_ATYPE_RSTR;
2000-02-22 08:43:59 -07:00
}
dev_priv->maccess = init->maccess;
2000-09-06 14:56:34 -06:00
dev_priv->fb_cpp = init->fb_cpp;
dev_priv->front_offset = init->front_offset;
dev_priv->front_pitch = init->front_pitch;
dev_priv->back_offset = init->back_offset;
dev_priv->back_pitch = init->back_pitch;
2000-02-22 08:43:59 -07:00
dev_priv->depth_cpp = init->depth_cpp;
dev_priv->depth_offset = init->depth_offset;
dev_priv->depth_pitch = init->depth_pitch;
2001-02-15 01:12:14 -07:00
/* FIXME: Need to support AGP textures...
*/
dev_priv->texture_offset = init->texture_offset[0];
dev_priv->texture_size = init->texture_size[0];
2002-07-05 02:31:11 -06:00
DRM_GETSAREA();
if (!dev_priv->sarea) {
DRM_ERROR("failed to find sarea!\n");
mga_do_cleanup_dma(dev);
2002-07-05 02:31:11 -06:00
return DRM_ERR(EINVAL);
}
2001-02-15 01:12:14 -07:00
2004-08-17 07:10:05 -06:00
dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset);
if (!dev_priv->mmio) {
DRM_ERROR("failed to find mmio region!\n");
mga_do_cleanup_dma(dev);
2002-07-05 02:31:11 -06:00
return DRM_ERR(EINVAL);
}
2004-08-17 07:10:05 -06:00
dev_priv->status = drm_core_findmap(dev, init->status_offset);
if (!dev_priv->status) {
DRM_ERROR("failed to find status page!\n");
mga_do_cleanup_dma(dev);
2002-07-05 02:31:11 -06:00
return DRM_ERR(EINVAL);
}
2004-08-17 07:10:05 -06:00
dev_priv->warp = drm_core_findmap(dev, init->warp_offset);
if (!dev_priv->warp) {
DRM_ERROR("failed to find warp microcode region!\n");
mga_do_cleanup_dma(dev);
2002-07-05 02:31:11 -06:00
return DRM_ERR(EINVAL);
}
2004-08-17 07:10:05 -06:00
dev_priv->primary = drm_core_findmap(dev, init->primary_offset);
if (!dev_priv->primary) {
DRM_ERROR("failed to find primary dma region!\n");
mga_do_cleanup_dma(dev);
2002-07-05 02:31:11 -06:00
return DRM_ERR(EINVAL);
}
2004-08-17 07:10:05 -06:00
dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
if (!dev->agp_buffer_map) {
DRM_ERROR("failed to find dma buffer region!\n");
mga_do_cleanup_dma(dev);
2002-07-05 02:31:11 -06:00
return DRM_ERR(EINVAL);
}
2001-02-15 01:12:14 -07:00
dev_priv->sarea_priv =
(drm_mga_sarea_t *) ((u8 *) dev_priv->sarea->handle +
init->sarea_priv_offset);
2001-02-15 01:12:14 -07:00
drm_core_ioremap(dev_priv->warp, dev);
drm_core_ioremap(dev_priv->primary, dev);
drm_core_ioremap(dev->agp_buffer_map, dev);
2001-02-15 01:12:14 -07:00
if (!dev_priv->warp->handle ||
!dev_priv->primary->handle || !dev->agp_buffer_map->handle) {
DRM_ERROR("failed to ioremap agp regions!\n");
mga_do_cleanup_dma(dev);
2002-07-05 02:31:11 -06:00
return DRM_ERR(ENOMEM);
}
ret = mga_warp_install_microcode(dev_priv);
if (ret < 0) {
DRM_ERROR("failed to install WARP ucode!\n");
mga_do_cleanup_dma(dev);
2001-02-15 01:12:14 -07:00
return ret;
2000-02-22 08:43:59 -07:00
}
2001-02-15 01:12:14 -07:00
ret = mga_warp_init(dev_priv);
if (ret < 0) {
DRM_ERROR("failed to init WARP engine!\n");
mga_do_cleanup_dma(dev);
2001-02-15 01:12:14 -07:00
return ret;
2000-04-04 16:08:14 -06:00
}
dev_priv->prim.status = (u32 *) dev_priv->status->handle;
2000-04-04 16:08:14 -06:00
mga_do_wait_for_idle(dev_priv);
2001-02-15 01:12:14 -07:00
/* Init the primary DMA registers.
*/
MGA_WRITE(MGA_PRIMADDRESS, dev_priv->primary->offset | MGA_DMA_GENERAL);
2001-03-19 05:04:12 -07:00
#if 0
MGA_WRITE(MGA_PRIMPTR, virt_to_bus((void *)dev_priv->prim.status) | MGA_PRIMPTREN0 | /* Soft trap, SECEND, SETUPEND */
MGA_PRIMPTREN1); /* DWGSYNC */
2001-03-19 05:04:12 -07:00
#endif
2000-04-04 16:08:14 -06:00
dev_priv->prim.start = (u8 *) dev_priv->primary->handle;
dev_priv->prim.end = ((u8 *) dev_priv->primary->handle
2001-02-15 01:12:14 -07:00
+ dev_priv->primary->size);
dev_priv->prim.size = dev_priv->primary->size;
2000-09-06 14:56:34 -06:00
2001-02-15 01:12:14 -07:00
dev_priv->prim.tail = 0;
dev_priv->prim.space = dev_priv->prim.size;
dev_priv->prim.wrapped = 0;
2000-04-04 16:08:14 -06:00
2001-02-15 01:12:14 -07:00
dev_priv->prim.last_flush = 0;
dev_priv->prim.last_wrap = 0;
2000-09-06 14:56:34 -06:00
2001-02-15 01:12:14 -07:00
dev_priv->prim.high_mark = 256 * DMA_BLOCK_SIZE;
2001-02-15 01:12:14 -07:00
dev_priv->prim.status[0] = dev_priv->primary->offset;
dev_priv->prim.status[1] = 0;
2000-09-06 14:56:34 -06:00
2001-02-15 01:12:14 -07:00
dev_priv->sarea_priv->last_wrap = 0;
dev_priv->sarea_priv->last_frame.head = 0;
dev_priv->sarea_priv->last_frame.wrap = 0;
if (mga_freelist_init(dev, dev_priv) < 0) {
DRM_ERROR("could not initialize freelist\n");
mga_do_cleanup_dma(dev);
2002-07-05 02:31:11 -06:00
return DRM_ERR(ENOMEM);
2000-04-04 16:08:14 -06:00
}
2001-02-15 01:12:14 -07:00
return 0;
}
static int mga_do_cleanup_dma(drm_device_t * dev)
2001-02-15 01:12:14 -07:00
{
DRM_DEBUG("\n");
2001-02-15 01:12:14 -07:00
/* Make sure interrupts are disabled here because the uninstall ioctl
* may not have been called from userspace and after dev_private
* is freed, it's too late.
*/
if (dev->irq_enabled)
drm_irq_uninstall(dev);
if (dev->dev_private) {
2001-02-15 01:12:14 -07:00
drm_mga_private_t *dev_priv = dev->dev_private;
if (dev_priv->warp != NULL)
drm_core_ioremapfree(dev_priv->warp, dev);
if (dev_priv->primary != NULL)
drm_core_ioremapfree(dev_priv->primary, dev);
if (dev->agp_buffer_map != NULL) {
drm_core_ioremapfree(dev->agp_buffer_map, dev);
dev->agp_buffer_map = NULL;
}
2001-02-15 01:12:14 -07:00
if (dev_priv->head != NULL) {
mga_freelist_cleanup(dev);
2001-02-15 01:12:14 -07:00
}
drm_free(dev->dev_private, sizeof(drm_mga_private_t),
DRM_MEM_DRIVER);
2001-02-15 01:12:14 -07:00
dev->dev_private = NULL;
2000-04-04 16:08:14 -06:00
}
2001-02-15 01:12:14 -07:00
2000-04-04 16:08:14 -06:00
return 0;
}
int mga_dma_init(DRM_IOCTL_ARGS)
2000-04-04 16:08:14 -06:00
{
2002-07-05 02:31:11 -06:00
DRM_DEVICE;
2000-04-04 16:08:14 -06:00
drm_mga_init_t init;
2000-09-06 14:56:34 -06:00
LOCK_TEST_WITH_RETURN(dev, filp);
DRM_COPY_FROM_USER_IOCTL(init, (drm_mga_init_t __user *) data,
sizeof(init));
2000-09-06 14:56:34 -06:00
switch (init.func) {
2000-04-04 16:08:14 -06:00
case MGA_INIT_DMA:
return mga_do_init_dma(dev, &init);
2000-04-04 16:08:14 -06:00
case MGA_CLEANUP_DMA:
return mga_do_cleanup_dma(dev);
2000-04-04 16:08:14 -06:00
}
2002-07-05 02:31:11 -06:00
return DRM_ERR(EINVAL);
2000-02-22 08:43:59 -07:00
}
2001-02-15 01:12:14 -07:00
/* ================================================================
* Primary DMA stream management
*/
2000-02-22 08:43:59 -07:00
int mga_dma_flush(DRM_IOCTL_ARGS)
2000-02-22 08:43:59 -07:00
{
2002-07-05 02:31:11 -06:00
DRM_DEVICE;
drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
2001-02-15 01:12:14 -07:00
drm_lock_t lock;
2000-02-22 08:43:59 -07:00
LOCK_TEST_WITH_RETURN(dev, filp);
2000-09-06 14:56:34 -06:00
DRM_COPY_FROM_USER_IOCTL(lock, (drm_lock_t __user *) data,
sizeof(lock));
DRM_DEBUG("%s%s%s\n",
(lock.flags & _DRM_LOCK_FLUSH) ? "flush, " : "",
(lock.flags & _DRM_LOCK_FLUSH_ALL) ? "flush all, " : "",
(lock.flags & _DRM_LOCK_QUIESCENT) ? "idle, " : "");
2001-02-15 01:12:14 -07:00
WRAP_WAIT_WITH_RETURN(dev_priv);
2001-02-15 01:12:14 -07:00
if (lock.flags & (_DRM_LOCK_FLUSH | _DRM_LOCK_FLUSH_ALL)) {
mga_do_dma_flush(dev_priv);
2000-02-22 08:43:59 -07:00
}
if (lock.flags & _DRM_LOCK_QUIESCENT) {
#if MGA_DMA_DEBUG
int ret = mga_do_wait_for_idle(dev_priv);
if (ret < 0)
DRM_INFO("%s: -EBUSY\n", __FUNCTION__);
return ret;
#else
return mga_do_wait_for_idle(dev_priv);
#endif
2001-02-15 01:12:14 -07:00
} else {
return 0;
2000-04-04 16:08:14 -06:00
}
2000-02-22 08:43:59 -07:00
}
int mga_dma_reset(DRM_IOCTL_ARGS)
2000-04-04 16:08:14 -06:00
{
2002-07-05 02:31:11 -06:00
DRM_DEVICE;
drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
2001-02-15 01:12:14 -07:00
LOCK_TEST_WITH_RETURN(dev, filp);
2001-02-15 01:12:14 -07:00
return mga_do_dma_reset(dev_priv);
2000-04-04 16:08:14 -06:00
}
2001-02-15 01:12:14 -07:00
/* ================================================================
* DMA buffer management
*/
2000-02-22 08:43:59 -07:00
static int mga_dma_get_buffers(DRMFILE filp, drm_device_t * dev, drm_dma_t * d)
2001-02-15 01:12:14 -07:00
{
drm_buf_t *buf;
int i;
2000-09-06 14:56:34 -06:00
for (i = d->granted_count; i < d->request_count; i++) {
buf = mga_freelist_get(dev);
if (!buf)
return DRM_ERR(EAGAIN);
2000-09-06 14:56:34 -06:00
2003-03-28 07:27:37 -07:00
buf->filp = filp;
2000-02-22 08:43:59 -07:00
if (DRM_COPY_TO_USER(&d->request_indices[i],
&buf->idx, sizeof(buf->idx)))
2002-07-05 02:31:11 -06:00
return DRM_ERR(EFAULT);
if (DRM_COPY_TO_USER(&d->request_sizes[i],
&buf->total, sizeof(buf->total)))
2002-07-05 02:31:11 -06:00
return DRM_ERR(EFAULT);
2000-09-06 14:56:34 -06:00
2001-02-15 01:12:14 -07:00
d->granted_count++;
2000-02-22 08:43:59 -07:00
}
2001-02-15 01:12:14 -07:00
return 0;
2000-02-22 08:43:59 -07:00
}
2000-09-06 14:56:34 -06:00
int mga_dma_buffers(DRM_IOCTL_ARGS)
2000-04-04 16:08:14 -06:00
{
2002-07-05 02:31:11 -06:00
DRM_DEVICE;
2001-02-15 01:12:14 -07:00
drm_device_dma_t *dma = dev->dma;
drm_mga_private_t *dev_priv = (drm_mga_private_t *) dev->dev_private;
drm_dma_t __user *argp = (void __user *)data;
2001-02-15 01:12:14 -07:00
drm_dma_t d;
int ret = 0;
LOCK_TEST_WITH_RETURN(dev, filp);
DRM_COPY_FROM_USER_IOCTL(d, argp, sizeof(d));
2000-04-04 16:08:14 -06:00
2001-02-15 01:12:14 -07:00
/* Please don't send us buffers.
*/
if (d.send_count != 0) {
DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n",
DRM_CURRENTPID, d.send_count);
2002-07-05 02:31:11 -06:00
return DRM_ERR(EINVAL);
2000-04-04 16:08:14 -06:00
}
2001-02-15 01:12:14 -07:00
/* We'll send you buffers.
*/
if (d.request_count < 0 || d.request_count > dma->buf_count) {
DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n",
DRM_CURRENTPID, d.request_count, dma->buf_count);
2002-07-05 02:31:11 -06:00
return DRM_ERR(EINVAL);
2001-02-15 01:12:14 -07:00
}
2000-07-11 05:41:07 -06:00
WRAP_TEST_WITH_RETURN(dev_priv);
2001-02-15 01:12:14 -07:00
d.granted_count = 0;
if (d.request_count) {
ret = mga_dma_get_buffers(filp, dev, &d);
2000-04-04 16:08:14 -06:00
}
DRM_COPY_TO_USER_IOCTL(argp, d, sizeof(d));
2001-02-15 01:12:14 -07:00
return ret;
2000-04-04 16:08:14 -06:00
}
2004-08-17 07:10:05 -06:00
int mga_driver_postcleanup(drm_device_t * dev)
2004-08-17 07:10:05 -06:00
{
return mga_do_cleanup_dma(dev);
2004-08-17 07:10:05 -06:00
}
int mga_driver_dma_quiescent(drm_device_t * dev)
2004-08-17 07:10:05 -06:00
{
drm_mga_private_t *dev_priv = dev->dev_private;
return mga_do_wait_for_idle(dev_priv);
2004-08-17 07:10:05 -06:00
}