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.
|
|
|
|
*
|
2000-06-08 08:38:22 -06:00
|
|
|
* Authors: Rickard E. (Rik) Faith <faith@valinux.com>
|
|
|
|
* Jeff Hartmann <jhartmann@valinux.com>
|
|
|
|
* Keith Whitwell <keithw@valinux.com>
|
2000-02-22 08:43:59 -07:00
|
|
|
*
|
|
|
|
*/
|
2000-09-24 03:34:10 -06:00
|
|
|
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/linux/drm/kernel/mga_dma.c,v 1.5 2000/08/28 02:43:15 tsi Exp $ */
|
2000-02-22 08:43:59 -07:00
|
|
|
|
|
|
|
#define __NO_VERSION__
|
|
|
|
#include "drmP.h"
|
|
|
|
#include "mga_drv.h"
|
|
|
|
|
|
|
|
#include <linux/interrupt.h> /* For task queue support */
|
|
|
|
|
|
|
|
#define MGA_REG(reg) 2
|
|
|
|
#define MGA_BASE(reg) ((unsigned long) \
|
|
|
|
((drm_device_t *)dev)->maplist[MGA_REG(reg)]->handle)
|
|
|
|
#define MGA_ADDR(reg) (MGA_BASE(reg) + reg)
|
|
|
|
#define MGA_DEREF(reg) *(__volatile__ int *)MGA_ADDR(reg)
|
|
|
|
#define MGA_READ(reg) MGA_DEREF(reg)
|
|
|
|
#define MGA_WRITE(reg,val) do { MGA_DEREF(reg) = val; } while (0)
|
|
|
|
|
|
|
|
#define PDEA_pagpxfer_enable 0x2
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
static int mga_flush_queue(drm_device_t *dev);
|
2000-02-22 08:43:59 -07:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
static unsigned long mga_alloc_page(drm_device_t *dev)
|
|
|
|
{
|
|
|
|
unsigned long address;
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
2000-04-04 16:08:14 -06:00
|
|
|
address = __get_free_page(GFP_KERNEL);
|
|
|
|
if(address == 0UL) {
|
|
|
|
return 0;
|
|
|
|
}
|
2000-08-08 10:04:21 -06:00
|
|
|
atomic_inc(&virt_to_page(address)->count);
|
|
|
|
set_bit(PG_locked, &virt_to_page(address)->flags);
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
return address;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mga_free_page(drm_device_t *dev, unsigned long page)
|
|
|
|
{
|
2000-05-25 15:06:02 -06:00
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
if(page == 0UL) {
|
|
|
|
return;
|
|
|
|
}
|
2000-08-08 10:04:21 -06:00
|
|
|
atomic_dec(&virt_to_page(page)->count);
|
|
|
|
clear_bit(PG_locked, &virt_to_page(page)->flags);
|
|
|
|
wake_up(&virt_to_page(page)->wait);
|
2000-04-04 16:08:14 -06:00
|
|
|
free_page(page);
|
|
|
|
return;
|
|
|
|
}
|
2000-02-22 08:43:59 -07:00
|
|
|
|
|
|
|
static void mga_delay(void)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
/* These are two age tags that will never be sent to
|
|
|
|
* the hardware */
|
|
|
|
#define MGA_BUF_USED 0xffffffff
|
|
|
|
#define MGA_BUF_FREE 0
|
|
|
|
|
|
|
|
static int mga_freelist_init(drm_device_t *dev)
|
|
|
|
{
|
|
|
|
drm_device_dma_t *dma = dev->dma;
|
|
|
|
drm_buf_t *buf;
|
|
|
|
drm_mga_buf_priv_t *buf_priv;
|
|
|
|
drm_mga_private_t *dev_priv = (drm_mga_private_t *)dev->dev_private;
|
|
|
|
drm_mga_freelist_t *item;
|
|
|
|
int i;
|
2000-05-25 15:06:02 -06:00
|
|
|
|
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
dev_priv->head = drm_alloc(sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
|
|
|
|
if(dev_priv->head == NULL) return -ENOMEM;
|
|
|
|
memset(dev_priv->head, 0, sizeof(drm_mga_freelist_t));
|
|
|
|
dev_priv->head->age = MGA_BUF_USED;
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
for (i = 0; i < dma->buf_count; i++) {
|
|
|
|
buf = dma->buflist[ i ];
|
|
|
|
buf_priv = buf->dev_private;
|
|
|
|
item = drm_alloc(sizeof(drm_mga_freelist_t),
|
|
|
|
DRM_MEM_DRIVER);
|
|
|
|
if(item == NULL) return -ENOMEM;
|
|
|
|
memset(item, 0, sizeof(drm_mga_freelist_t));
|
|
|
|
item->age = MGA_BUF_FREE;
|
|
|
|
item->prev = dev_priv->head;
|
|
|
|
item->next = dev_priv->head->next;
|
|
|
|
if(dev_priv->head->next != NULL)
|
|
|
|
dev_priv->head->next->prev = item;
|
|
|
|
if(item->next == NULL) dev_priv->tail = item;
|
|
|
|
item->buf = buf;
|
|
|
|
buf_priv->my_freelist = item;
|
|
|
|
buf_priv->discard = 0;
|
2000-05-25 15:06:02 -06:00
|
|
|
buf_priv->dispatched = 0;
|
2000-04-04 16:08:14 -06:00
|
|
|
dev_priv->head->next = item;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
return 0;
|
|
|
|
}
|
2000-02-22 08:43:59 -07:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
static void mga_freelist_cleanup(drm_device_t *dev)
|
|
|
|
{
|
|
|
|
drm_mga_private_t *dev_priv = (drm_mga_private_t *)dev->dev_private;
|
|
|
|
drm_mga_freelist_t *item;
|
|
|
|
drm_mga_freelist_t *prev;
|
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
item = dev_priv->head;
|
|
|
|
while(item) {
|
|
|
|
prev = item;
|
|
|
|
item = item->next;
|
|
|
|
drm_free(prev, sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
|
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
dev_priv->head = dev_priv->tail = NULL;
|
|
|
|
}
|
2000-02-22 08:43:59 -07:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
/* Frees dispatch lock */
|
|
|
|
static inline void mga_dma_quiescent(drm_device_t *dev)
|
|
|
|
{
|
|
|
|
drm_device_dma_t *dma = dev->dma;
|
|
|
|
drm_mga_private_t *dev_priv = (drm_mga_private_t *)dev->dev_private;
|
|
|
|
drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
|
|
|
|
unsigned long end;
|
|
|
|
int i;
|
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
2000-04-04 16:08:14 -06:00
|
|
|
end = jiffies + (HZ*3);
|
|
|
|
while(1) {
|
2000-09-06 14:56:34 -06:00
|
|
|
if(!test_and_set_bit(MGA_IN_DISPATCH,
|
2000-05-25 15:06:02 -06:00
|
|
|
&dev_priv->dispatch_status)) {
|
2000-04-04 16:08:14 -06:00
|
|
|
break;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
2000-04-04 16:08:14 -06:00
|
|
|
if((signed)(end - jiffies) <= 0) {
|
2000-09-06 14:56:34 -06:00
|
|
|
DRM_ERROR("irqs: %d wanted %d\n",
|
|
|
|
atomic_read(&dev->total_irq),
|
2000-04-04 16:08:14 -06:00
|
|
|
atomic_read(&dma->total_lost));
|
2000-09-06 14:56:34 -06:00
|
|
|
DRM_ERROR("lockup\n");
|
2000-04-04 16:08:14 -06:00
|
|
|
goto out_nolock;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
2000-04-04 16:08:14 -06:00
|
|
|
for (i = 0 ; i < 2000 ; i++) mga_delay();
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
2000-04-04 16:08:14 -06:00
|
|
|
end = jiffies + (HZ*3);
|
|
|
|
DRM_DEBUG("quiescent status : %x\n", MGA_READ(MGAREG_STATUS));
|
|
|
|
while((MGA_READ(MGAREG_STATUS) & 0x00030001) != 0x00020000) {
|
|
|
|
if((signed)(end - jiffies) <= 0) {
|
2000-09-06 14:56:34 -06:00
|
|
|
DRM_ERROR("irqs: %d wanted %d\n",
|
|
|
|
atomic_read(&dev->total_irq),
|
2000-04-04 16:08:14 -06:00
|
|
|
atomic_read(&dma->total_lost));
|
2000-09-06 14:56:34 -06:00
|
|
|
DRM_ERROR("lockup\n");
|
2000-04-04 16:08:14 -06:00
|
|
|
goto out_status;
|
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
for (i = 0 ; i < 2000 ; i++) mga_delay();
|
2000-04-04 16:08:14 -06:00
|
|
|
}
|
|
|
|
sarea_priv->dirty |= MGA_DMA_FLUSH;
|
|
|
|
|
|
|
|
out_status:
|
2000-05-25 15:06:02 -06:00
|
|
|
clear_bit(MGA_IN_DISPATCH, &dev_priv->dispatch_status);
|
2000-04-04 16:08:14 -06:00
|
|
|
out_nolock:
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
static void mga_reset_freelist(drm_device_t *dev)
|
2000-02-22 08:43:59 -07:00
|
|
|
{
|
2000-05-25 15:06:02 -06:00
|
|
|
drm_device_dma_t *dma = dev->dma;
|
|
|
|
drm_buf_t *buf;
|
2000-04-04 16:08:14 -06:00
|
|
|
drm_mga_buf_priv_t *buf_priv;
|
2000-05-25 15:06:02 -06:00
|
|
|
int i;
|
2000-02-22 08:43:59 -07:00
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
for (i = 0; i < dma->buf_count; i++) {
|
|
|
|
buf = dma->buflist[ i ];
|
|
|
|
buf_priv = buf->dev_private;
|
|
|
|
buf_priv->my_freelist->age = MGA_BUF_FREE;
|
|
|
|
}
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
/* Least recently used :
|
2000-09-06 14:56:34 -06:00
|
|
|
* These operations are not atomic b/c they are protected by the
|
2000-04-04 16:08:14 -06:00
|
|
|
* hardware lock */
|
|
|
|
|
|
|
|
drm_buf_t *mga_freelist_get(drm_device_t *dev)
|
2000-02-22 08:43:59 -07:00
|
|
|
{
|
2000-05-25 15:06:02 -06:00
|
|
|
DECLARE_WAITQUEUE(entry, current);
|
2000-09-06 14:56:34 -06:00
|
|
|
drm_mga_private_t *dev_priv =
|
2000-04-04 16:08:14 -06:00
|
|
|
(drm_mga_private_t *) dev->dev_private;
|
|
|
|
drm_mga_freelist_t *prev;
|
|
|
|
drm_mga_freelist_t *next;
|
2000-05-25 15:06:02 -06:00
|
|
|
static int failed = 0;
|
2000-09-13 09:00:09 -06:00
|
|
|
int return_null = 0;
|
2000-05-25 15:06:02 -06:00
|
|
|
|
|
|
|
DRM_DEBUG("%s : tail->age : %d last_prim_age : %d\n", __FUNCTION__,
|
|
|
|
dev_priv->tail->age, dev_priv->last_prim_age);
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
if(failed >= 1000 && dev_priv->tail->age >= dev_priv->last_prim_age) {
|
2000-09-06 14:56:34 -06:00
|
|
|
DRM_DEBUG("I'm waiting on the freelist!!! %d\n",
|
2000-05-25 15:06:02 -06:00
|
|
|
dev_priv->last_prim_age);
|
|
|
|
set_bit(MGA_IN_GETBUF, &dev_priv->dispatch_status);
|
|
|
|
add_wait_queue(&dev_priv->buf_queue, &entry);
|
|
|
|
for (;;) {
|
|
|
|
mga_dma_schedule(dev, 0);
|
2000-09-19 13:41:07 -06:00
|
|
|
current->state = TASK_INTERRUPTIBLE;
|
2000-09-06 14:56:34 -06:00
|
|
|
if(!test_bit(MGA_IN_GETBUF,
|
|
|
|
&dev_priv->dispatch_status))
|
2000-05-25 15:06:02 -06:00
|
|
|
break;
|
|
|
|
atomic_inc(&dev->total_sleeps);
|
|
|
|
schedule();
|
|
|
|
if (signal_pending(current)) {
|
2000-09-13 09:00:09 -06:00
|
|
|
++return_null;
|
2000-05-25 15:06:02 -06:00
|
|
|
clear_bit(MGA_IN_GETBUF,
|
|
|
|
&dev_priv->dispatch_status);
|
2000-09-13 09:00:09 -06:00
|
|
|
break;
|
2000-05-25 15:06:02 -06:00
|
|
|
}
|
|
|
|
}
|
2000-09-19 13:24:28 -06:00
|
|
|
current->state = TASK_RUNNING;
|
2000-05-25 15:06:02 -06:00
|
|
|
remove_wait_queue(&dev_priv->buf_queue, &entry);
|
2000-09-13 09:00:09 -06:00
|
|
|
if (return_null) return NULL;
|
2000-05-25 15:06:02 -06:00
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
if(dev_priv->tail->age < dev_priv->last_prim_age) {
|
2000-04-04 16:08:14 -06:00
|
|
|
prev = dev_priv->tail->prev;
|
|
|
|
next = dev_priv->tail;
|
|
|
|
prev->next = NULL;
|
|
|
|
next->prev = next->next = NULL;
|
|
|
|
dev_priv->tail = prev;
|
|
|
|
next->age = MGA_BUF_USED;
|
2000-05-25 15:06:02 -06:00
|
|
|
failed = 0;
|
2000-04-04 16:08:14 -06:00
|
|
|
return next->buf;
|
2000-05-25 15:06:02 -06:00
|
|
|
}
|
|
|
|
failed++;
|
2000-04-04 16:08:14 -06:00
|
|
|
return NULL;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
int mga_freelist_put(drm_device_t *dev, drm_buf_t *buf)
|
2000-02-22 08:43:59 -07:00
|
|
|
{
|
2000-09-06 14:56:34 -06:00
|
|
|
drm_mga_private_t *dev_priv =
|
2000-04-04 16:08:14 -06:00
|
|
|
(drm_mga_private_t *) dev->dev_private;
|
2000-02-22 08:43:59 -07:00
|
|
|
drm_mga_buf_priv_t *buf_priv = buf->dev_private;
|
2000-04-04 16:08:14 -06:00
|
|
|
drm_mga_freelist_t *prev;
|
|
|
|
drm_mga_freelist_t *head;
|
|
|
|
drm_mga_freelist_t *next;
|
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
if(buf_priv->my_freelist->age == MGA_BUF_USED) {
|
|
|
|
/* Discarded buffer, put it on the tail */
|
|
|
|
next = buf_priv->my_freelist;
|
|
|
|
next->age = MGA_BUF_FREE;
|
|
|
|
prev = dev_priv->tail;
|
|
|
|
prev->next = next;
|
|
|
|
next->prev = prev;
|
|
|
|
next->next = NULL;
|
|
|
|
dev_priv->tail = next;
|
|
|
|
DRM_DEBUG("Discarded\n");
|
2000-02-22 08:43:59 -07:00
|
|
|
} else {
|
2000-04-04 16:08:14 -06:00
|
|
|
/* Normally aged buffer, put it on the head + 1,
|
|
|
|
* as the real head is a sentinal element
|
|
|
|
*/
|
|
|
|
next = buf_priv->my_freelist;
|
|
|
|
head = dev_priv->head;
|
|
|
|
prev = head->next;
|
|
|
|
head->next = next;
|
|
|
|
prev->prev = next;
|
|
|
|
next->prev = head;
|
|
|
|
next->next = prev;
|
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
return 0;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
static int mga_init_primary_bufs(drm_device_t *dev, drm_mga_init_t *init)
|
2000-02-22 08:43:59 -07:00
|
|
|
{
|
|
|
|
drm_mga_private_t *dev_priv = dev->dev_private;
|
2000-04-04 16:08:14 -06:00
|
|
|
drm_mga_prim_buf_t *prim_buffer;
|
|
|
|
int i, temp, size_of_buf;
|
|
|
|
int offset = init->reserved_map_agpstart;
|
2000-02-22 08:43:59 -07:00
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
2000-09-06 14:56:34 -06:00
|
|
|
dev_priv->primary_size = ((init->primary_size + PAGE_SIZE - 1) /
|
2000-04-04 16:08:14 -06:00
|
|
|
PAGE_SIZE) * PAGE_SIZE;
|
|
|
|
size_of_buf = dev_priv->primary_size / MGA_NUM_PRIM_BUFS;
|
|
|
|
dev_priv->warp_ucode_size = init->warp_ucode_size;
|
2000-09-06 14:56:34 -06:00
|
|
|
dev_priv->prim_bufs = drm_alloc(sizeof(drm_mga_prim_buf_t *) *
|
|
|
|
(MGA_NUM_PRIM_BUFS + 1),
|
2000-04-04 16:08:14 -06:00
|
|
|
DRM_MEM_DRIVER);
|
|
|
|
if(dev_priv->prim_bufs == NULL) {
|
|
|
|
DRM_ERROR("Unable to allocate memory for prim_buf\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
memset(dev_priv->prim_bufs,
|
2000-04-04 16:08:14 -06:00
|
|
|
0, sizeof(drm_mga_prim_buf_t *) * (MGA_NUM_PRIM_BUFS + 1));
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
temp = init->warp_ucode_size + dev_priv->primary_size;
|
|
|
|
temp = ((temp + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE;
|
2000-09-06 14:56:34 -06:00
|
|
|
|
|
|
|
dev_priv->ioremap = drm_ioremap(dev->agp->base + offset,
|
2000-04-04 16:08:14 -06:00
|
|
|
temp);
|
|
|
|
if(dev_priv->ioremap == NULL) {
|
|
|
|
DRM_DEBUG("Ioremap failed\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
init_waitqueue_head(&dev_priv->wait_queue);
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
for(i = 0; i < MGA_NUM_PRIM_BUFS; i++) {
|
2000-09-06 14:56:34 -06:00
|
|
|
prim_buffer = drm_alloc(sizeof(drm_mga_prim_buf_t),
|
2000-04-04 16:08:14 -06:00
|
|
|
DRM_MEM_DRIVER);
|
|
|
|
if(prim_buffer == NULL) return -ENOMEM;
|
|
|
|
memset(prim_buffer, 0, sizeof(drm_mga_prim_buf_t));
|
|
|
|
prim_buffer->phys_head = offset + dev->agp->base;
|
2000-09-06 14:56:34 -06:00
|
|
|
prim_buffer->current_dma_ptr =
|
|
|
|
prim_buffer->head =
|
|
|
|
(u32 *) (dev_priv->ioremap +
|
|
|
|
offset -
|
2000-04-04 16:08:14 -06:00
|
|
|
init->reserved_map_agpstart);
|
|
|
|
prim_buffer->num_dwords = 0;
|
|
|
|
prim_buffer->max_dwords = size_of_buf / sizeof(u32);
|
|
|
|
prim_buffer->max_dwords -= 5; /* Leave room for the softrap */
|
|
|
|
prim_buffer->sec_used = 0;
|
|
|
|
prim_buffer->idx = i;
|
2000-05-25 15:06:02 -06:00
|
|
|
prim_buffer->prim_age = i + 1;
|
2000-04-04 16:08:14 -06:00
|
|
|
offset = offset + size_of_buf;
|
|
|
|
dev_priv->prim_bufs[i] = prim_buffer;
|
|
|
|
}
|
|
|
|
dev_priv->current_prim_idx = 0;
|
2000-09-06 14:56:34 -06:00
|
|
|
dev_priv->next_prim =
|
|
|
|
dev_priv->last_prim =
|
2000-04-04 16:08:14 -06:00
|
|
|
dev_priv->current_prim =
|
|
|
|
dev_priv->prim_bufs[0];
|
2000-09-06 14:56:34 -06:00
|
|
|
dev_priv->next_prim_age = 2;
|
2000-05-25 15:06:02 -06:00
|
|
|
dev_priv->last_prim_age = 1;
|
|
|
|
set_bit(MGA_BUF_IN_USE, &dev_priv->current_prim->buffer_status);
|
2000-04-04 16:08:14 -06:00
|
|
|
return 0;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
void mga_fire_primary(drm_device_t *dev, drm_mga_prim_buf_t *prim)
|
2000-02-22 08:43:59 -07:00
|
|
|
{
|
2000-04-04 16:08:14 -06:00
|
|
|
drm_mga_private_t *dev_priv = dev->dev_private;
|
|
|
|
drm_device_dma_t *dma = dev->dma;
|
|
|
|
drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
|
|
|
|
int use_agp = PDEA_pagpxfer_enable;
|
|
|
|
unsigned long end;
|
|
|
|
int i;
|
|
|
|
int next_idx;
|
|
|
|
PRIMLOCALS;
|
2000-05-25 15:06:02 -06:00
|
|
|
|
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
2000-04-04 16:08:14 -06:00
|
|
|
dev_priv->last_prim = prim;
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
/* We never check for overflow, b/c there is always room */
|
|
|
|
PRIMPTR(prim);
|
|
|
|
if(num_dwords <= 0) {
|
2000-08-30 16:34:28 -06:00
|
|
|
DRM_ERROR("num_dwords == 0 when dispatched\n");
|
2000-04-04 16:08:14 -06:00
|
|
|
goto out_prim_wait;
|
|
|
|
}
|
|
|
|
PRIMOUTREG( MGAREG_DMAPAD, 0);
|
|
|
|
PRIMOUTREG( MGAREG_DMAPAD, 0);
|
2000-05-25 15:06:02 -06:00
|
|
|
PRIMOUTREG( MGAREG_DMAPAD, 0);
|
2000-04-04 16:08:14 -06:00
|
|
|
PRIMOUTREG( MGAREG_SOFTRAP, 0);
|
|
|
|
PRIMFINISH(prim);
|
|
|
|
|
|
|
|
end = jiffies + (HZ*3);
|
|
|
|
if(sarea_priv->dirty & MGA_DMA_FLUSH) {
|
2000-09-06 14:56:34 -06:00
|
|
|
DRM_DEBUG("Dma top flush\n");
|
2000-04-04 16:08:14 -06:00
|
|
|
while((MGA_READ(MGAREG_STATUS) & 0x00030001) != 0x00020000) {
|
|
|
|
if((signed)(end - jiffies) <= 0) {
|
2000-09-06 14:56:34 -06:00
|
|
|
DRM_ERROR("irqs: %d wanted %d\n",
|
|
|
|
atomic_read(&dev->total_irq),
|
2000-04-04 16:08:14 -06:00
|
|
|
atomic_read(&dma->total_lost));
|
|
|
|
DRM_ERROR("lockup in fire primary "
|
|
|
|
"(Dma Top Flush)\n");
|
|
|
|
goto out_prim_wait;
|
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
for (i = 0 ; i < 4096 ; i++) mga_delay();
|
|
|
|
}
|
|
|
|
sarea_priv->dirty &= ~(MGA_DMA_FLUSH);
|
2000-02-22 08:43:59 -07:00
|
|
|
} else {
|
2000-04-04 16:08:14 -06:00
|
|
|
DRM_DEBUG("Status wait\n");
|
|
|
|
while((MGA_READ(MGAREG_STATUS) & 0x00020001) != 0x00020000) {
|
|
|
|
if((signed)(end - jiffies) <= 0) {
|
2000-09-06 14:56:34 -06:00
|
|
|
DRM_ERROR("irqs: %d wanted %d\n",
|
|
|
|
atomic_read(&dev->total_irq),
|
2000-04-04 16:08:14 -06:00
|
|
|
atomic_read(&dma->total_lost));
|
|
|
|
DRM_ERROR("lockup in fire primary "
|
|
|
|
"(Status Wait)\n");
|
|
|
|
goto out_prim_wait;
|
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
for (i = 0 ; i < 4096 ; i++) mga_delay();
|
|
|
|
}
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
2000-05-25 15:06:02 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
mga_flush_write_combine();
|
|
|
|
atomic_inc(&dev_priv->pending_bufs);
|
|
|
|
MGA_WRITE(MGAREG_PRIMADDRESS, phys_head | TT_GENERAL);
|
|
|
|
MGA_WRITE(MGAREG_PRIMEND, (phys_head + num_dwords * 4) | use_agp);
|
|
|
|
prim->num_dwords = 0;
|
2000-05-25 15:06:02 -06:00
|
|
|
sarea_priv->last_enqueue = prim->prim_age;
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
next_idx = prim->idx + 1;
|
2000-09-06 14:56:34 -06:00
|
|
|
if(next_idx >= MGA_NUM_PRIM_BUFS)
|
2000-04-04 16:08:14 -06:00
|
|
|
next_idx = 0;
|
|
|
|
|
|
|
|
dev_priv->next_prim = dev_priv->prim_bufs[next_idx];
|
|
|
|
return;
|
|
|
|
|
|
|
|
out_prim_wait:
|
|
|
|
prim->num_dwords = 0;
|
|
|
|
prim->sec_used = 0;
|
2000-05-25 15:06:02 -06:00
|
|
|
clear_bit(MGA_BUF_IN_USE, &prim->buffer_status);
|
2000-04-04 16:08:14 -06:00
|
|
|
wake_up_interruptible(&dev_priv->wait_queue);
|
2000-05-25 15:06:02 -06:00
|
|
|
clear_bit(MGA_BUF_SWAP_PENDING, &prim->buffer_status);
|
|
|
|
clear_bit(MGA_IN_DISPATCH, &dev_priv->dispatch_status);
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
int mga_advance_primary(drm_device_t *dev)
|
2000-02-22 08:43:59 -07:00
|
|
|
{
|
2000-04-04 16:08:14 -06:00
|
|
|
DECLARE_WAITQUEUE(entry, current);
|
|
|
|
drm_mga_private_t *dev_priv = dev->dev_private;
|
|
|
|
drm_mga_prim_buf_t *prim_buffer;
|
|
|
|
drm_device_dma_t *dma = dev->dma;
|
|
|
|
int next_prim_idx;
|
|
|
|
int ret = 0;
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
/* This needs to reset the primary buffer if available,
|
|
|
|
* we should collect stats on how many times it bites
|
|
|
|
* it's tail */
|
2000-05-25 15:06:02 -06:00
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
next_prim_idx = dev_priv->current_prim_idx + 1;
|
|
|
|
if(next_prim_idx >= MGA_NUM_PRIM_BUFS)
|
|
|
|
next_prim_idx = 0;
|
|
|
|
prim_buffer = dev_priv->prim_bufs[next_prim_idx];
|
2000-05-25 15:06:02 -06:00
|
|
|
set_bit(MGA_IN_WAIT, &dev_priv->dispatch_status);
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
/* In use is cleared in interrupt handler */
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
if(test_and_set_bit(MGA_BUF_IN_USE, &prim_buffer->buffer_status)) {
|
2000-04-04 16:08:14 -06:00
|
|
|
add_wait_queue(&dev_priv->wait_queue, &entry);
|
2000-05-25 15:06:02 -06:00
|
|
|
current->state = TASK_INTERRUPTIBLE;
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
for (;;) {
|
|
|
|
mga_dma_schedule(dev, 0);
|
2000-09-06 14:56:34 -06:00
|
|
|
if(!test_and_set_bit(MGA_BUF_IN_USE,
|
|
|
|
&prim_buffer->buffer_status))
|
2000-05-25 15:06:02 -06:00
|
|
|
break;
|
2000-04-04 16:08:14 -06:00
|
|
|
atomic_inc(&dev->total_sleeps);
|
|
|
|
atomic_inc(&dma->total_missed_sched);
|
2000-05-25 15:06:02 -06:00
|
|
|
schedule();
|
2000-04-04 16:08:14 -06:00
|
|
|
if (signal_pending(current)) {
|
|
|
|
ret = -ERESTARTSYS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
current->state = TASK_RUNNING;
|
|
|
|
remove_wait_queue(&dev_priv->wait_queue, &entry);
|
|
|
|
if(ret) return ret;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
2000-05-25 15:06:02 -06:00
|
|
|
clear_bit(MGA_IN_WAIT, &dev_priv->dispatch_status);
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
/* This primary buffer is now free to use */
|
|
|
|
prim_buffer->current_dma_ptr = prim_buffer->head;
|
|
|
|
prim_buffer->num_dwords = 0;
|
|
|
|
prim_buffer->sec_used = 0;
|
2000-05-25 15:06:02 -06:00
|
|
|
prim_buffer->prim_age = dev_priv->next_prim_age++;
|
|
|
|
if(prim_buffer->prim_age == 0 || prim_buffer->prim_age == 0xffffffff) {
|
|
|
|
mga_flush_queue(dev);
|
|
|
|
mga_dma_quiescent(dev);
|
|
|
|
mga_reset_freelist(dev);
|
|
|
|
prim_buffer->prim_age = (dev_priv->next_prim_age += 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset all buffer status stuff */
|
|
|
|
clear_bit(MGA_BUF_NEEDS_OVERFLOW, &prim_buffer->buffer_status);
|
|
|
|
clear_bit(MGA_BUF_FORCE_FIRE, &prim_buffer->buffer_status);
|
|
|
|
clear_bit(MGA_BUF_SWAP_PENDING, &prim_buffer->buffer_status);
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
dev_priv->current_prim = prim_buffer;
|
|
|
|
dev_priv->current_prim_idx = next_prim_idx;
|
|
|
|
return 0;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
/* More dynamic performance decisions */
|
|
|
|
static inline int mga_decide_to_fire(drm_device_t *dev)
|
2000-02-22 08:43:59 -07:00
|
|
|
{
|
|
|
|
drm_mga_private_t *dev_priv = (drm_mga_private_t *)dev->dev_private;
|
2000-04-04 16:08:14 -06:00
|
|
|
drm_device_dma_t *dma = dev->dma;
|
2000-05-25 15:06:02 -06:00
|
|
|
|
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
|
|
|
|
|
|
|
if(test_bit(MGA_BUF_FORCE_FIRE, &dev_priv->next_prim->buffer_status)) {
|
2000-04-04 16:08:14 -06:00
|
|
|
atomic_inc(&dma->total_prio);
|
|
|
|
return 1;
|
|
|
|
}
|
2000-02-22 08:43:59 -07:00
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
if (test_bit(MGA_IN_GETBUF, &dev_priv->dispatch_status) &&
|
|
|
|
dev_priv->next_prim->num_dwords) {
|
|
|
|
atomic_inc(&dma->total_prio);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (test_bit(MGA_IN_FLUSH, &dev_priv->dispatch_status) &&
|
|
|
|
dev_priv->next_prim->num_dwords) {
|
2000-04-04 16:08:14 -06:00
|
|
|
atomic_inc(&dma->total_prio);
|
|
|
|
return 1;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
if(atomic_read(&dev_priv->pending_bufs) <= MGA_NUM_PRIM_BUFS - 1) {
|
2000-09-06 14:56:34 -06:00
|
|
|
if(test_bit(MGA_BUF_SWAP_PENDING,
|
2000-05-25 15:06:02 -06:00
|
|
|
&dev_priv->next_prim->buffer_status)) {
|
2000-04-04 16:08:14 -06:00
|
|
|
atomic_inc(&dma->total_dmas);
|
|
|
|
return 1;
|
|
|
|
}
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
if(atomic_read(&dev_priv->pending_bufs) <= MGA_NUM_PRIM_BUFS / 2) {
|
|
|
|
if(dev_priv->next_prim->sec_used >= MGA_DMA_BUF_NR / 8) {
|
|
|
|
atomic_inc(&dma->total_hit);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2000-02-22 08:43:59 -07:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
if(atomic_read(&dev_priv->pending_bufs) >= MGA_NUM_PRIM_BUFS / 2) {
|
|
|
|
if(dev_priv->next_prim->sec_used >= MGA_DMA_BUF_NR / 4) {
|
|
|
|
atomic_inc(&dma->total_missed_free);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
atomic_inc(&dma->total_tried);
|
|
|
|
return 0;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
int mga_dma_schedule(drm_device_t *dev, int locked)
|
2000-02-22 08:43:59 -07:00
|
|
|
{
|
|
|
|
drm_mga_private_t *dev_priv = (drm_mga_private_t *)dev->dev_private;
|
2000-04-04 16:08:14 -06:00
|
|
|
drm_device_dma_t *dma = dev->dma;
|
2000-07-11 05:41:07 -06:00
|
|
|
int retval = 0;
|
2000-02-22 08:43:59 -07:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
if (test_and_set_bit(0, &dev->dma_flag)) {
|
2000-02-22 08:43:59 -07:00
|
|
|
atomic_inc(&dma->total_missed_dma);
|
2000-07-11 05:41:07 -06:00
|
|
|
retval = -EBUSY;
|
|
|
|
goto sch_out_wakeup;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
2000-02-22 08:43:59 -07:00
|
|
|
|
2000-09-06 14:56:34 -06:00
|
|
|
if(test_bit(MGA_IN_FLUSH, &dev_priv->dispatch_status) ||
|
2000-05-25 15:06:02 -06:00
|
|
|
test_bit(MGA_IN_WAIT, &dev_priv->dispatch_status) ||
|
|
|
|
test_bit(MGA_IN_GETBUF, &dev_priv->dispatch_status)) {
|
2000-04-04 16:08:14 -06:00
|
|
|
locked = 1;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
|
|
|
|
if (!locked &&
|
2000-04-04 16:08:14 -06:00
|
|
|
!drm_lock_take(&dev->lock.hw_lock->lock, DRM_KERNEL_CONTEXT)) {
|
|
|
|
atomic_inc(&dma->total_missed_lock);
|
|
|
|
clear_bit(0, &dev->dma_flag);
|
2000-05-25 15:06:02 -06:00
|
|
|
DRM_DEBUG("Not locked\n");
|
2000-07-11 05:41:07 -06:00
|
|
|
retval = -EBUSY;
|
|
|
|
goto sch_out_wakeup;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
2000-04-04 16:08:14 -06:00
|
|
|
DRM_DEBUG("I'm locked\n");
|
2000-02-22 08:43:59 -07:00
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
if(!test_and_set_bit(MGA_IN_DISPATCH, &dev_priv->dispatch_status)) {
|
2000-04-04 16:08:14 -06:00
|
|
|
/* Fire dma buffer */
|
|
|
|
if(mga_decide_to_fire(dev)) {
|
|
|
|
DRM_DEBUG("idx :%d\n", dev_priv->next_prim->idx);
|
2000-09-06 14:56:34 -06:00
|
|
|
clear_bit(MGA_BUF_FORCE_FIRE,
|
2000-05-25 15:06:02 -06:00
|
|
|
&dev_priv->next_prim->buffer_status);
|
|
|
|
if(dev_priv->current_prim == dev_priv->next_prim) {
|
2000-04-04 16:08:14 -06:00
|
|
|
/* Schedule overflow for a later time */
|
2000-05-25 15:06:02 -06:00
|
|
|
set_bit(MGA_BUF_NEEDS_OVERFLOW,
|
|
|
|
&dev_priv->next_prim->buffer_status);
|
2000-04-04 16:08:14 -06:00
|
|
|
}
|
|
|
|
mga_fire_primary(dev, dev_priv->next_prim);
|
|
|
|
} else {
|
2000-05-25 15:06:02 -06:00
|
|
|
clear_bit(MGA_IN_DISPATCH, &dev_priv->dispatch_status);
|
2000-04-04 16:08:14 -06:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DRM_DEBUG("I can't get the dispatch lock\n");
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-02-22 08:43:59 -07:00
|
|
|
if (!locked) {
|
|
|
|
if (drm_lock_free(dev, &dev->lock.hw_lock->lock,
|
|
|
|
DRM_KERNEL_CONTEXT)) {
|
|
|
|
DRM_ERROR("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-11 05:41:07 -06:00
|
|
|
sch_out_wakeup:
|
2000-05-25 15:06:02 -06:00
|
|
|
if(test_bit(MGA_IN_FLUSH, &dev_priv->dispatch_status) &&
|
|
|
|
atomic_read(&dev_priv->pending_bufs) == 0) {
|
2000-07-11 05:41:07 -06:00
|
|
|
/* Everything has been processed by the hardware */
|
2000-05-25 15:06:02 -06:00
|
|
|
clear_bit(MGA_IN_FLUSH, &dev_priv->dispatch_status);
|
2000-07-11 05:41:07 -06:00
|
|
|
wake_up_interruptible(&dev_priv->flush_queue);
|
2000-04-04 16:08:14 -06:00
|
|
|
}
|
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
if(test_bit(MGA_IN_GETBUF, &dev_priv->dispatch_status) &&
|
|
|
|
dev_priv->tail->age < dev_priv->last_prim_age) {
|
|
|
|
clear_bit(MGA_IN_GETBUF, &dev_priv->dispatch_status);
|
|
|
|
DRM_DEBUG("Waking up buf queue\n");
|
|
|
|
wake_up_interruptible(&dev_priv->buf_queue);
|
|
|
|
} else if (test_bit(MGA_IN_GETBUF, &dev_priv->dispatch_status)) {
|
2000-09-06 14:56:34 -06:00
|
|
|
DRM_DEBUG("Not waking buf_queue on %d %d\n",
|
|
|
|
atomic_read(&dev->total_irq),
|
2000-05-25 15:06:02 -06:00
|
|
|
dev_priv->last_prim_age);
|
|
|
|
}
|
|
|
|
|
|
|
|
clear_bit(0, &dev->dma_flag);
|
2000-07-11 05:41:07 -06:00
|
|
|
return retval;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
static void mga_dma_service(int irq, void *device, struct pt_regs *regs)
|
2000-02-22 08:43:59 -07:00
|
|
|
{
|
2000-04-04 16:08:14 -06:00
|
|
|
drm_device_t *dev = (drm_device_t *)device;
|
|
|
|
drm_mga_private_t *dev_priv = (drm_mga_private_t *)dev->dev_private;
|
|
|
|
drm_mga_prim_buf_t *last_prim_buffer;
|
2000-05-25 15:06:02 -06:00
|
|
|
|
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
2000-04-04 16:08:14 -06:00
|
|
|
atomic_inc(&dev->total_irq);
|
2000-05-25 15:06:02 -06:00
|
|
|
if((MGA_READ(MGAREG_STATUS) & 0x00000001) != 0x00000001) return;
|
2000-04-04 16:08:14 -06:00
|
|
|
MGA_WRITE(MGAREG_ICLEAR, 0x00000001);
|
|
|
|
last_prim_buffer = dev_priv->last_prim;
|
|
|
|
last_prim_buffer->num_dwords = 0;
|
|
|
|
last_prim_buffer->sec_used = 0;
|
2000-09-06 14:56:34 -06:00
|
|
|
dev_priv->sarea_priv->last_dispatch =
|
2000-05-25 15:06:02 -06:00
|
|
|
dev_priv->last_prim_age = last_prim_buffer->prim_age;
|
|
|
|
clear_bit(MGA_BUF_IN_USE, &last_prim_buffer->buffer_status);
|
2000-04-04 16:08:14 -06:00
|
|
|
wake_up_interruptible(&dev_priv->wait_queue);
|
2000-05-25 15:06:02 -06:00
|
|
|
clear_bit(MGA_BUF_SWAP_PENDING, &last_prim_buffer->buffer_status);
|
|
|
|
clear_bit(MGA_IN_DISPATCH, &dev_priv->dispatch_status);
|
2000-04-04 16:08:14 -06:00
|
|
|
atomic_dec(&dev_priv->pending_bufs);
|
|
|
|
queue_task(&dev->tq, &tq_immediate);
|
|
|
|
mark_bh(IMMEDIATE_BH);
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
static void mga_dma_task_queue(void *device)
|
2000-02-22 08:43:59 -07:00
|
|
|
{
|
2000-05-25 15:06:02 -06:00
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
|
|
|
mga_dma_schedule((drm_device_t *)device, 0);
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
int mga_dma_cleanup(drm_device_t *dev)
|
2000-02-22 08:43:59 -07:00
|
|
|
{
|
2000-05-25 15:06:02 -06:00
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
if(dev->dev_private) {
|
2000-09-06 14:56:34 -06:00
|
|
|
drm_mga_private_t *dev_priv =
|
2000-04-04 16:08:14 -06:00
|
|
|
(drm_mga_private_t *) dev->dev_private;
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
if(dev_priv->ioremap) {
|
2000-09-06 14:56:34 -06:00
|
|
|
int temp = (dev_priv->warp_ucode_size +
|
|
|
|
dev_priv->primary_size +
|
2000-04-04 16:08:14 -06:00
|
|
|
PAGE_SIZE - 1) / PAGE_SIZE * PAGE_SIZE;
|
2000-02-22 08:43:59 -07:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
drm_ioremapfree((void *) dev_priv->ioremap, temp);
|
|
|
|
}
|
|
|
|
if(dev_priv->status_page != NULL) {
|
|
|
|
iounmap(dev_priv->status_page);
|
|
|
|
}
|
|
|
|
if(dev_priv->real_status_page != 0UL) {
|
|
|
|
mga_free_page(dev, dev_priv->real_status_page);
|
|
|
|
}
|
|
|
|
if(dev_priv->prim_bufs != NULL) {
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < MGA_NUM_PRIM_BUFS; i++) {
|
|
|
|
if(dev_priv->prim_bufs[i] != NULL) {
|
|
|
|
drm_free(dev_priv->prim_bufs[i],
|
|
|
|
sizeof(drm_mga_prim_buf_t),
|
|
|
|
DRM_MEM_DRIVER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drm_free(dev_priv->prim_bufs, sizeof(void *) *
|
2000-09-06 14:56:34 -06:00
|
|
|
(MGA_NUM_PRIM_BUFS + 1),
|
2000-04-04 16:08:14 -06:00
|
|
|
DRM_MEM_DRIVER);
|
|
|
|
}
|
|
|
|
if(dev_priv->head != NULL) {
|
|
|
|
mga_freelist_cleanup(dev);
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
2000-04-04 16:08:14 -06:00
|
|
|
|
|
|
|
|
2000-09-06 14:56:34 -06:00
|
|
|
drm_free(dev->dev_private, sizeof(drm_mga_private_t),
|
2000-04-04 16:08:14 -06:00
|
|
|
DRM_MEM_DRIVER);
|
|
|
|
dev->dev_private = NULL;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mga_dma_initialize(drm_device_t *dev, drm_mga_init_t *init) {
|
|
|
|
drm_mga_private_t *dev_priv;
|
|
|
|
drm_map_t *sarea_map = NULL;
|
|
|
|
int i;
|
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
dev_priv = drm_alloc(sizeof(drm_mga_private_t), DRM_MEM_DRIVER);
|
|
|
|
if(dev_priv == NULL) return -ENOMEM;
|
|
|
|
dev->dev_private = (void *) dev_priv;
|
|
|
|
|
|
|
|
memset(dev_priv, 0, sizeof(drm_mga_private_t));
|
|
|
|
|
|
|
|
if((init->reserved_map_idx >= dev->map_count) ||
|
|
|
|
(init->buffer_map_idx >= dev->map_count)) {
|
|
|
|
mga_dma_cleanup(dev);
|
|
|
|
DRM_DEBUG("reserved_map or buffer_map are invalid\n");
|
|
|
|
return -EINVAL;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
dev_priv->reserved_map_idx = init->reserved_map_idx;
|
|
|
|
dev_priv->buffer_map_idx = init->buffer_map_idx;
|
|
|
|
sarea_map = dev->maplist[0];
|
2000-09-06 14:56:34 -06:00
|
|
|
dev_priv->sarea_priv = (drm_mga_sarea_t *)
|
|
|
|
((u8 *)sarea_map->handle +
|
2000-04-04 16:08:14 -06:00
|
|
|
init->sarea_priv_offset);
|
2000-02-22 08:43:59 -07:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
/* Scale primary size to the next page */
|
|
|
|
dev_priv->chipset = init->chipset;
|
|
|
|
dev_priv->frontOffset = init->frontOffset;
|
|
|
|
dev_priv->backOffset = init->backOffset;
|
|
|
|
dev_priv->depthOffset = init->depthOffset;
|
|
|
|
dev_priv->textureOffset = init->textureOffset;
|
|
|
|
dev_priv->textureSize = init->textureSize;
|
|
|
|
dev_priv->cpp = init->cpp;
|
|
|
|
dev_priv->sgram = init->sgram;
|
|
|
|
dev_priv->stride = init->stride;
|
2000-02-22 08:43:59 -07:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
dev_priv->mAccess = init->mAccess;
|
|
|
|
init_waitqueue_head(&dev_priv->flush_queue);
|
2000-05-25 15:06:02 -06:00
|
|
|
init_waitqueue_head(&dev_priv->buf_queue);
|
2000-08-16 15:13:24 -06:00
|
|
|
dev_priv->WarpPipe = 0xff000000;
|
2000-08-30 16:34:28 -06:00
|
|
|
dev_priv->vertexsize = 0;
|
2000-04-04 16:08:14 -06:00
|
|
|
|
|
|
|
DRM_DEBUG("chipset: %d ucode_size: %d backOffset: %x depthOffset: %x\n",
|
2000-09-06 14:56:34 -06:00
|
|
|
dev_priv->chipset, dev_priv->warp_ucode_size,
|
2000-04-04 16:08:14 -06:00
|
|
|
dev_priv->backOffset, dev_priv->depthOffset);
|
|
|
|
DRM_DEBUG("cpp: %d sgram: %d stride: %d maccess: %x\n",
|
2000-09-06 14:56:34 -06:00
|
|
|
dev_priv->cpp, dev_priv->sgram, dev_priv->stride,
|
2000-04-04 16:08:14 -06:00
|
|
|
dev_priv->mAccess);
|
2000-09-06 14:56:34 -06:00
|
|
|
|
|
|
|
memcpy(&dev_priv->WarpIndex, &init->WarpIndex,
|
2000-04-04 16:08:14 -06:00
|
|
|
sizeof(drm_mga_warp_index_t) * MGA_MAX_WARP_PIPES);
|
|
|
|
|
2000-09-06 14:56:34 -06:00
|
|
|
for (i = 0 ; i < MGA_MAX_WARP_PIPES ; i++)
|
2000-04-04 16:08:14 -06:00
|
|
|
DRM_DEBUG("warp pipe %d: installed: %d phys: %lx size: %x\n",
|
2000-09-06 14:56:34 -06:00
|
|
|
i,
|
2000-04-04 16:08:14 -06:00
|
|
|
dev_priv->WarpIndex[i].installed,
|
|
|
|
dev_priv->WarpIndex[i].phys_addr,
|
|
|
|
dev_priv->WarpIndex[i].size);
|
|
|
|
|
|
|
|
if(mga_init_primary_bufs(dev, init) != 0) {
|
|
|
|
DRM_ERROR("Can not initialize primary buffers\n");
|
|
|
|
mga_dma_cleanup(dev);
|
|
|
|
return -ENOMEM;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
2000-04-04 16:08:14 -06:00
|
|
|
dev_priv->real_status_page = mga_alloc_page(dev);
|
|
|
|
if(dev_priv->real_status_page == 0UL) {
|
|
|
|
mga_dma_cleanup(dev);
|
|
|
|
DRM_ERROR("Can not allocate status page\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2000-09-06 14:56:34 -06:00
|
|
|
dev_priv->status_page =
|
2000-04-04 16:08:14 -06:00
|
|
|
ioremap_nocache(virt_to_bus((void *)dev_priv->real_status_page),
|
|
|
|
PAGE_SIZE);
|
|
|
|
|
|
|
|
if(dev_priv->status_page == NULL) {
|
|
|
|
mga_dma_cleanup(dev);
|
|
|
|
DRM_ERROR("Can not remap status page\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write status page when secend or softrap occurs */
|
2000-09-06 14:56:34 -06:00
|
|
|
MGA_WRITE(MGAREG_PRIMPTR,
|
2000-04-04 16:08:14 -06:00
|
|
|
virt_to_bus((void *)dev_priv->real_status_page) | 0x00000003);
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
|
|
|
|
/* Private is now filled in, initialize the hardware */
|
|
|
|
{
|
|
|
|
PRIMLOCALS;
|
|
|
|
PRIMGETPTR( dev_priv );
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
PRIMOUTREG(MGAREG_DMAPAD, 0);
|
|
|
|
PRIMOUTREG(MGAREG_DMAPAD, 0);
|
2000-05-25 15:06:02 -06:00
|
|
|
PRIMOUTREG(MGAREG_DWGSYNC, 0x0100);
|
2000-04-04 16:08:14 -06:00
|
|
|
PRIMOUTREG(MGAREG_SOFTRAP, 0);
|
|
|
|
/* Poll for the first buffer to insure that
|
|
|
|
* the status register will be correct
|
|
|
|
*/
|
2000-09-07 14:42:32 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
mga_flush_write_combine();
|
|
|
|
MGA_WRITE(MGAREG_PRIMADDRESS, phys_head | TT_GENERAL);
|
|
|
|
|
2000-09-06 14:56:34 -06:00
|
|
|
MGA_WRITE(MGAREG_PRIMEND, ((phys_head + num_dwords * 4) |
|
2000-04-04 16:08:14 -06:00
|
|
|
PDEA_pagpxfer_enable));
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
while(MGA_READ(MGAREG_DWGSYNC) != 0x0100) ;
|
2000-04-04 16:08:14 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if(mga_freelist_init(dev) != 0) {
|
|
|
|
DRM_ERROR("Could not initialize freelist\n");
|
|
|
|
mga_dma_cleanup(dev);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mga_dma_init(struct inode *inode, struct file *filp,
|
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
drm_file_t *priv = filp->private_data;
|
|
|
|
drm_device_t *dev = priv->dev;
|
|
|
|
drm_mga_init_t init;
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
|
|
|
|
2000-09-06 14:56:34 -06:00
|
|
|
if (copy_from_user(&init, (drm_mga_init_t *)arg, sizeof(init)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
switch(init.func) {
|
|
|
|
case MGA_INIT_DMA:
|
|
|
|
return mga_dma_initialize(dev, &init);
|
|
|
|
case MGA_CLEANUP_DMA:
|
|
|
|
return mga_dma_cleanup(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int mga_irq_install(drm_device_t *dev, int irq)
|
|
|
|
{
|
|
|
|
int retcode;
|
|
|
|
|
|
|
|
if (!irq) return -EINVAL;
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-02-22 08:43:59 -07:00
|
|
|
down(&dev->struct_sem);
|
|
|
|
if (dev->irq) {
|
|
|
|
up(&dev->struct_sem);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
dev->irq = irq;
|
|
|
|
up(&dev->struct_sem);
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
DRM_DEBUG("install irq handler %d\n", irq);
|
2000-02-22 08:43:59 -07:00
|
|
|
|
|
|
|
dev->context_flag = 0;
|
|
|
|
dev->interrupt_flag = 0;
|
|
|
|
dev->dma_flag = 0;
|
|
|
|
dev->dma->next_buffer = NULL;
|
|
|
|
dev->dma->next_queue = NULL;
|
|
|
|
dev->dma->this_buffer = NULL;
|
|
|
|
dev->tq.next = NULL;
|
|
|
|
dev->tq.sync = 0;
|
2000-04-04 16:08:14 -06:00
|
|
|
dev->tq.routine = mga_dma_task_queue;
|
2000-02-22 08:43:59 -07:00
|
|
|
dev->tq.data = dev;
|
|
|
|
|
|
|
|
/* Before installing handler */
|
|
|
|
MGA_WRITE(MGAREG_IEN, 0);
|
|
|
|
/* Install handler */
|
|
|
|
if ((retcode = request_irq(dev->irq,
|
|
|
|
mga_dma_service,
|
2000-05-25 15:06:02 -06:00
|
|
|
SA_SHIRQ,
|
2000-02-22 08:43:59 -07:00
|
|
|
dev->devname,
|
|
|
|
dev))) {
|
|
|
|
down(&dev->struct_sem);
|
|
|
|
dev->irq = 0;
|
|
|
|
up(&dev->struct_sem);
|
|
|
|
return retcode;
|
|
|
|
}
|
|
|
|
/* After installing handler */
|
2000-04-04 16:08:14 -06:00
|
|
|
MGA_WRITE(MGAREG_ICLEAR, 0x00000001);
|
2000-02-22 08:43:59 -07:00
|
|
|
MGA_WRITE(MGAREG_IEN, 0x00000001);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mga_irq_uninstall(drm_device_t *dev)
|
|
|
|
{
|
|
|
|
int irq;
|
|
|
|
|
|
|
|
down(&dev->struct_sem);
|
|
|
|
irq = dev->irq;
|
|
|
|
dev->irq = 0;
|
|
|
|
up(&dev->struct_sem);
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-02-22 08:43:59 -07:00
|
|
|
if (!irq) return -EINVAL;
|
2000-04-04 16:08:14 -06:00
|
|
|
DRM_DEBUG("remove irq handler %d\n", irq);
|
|
|
|
MGA_WRITE(MGAREG_ICLEAR, 0x00000001);
|
2000-02-22 08:43:59 -07:00
|
|
|
MGA_WRITE(MGAREG_IEN, 0);
|
|
|
|
free_irq(irq, dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mga_control(struct inode *inode, struct file *filp, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
drm_file_t *priv = filp->private_data;
|
|
|
|
drm_device_t *dev = priv->dev;
|
|
|
|
drm_control_t ctl;
|
2000-09-06 14:56:34 -06:00
|
|
|
|
|
|
|
if (copy_from_user(&ctl, (drm_control_t *)arg, sizeof(ctl)))
|
|
|
|
return -EFAULT;
|
2000-05-25 15:06:02 -06:00
|
|
|
|
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
|
|
|
|
2000-02-22 08:43:59 -07:00
|
|
|
switch (ctl.func) {
|
|
|
|
case DRM_INST_HANDLER:
|
|
|
|
return mga_irq_install(dev, ctl.irq);
|
|
|
|
case DRM_UNINST_HANDLER:
|
|
|
|
return mga_irq_uninstall(dev);
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
static int mga_flush_queue(drm_device_t *dev)
|
2000-02-22 08:43:59 -07:00
|
|
|
{
|
|
|
|
DECLARE_WAITQUEUE(entry, current);
|
2000-04-04 16:08:14 -06:00
|
|
|
drm_mga_private_t *dev_priv = (drm_mga_private_t *)dev->dev_private;
|
2000-02-22 08:43:59 -07:00
|
|
|
int ret = 0;
|
2000-04-04 16:08:14 -06:00
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
if(dev_priv == NULL) {
|
|
|
|
return 0;
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
if(dev_priv->next_prim->num_dwords != 0) {
|
|
|
|
current->state = TASK_INTERRUPTIBLE;
|
|
|
|
add_wait_queue(&dev_priv->flush_queue, &entry);
|
2000-07-11 05:41:07 -06:00
|
|
|
set_bit(MGA_IN_FLUSH, &dev_priv->dispatch_status);
|
|
|
|
mga_dma_schedule(dev, 0);
|
2000-04-04 16:08:14 -06:00
|
|
|
for (;;) {
|
2000-09-06 14:56:34 -06:00
|
|
|
if (!test_bit(MGA_IN_FLUSH,
|
|
|
|
&dev_priv->dispatch_status))
|
2000-04-04 16:08:14 -06:00
|
|
|
break;
|
|
|
|
atomic_inc(&dev->total_sleeps);
|
2000-05-25 15:06:02 -06:00
|
|
|
schedule();
|
2000-04-04 16:08:14 -06:00
|
|
|
if (signal_pending(current)) {
|
|
|
|
ret = -EINTR; /* Can't restart */
|
2000-09-06 14:56:34 -06:00
|
|
|
clear_bit(MGA_IN_FLUSH,
|
2000-05-25 15:06:02 -06:00
|
|
|
&dev_priv->dispatch_status);
|
2000-04-04 16:08:14 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
current->state = TASK_RUNNING;
|
|
|
|
remove_wait_queue(&dev_priv->flush_queue, &entry);
|
|
|
|
}
|
2000-02-22 08:43:59 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
/* Must be called with the lock held */
|
|
|
|
void mga_reclaim_buffers(drm_device_t *dev, pid_t pid)
|
|
|
|
{
|
|
|
|
drm_device_dma_t *dma = dev->dma;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!dma) return;
|
|
|
|
if(dev->dev_private == NULL) return;
|
2000-04-05 12:48:23 -06:00
|
|
|
if(dma->buflist == NULL) return;
|
2000-04-04 16:08:14 -06:00
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
2000-04-04 16:08:14 -06:00
|
|
|
mga_flush_queue(dev);
|
|
|
|
|
|
|
|
for (i = 0; i < dma->buf_count; i++) {
|
|
|
|
drm_buf_t *buf = dma->buflist[ i ];
|
|
|
|
drm_mga_buf_priv_t *buf_priv = buf->dev_private;
|
|
|
|
|
2000-09-06 14:56:34 -06:00
|
|
|
/* Only buffers that need to get reclaimed ever
|
|
|
|
* get set to free
|
2000-04-05 12:48:23 -06:00
|
|
|
*/
|
|
|
|
if (buf->pid == pid && buf_priv) {
|
2000-09-06 14:56:34 -06:00
|
|
|
if(buf_priv->my_freelist->age == MGA_BUF_USED)
|
2000-04-04 16:08:14 -06:00
|
|
|
buf_priv->my_freelist->age = MGA_BUF_FREE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-22 08:43:59 -07:00
|
|
|
int mga_lock(struct inode *inode, struct file *filp, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
drm_file_t *priv = filp->private_data;
|
|
|
|
drm_device_t *dev = priv->dev;
|
|
|
|
DECLARE_WAITQUEUE(entry, current);
|
|
|
|
int ret = 0;
|
|
|
|
drm_lock_t lock;
|
|
|
|
|
2000-05-25 15:06:02 -06:00
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
2000-09-06 14:56:34 -06:00
|
|
|
if (copy_from_user(&lock, (drm_lock_t *)arg, sizeof(lock)))
|
|
|
|
return -EFAULT;
|
2000-02-22 08:43:59 -07:00
|
|
|
|
|
|
|
if (lock.context == DRM_KERNEL_CONTEXT) {
|
|
|
|
DRM_ERROR("Process %d using kernel context %d\n",
|
|
|
|
current->pid, lock.context);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
DRM_DEBUG("%d (pid %d) requests lock (0x%08x), flags = 0x%08x\n",
|
|
|
|
lock.context, current->pid, dev->lock.hw_lock->lock,
|
|
|
|
lock.flags);
|
2000-02-22 08:43:59 -07:00
|
|
|
|
|
|
|
if (lock.context < 0) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-02-22 08:43:59 -07:00
|
|
|
/* Only one queue:
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
add_wait_queue(&dev->lock.lock_queue, &entry);
|
|
|
|
for (;;) {
|
|
|
|
if (!dev->lock.hw_lock) {
|
|
|
|
/* Device has been unregistered */
|
|
|
|
ret = -EINTR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (drm_lock_take(&dev->lock.hw_lock->lock,
|
|
|
|
lock.context)) {
|
|
|
|
dev->lock.pid = current->pid;
|
|
|
|
dev->lock.lock_time = jiffies;
|
|
|
|
atomic_inc(&dev->total_locks);
|
|
|
|
break; /* Got lock */
|
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-02-22 08:43:59 -07:00
|
|
|
/* Contention */
|
|
|
|
atomic_inc(&dev->total_sleeps);
|
|
|
|
current->state = TASK_INTERRUPTIBLE;
|
|
|
|
schedule();
|
|
|
|
if (signal_pending(current)) {
|
|
|
|
ret = -ERESTARTSYS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
current->state = TASK_RUNNING;
|
|
|
|
remove_wait_queue(&dev->lock.lock_queue, &entry);
|
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-02-22 08:43:59 -07:00
|
|
|
if (!ret) {
|
2000-08-26 04:36:44 -06:00
|
|
|
sigemptyset(&dev->sigmask);
|
|
|
|
sigaddset(&dev->sigmask, SIGSTOP);
|
|
|
|
sigaddset(&dev->sigmask, SIGTSTP);
|
|
|
|
sigaddset(&dev->sigmask, SIGTTIN);
|
|
|
|
sigaddset(&dev->sigmask, SIGTTOU);
|
|
|
|
dev->sigdata.context = lock.context;
|
|
|
|
dev->sigdata.lock = dev->lock.hw_lock;
|
|
|
|
block_all_signals(drm_notifier, &dev->sigdata, &dev->sigmask);
|
2000-08-28 13:50:52 -06:00
|
|
|
|
2000-02-22 08:43:59 -07:00
|
|
|
if (lock.flags & _DRM_LOCK_QUIESCENT) {
|
2000-04-04 16:08:14 -06:00
|
|
|
DRM_DEBUG("_DRM_LOCK_QUIESCENT\n");
|
|
|
|
mga_flush_queue(dev);
|
|
|
|
mga_dma_quiescent(dev);
|
2000-02-22 08:43:59 -07:00
|
|
|
}
|
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
|
2000-04-04 16:08:14 -06:00
|
|
|
DRM_DEBUG("%d %s\n", lock.context, ret ? "interrupted" : "has lock");
|
2000-02-22 08:43:59 -07:00
|
|
|
return ret;
|
|
|
|
}
|
2000-09-06 14:56:34 -06:00
|
|
|
|
|
|
|
int mga_flush_ioctl(struct inode *inode, struct file *filp,
|
2000-04-04 16:08:14 -06:00
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
drm_file_t *priv = filp->private_data;
|
|
|
|
drm_device_t *dev = priv->dev;
|
|
|
|
drm_lock_t lock;
|
|
|
|
drm_mga_private_t *dev_priv = (drm_mga_private_t *)dev->dev_private;
|
2000-05-25 15:06:02 -06:00
|
|
|
|
|
|
|
DRM_DEBUG("%s\n", __FUNCTION__);
|
2000-09-06 14:56:34 -06:00
|
|
|
if (copy_from_user(&lock, (drm_lock_t *)arg, sizeof(lock)))
|
|
|
|
return -EFAULT;
|
2000-04-04 16:08:14 -06:00
|
|
|
|
|
|
|
if(!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) {
|
|
|
|
DRM_ERROR("mga_flush_ioctl called without lock held\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(lock.flags & _DRM_LOCK_FLUSH || lock.flags & _DRM_LOCK_FLUSH_ALL) {
|
2000-07-11 05:41:07 -06:00
|
|
|
drm_mga_prim_buf_t *temp_buf;
|
|
|
|
|
|
|
|
temp_buf = dev_priv->current_prim;
|
2000-05-25 15:06:02 -06:00
|
|
|
|
|
|
|
if(temp_buf && temp_buf->num_dwords) {
|
|
|
|
set_bit(MGA_BUF_FORCE_FIRE, &temp_buf->buffer_status);
|
|
|
|
mga_advance_primary(dev);
|
|
|
|
}
|
2000-07-11 05:41:07 -06:00
|
|
|
mga_dma_schedule(dev, 1);
|
2000-04-04 16:08:14 -06:00
|
|
|
}
|
|
|
|
if(lock.flags & _DRM_LOCK_QUIESCENT) {
|
2000-05-25 15:06:02 -06:00
|
|
|
mga_flush_queue(dev);
|
2000-04-04 16:08:14 -06:00
|
|
|
mga_dma_quiescent(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|