summaryrefslogtreecommitdiff
path: root/linux/mga_dma.c
diff options
context:
space:
mode:
Diffstat (limited to 'linux/mga_dma.c')
-rw-r--r--linux/mga_dma.c259
1 files changed, 124 insertions, 135 deletions
diff --git a/linux/mga_dma.c b/linux/mga_dma.c
index 4b861220..f763cdc8 100644
--- a/linux/mga_dma.c
+++ b/linux/mga_dma.c
@@ -11,11 +11,11 @@
* 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
@@ -51,7 +51,7 @@ static int mga_flush_queue(drm_device_t *dev);
static unsigned long mga_alloc_page(drm_device_t *dev)
{
unsigned long address;
-
+
DRM_DEBUG("%s\n", __FUNCTION__);
address = __get_free_page(GFP_KERNEL);
if(address == 0UL) {
@@ -59,7 +59,7 @@ static unsigned long mga_alloc_page(drm_device_t *dev)
}
atomic_inc(&virt_to_page(address)->count);
set_bit(PG_locked, &virt_to_page(address)->flags);
-
+
return address;
}
@@ -82,19 +82,6 @@ static void mga_delay(void)
return;
}
-#ifdef __i386__
-void mga_flush_write_combine(void)
-{
- int xchangeDummy;
- DRM_DEBUG("%s\n", __FUNCTION__);
-
- __asm__ volatile(" push %%eax ; xchg %%eax, %0 ; pop %%eax" : : "m" (xchangeDummy));
- __asm__ volatile(" push %%eax ; push %%ebx ; push %%ecx ; push %%edx ;"
- " movl $0,%%eax ; cpuid ; pop %%edx ; pop %%ecx ; pop %%ebx ;"
- " pop %%eax" : /* no outputs */ : /* no inputs */ );
-}
-#endif
-
/* These are two age tags that will never be sent to
* the hardware */
#define MGA_BUF_USED 0xffffffff
@@ -115,7 +102,7 @@ static int mga_freelist_init(drm_device_t *dev)
if(dev_priv->head == NULL) return -ENOMEM;
memset(dev_priv->head, 0, sizeof(drm_mga_freelist_t));
dev_priv->head->age = MGA_BUF_USED;
-
+
for (i = 0; i < dma->buf_count; i++) {
buf = dma->buflist[ i ];
buf_priv = buf->dev_private;
@@ -135,7 +122,7 @@ static int mga_freelist_init(drm_device_t *dev)
buf_priv->dispatched = 0;
dev_priv->head->next = item;
}
-
+
return 0;
}
@@ -153,7 +140,7 @@ static void mga_freelist_cleanup(drm_device_t *dev)
item = item->next;
drm_free(prev, sizeof(drm_mga_freelist_t), DRM_MEM_DRIVER);
}
-
+
dev_priv->head = dev_priv->tail = NULL;
}
@@ -169,15 +156,15 @@ static inline void mga_dma_quiescent(drm_device_t *dev)
DRM_DEBUG("%s\n", __FUNCTION__);
end = jiffies + (HZ*3);
while(1) {
- if(!test_and_set_bit(MGA_IN_DISPATCH,
+ if(!test_and_set_bit(MGA_IN_DISPATCH,
&dev_priv->dispatch_status)) {
break;
}
if((signed)(end - jiffies) <= 0) {
- DRM_ERROR("irqs: %d wanted %d\n",
- atomic_read(&dev->total_irq),
+ DRM_ERROR("irqs: %d wanted %d\n",
+ atomic_read(&dev->total_irq),
atomic_read(&dma->total_lost));
- DRM_ERROR("lockup\n");
+ DRM_ERROR("lockup\n");
goto out_nolock;
}
for (i = 0 ; i < 2000 ; i++) mga_delay();
@@ -186,13 +173,13 @@ static inline void mga_dma_quiescent(drm_device_t *dev)
DRM_DEBUG("quiescent status : %x\n", MGA_READ(MGAREG_STATUS));
while((MGA_READ(MGAREG_STATUS) & 0x00030001) != 0x00020000) {
if((signed)(end - jiffies) <= 0) {
- DRM_ERROR("irqs: %d wanted %d\n",
- atomic_read(&dev->total_irq),
+ DRM_ERROR("irqs: %d wanted %d\n",
+ atomic_read(&dev->total_irq),
atomic_read(&dma->total_lost));
- DRM_ERROR("lockup\n");
+ DRM_ERROR("lockup\n");
goto out_status;
}
- for (i = 0 ; i < 2000 ; i++) mga_delay();
+ for (i = 0 ; i < 2000 ; i++) mga_delay();
}
sarea_priv->dirty |= MGA_DMA_FLUSH;
@@ -216,44 +203,46 @@ static void mga_reset_freelist(drm_device_t *dev)
}
/* Least recently used :
- * These operations are not atomic b/c they are protected by the
+ * These operations are not atomic b/c they are protected by the
* hardware lock */
drm_buf_t *mga_freelist_get(drm_device_t *dev)
{
DECLARE_WAITQUEUE(entry, current);
- drm_mga_private_t *dev_priv =
+ drm_mga_private_t *dev_priv =
(drm_mga_private_t *) dev->dev_private;
drm_mga_freelist_t *prev;
drm_mga_freelist_t *next;
static int failed = 0;
+ int return_null = 0;
DRM_DEBUG("%s : tail->age : %d last_prim_age : %d\n", __FUNCTION__,
dev_priv->tail->age, dev_priv->last_prim_age);
-
+
if(failed >= 1000 && dev_priv->tail->age >= dev_priv->last_prim_age) {
- DRM_DEBUG("I'm waiting on the freelist!!! %d\n",
+ DRM_DEBUG("I'm waiting on the freelist!!! %d\n",
dev_priv->last_prim_age);
set_bit(MGA_IN_GETBUF, &dev_priv->dispatch_status);
- current->state = TASK_INTERRUPTIBLE;
add_wait_queue(&dev_priv->buf_queue, &entry);
for (;;) {
mga_dma_schedule(dev, 0);
- if(!test_bit(MGA_IN_GETBUF,
- &dev_priv->dispatch_status))
+ if(!test_bit(MGA_IN_GETBUF,
+ &dev_priv->dispatch_status))
break;
atomic_inc(&dev->total_sleeps);
+ current->state = TASK_INTERRUPTIBLE;
schedule();
if (signal_pending(current)) {
+ ++return_null;
clear_bit(MGA_IN_GETBUF,
&dev_priv->dispatch_status);
- goto failed_getbuf;
+ break;
}
}
- current->state = TASK_RUNNING;
remove_wait_queue(&dev_priv->buf_queue, &entry);
+ if (return_null) return NULL;
}
-
+
if(dev_priv->tail->age < dev_priv->last_prim_age) {
prev = dev_priv->tail->prev;
next = dev_priv->tail;
@@ -264,15 +253,13 @@ drm_buf_t *mga_freelist_get(drm_device_t *dev)
failed = 0;
return next->buf;
}
-
-failed_getbuf:
failed++;
return NULL;
}
int mga_freelist_put(drm_device_t *dev, drm_buf_t *buf)
{
- drm_mga_private_t *dev_priv =
+ drm_mga_private_t *dev_priv =
(drm_mga_private_t *) dev->dev_private;
drm_mga_buf_priv_t *buf_priv = buf->dev_private;
drm_mga_freelist_t *prev;
@@ -303,7 +290,7 @@ int mga_freelist_put(drm_device_t *dev, drm_buf_t *buf)
next->prev = head;
next->next = prev;
}
-
+
return 0;
}
@@ -315,41 +302,41 @@ static int mga_init_primary_bufs(drm_device_t *dev, drm_mga_init_t *init)
int offset = init->reserved_map_agpstart;
DRM_DEBUG("%s\n", __FUNCTION__);
- dev_priv->primary_size = ((init->primary_size + PAGE_SIZE - 1) /
+ dev_priv->primary_size = ((init->primary_size + PAGE_SIZE - 1) /
PAGE_SIZE) * PAGE_SIZE;
size_of_buf = dev_priv->primary_size / MGA_NUM_PRIM_BUFS;
dev_priv->warp_ucode_size = init->warp_ucode_size;
- dev_priv->prim_bufs = drm_alloc(sizeof(drm_mga_prim_buf_t *) *
- (MGA_NUM_PRIM_BUFS + 1),
+ dev_priv->prim_bufs = drm_alloc(sizeof(drm_mga_prim_buf_t *) *
+ (MGA_NUM_PRIM_BUFS + 1),
DRM_MEM_DRIVER);
if(dev_priv->prim_bufs == NULL) {
DRM_ERROR("Unable to allocate memory for prim_buf\n");
return -ENOMEM;
}
- memset(dev_priv->prim_bufs,
+ memset(dev_priv->prim_bufs,
0, sizeof(drm_mga_prim_buf_t *) * (MGA_NUM_PRIM_BUFS + 1));
-
+
temp = init->warp_ucode_size + dev_priv->primary_size;
temp = ((temp + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE;
-
- dev_priv->ioremap = drm_ioremap(dev->agp->base + offset,
+
+ dev_priv->ioremap = drm_ioremap(dev->agp->base + offset,
temp);
if(dev_priv->ioremap == NULL) {
DRM_DEBUG("Ioremap failed\n");
return -ENOMEM;
}
init_waitqueue_head(&dev_priv->wait_queue);
-
+
for(i = 0; i < MGA_NUM_PRIM_BUFS; i++) {
- prim_buffer = drm_alloc(sizeof(drm_mga_prim_buf_t),
+ prim_buffer = drm_alloc(sizeof(drm_mga_prim_buf_t),
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;
- prim_buffer->current_dma_ptr =
- prim_buffer->head =
- (u32 *) (dev_priv->ioremap +
- offset -
+ prim_buffer->current_dma_ptr =
+ prim_buffer->head =
+ (u32 *) (dev_priv->ioremap +
+ offset -
init->reserved_map_agpstart);
prim_buffer->num_dwords = 0;
prim_buffer->max_dwords = size_of_buf / sizeof(u32);
@@ -361,11 +348,11 @@ static int mga_init_primary_bufs(drm_device_t *dev, drm_mga_init_t *init)
dev_priv->prim_bufs[i] = prim_buffer;
}
dev_priv->current_prim_idx = 0;
- dev_priv->next_prim =
- dev_priv->last_prim =
+ dev_priv->next_prim =
+ dev_priv->last_prim =
dev_priv->current_prim =
dev_priv->prim_bufs[0];
- dev_priv->next_prim_age = 2;
+ dev_priv->next_prim_age = 2;
dev_priv->last_prim_age = 1;
set_bit(MGA_BUF_IN_USE, &dev_priv->current_prim->buffer_status);
return 0;
@@ -384,7 +371,7 @@ void mga_fire_primary(drm_device_t *dev, drm_mga_prim_buf_t *prim)
DRM_DEBUG("%s\n", __FUNCTION__);
dev_priv->last_prim = prim;
-
+
/* We never check for overflow, b/c there is always room */
PRIMPTR(prim);
if(num_dwords <= 0) {
@@ -399,17 +386,17 @@ void mga_fire_primary(drm_device_t *dev, drm_mga_prim_buf_t *prim)
end = jiffies + (HZ*3);
if(sarea_priv->dirty & MGA_DMA_FLUSH) {
- DRM_DEBUG("Dma top flush\n");
+ DRM_DEBUG("Dma top flush\n");
while((MGA_READ(MGAREG_STATUS) & 0x00030001) != 0x00020000) {
if((signed)(end - jiffies) <= 0) {
- DRM_ERROR("irqs: %d wanted %d\n",
- atomic_read(&dev->total_irq),
+ DRM_ERROR("irqs: %d wanted %d\n",
+ atomic_read(&dev->total_irq),
atomic_read(&dma->total_lost));
DRM_ERROR("lockup in fire primary "
"(Dma Top Flush)\n");
goto out_prim_wait;
}
-
+
for (i = 0 ; i < 4096 ; i++) mga_delay();
}
sarea_priv->dirty &= ~(MGA_DMA_FLUSH);
@@ -417,29 +404,28 @@ void mga_fire_primary(drm_device_t *dev, drm_mga_prim_buf_t *prim)
DRM_DEBUG("Status wait\n");
while((MGA_READ(MGAREG_STATUS) & 0x00020001) != 0x00020000) {
if((signed)(end - jiffies) <= 0) {
- DRM_ERROR("irqs: %d wanted %d\n",
- atomic_read(&dev->total_irq),
+ DRM_ERROR("irqs: %d wanted %d\n",
+ atomic_read(&dev->total_irq),
atomic_read(&dma->total_lost));
DRM_ERROR("lockup in fire primary "
"(Status Wait)\n");
goto out_prim_wait;
}
-
+
for (i = 0 ; i < 4096 ; i++) mga_delay();
}
}
-#ifdef __i386__
mga_flush_write_combine();
-#endif
+
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;
sarea_priv->last_enqueue = prim->prim_age;
-
+
next_idx = prim->idx + 1;
- if(next_idx >= MGA_NUM_PRIM_BUFS)
+ if(next_idx >= MGA_NUM_PRIM_BUFS)
next_idx = 0;
dev_priv->next_prim = dev_priv->prim_bufs[next_idx];
@@ -462,28 +448,28 @@ int mga_advance_primary(drm_device_t *dev)
drm_device_dma_t *dma = dev->dma;
int next_prim_idx;
int ret = 0;
-
+
/* This needs to reset the primary buffer if available,
* we should collect stats on how many times it bites
* it's tail */
DRM_DEBUG("%s\n", __FUNCTION__);
-
+
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];
set_bit(MGA_IN_WAIT, &dev_priv->dispatch_status);
-
+
/* In use is cleared in interrupt handler */
-
+
if(test_and_set_bit(MGA_BUF_IN_USE, &prim_buffer->buffer_status)) {
add_wait_queue(&dev_priv->wait_queue, &entry);
current->state = TASK_INTERRUPTIBLE;
for (;;) {
mga_dma_schedule(dev, 0);
- if(!test_and_set_bit(MGA_BUF_IN_USE,
- &prim_buffer->buffer_status))
+ if(!test_and_set_bit(MGA_BUF_IN_USE,
+ &prim_buffer->buffer_status))
break;
atomic_inc(&dev->total_sleeps);
atomic_inc(&dma->total_missed_sched);
@@ -545,9 +531,9 @@ static inline int mga_decide_to_fire(drm_device_t *dev)
atomic_inc(&dma->total_prio);
return 1;
}
-
+
if(atomic_read(&dev_priv->pending_bufs) <= MGA_NUM_PRIM_BUFS - 1) {
- if(test_bit(MGA_BUF_SWAP_PENDING,
+ if(test_bit(MGA_BUF_SWAP_PENDING,
&dev_priv->next_prim->buffer_status)) {
atomic_inc(&dma->total_dmas);
return 1;
@@ -583,16 +569,16 @@ int mga_dma_schedule(drm_device_t *dev, int locked)
retval = -EBUSY;
goto sch_out_wakeup;
}
-
+
DRM_DEBUG("%s\n", __FUNCTION__);
- if(test_bit(MGA_IN_FLUSH, &dev_priv->dispatch_status) ||
+ if(test_bit(MGA_IN_FLUSH, &dev_priv->dispatch_status) ||
test_bit(MGA_IN_WAIT, &dev_priv->dispatch_status) ||
test_bit(MGA_IN_GETBUF, &dev_priv->dispatch_status)) {
locked = 1;
}
-
- if (!locked &&
+
+ if (!locked &&
!drm_lock_take(&dev->lock.hw_lock->lock, DRM_KERNEL_CONTEXT)) {
atomic_inc(&dma->total_missed_lock);
clear_bit(0, &dev->dma_flag);
@@ -606,7 +592,7 @@ int mga_dma_schedule(drm_device_t *dev, int locked)
/* Fire dma buffer */
if(mga_decide_to_fire(dev)) {
DRM_DEBUG("idx :%d\n", dev_priv->next_prim->idx);
- clear_bit(MGA_BUF_FORCE_FIRE,
+ clear_bit(MGA_BUF_FORCE_FIRE,
&dev_priv->next_prim->buffer_status);
if(dev_priv->current_prim == dev_priv->next_prim) {
/* Schedule overflow for a later time */
@@ -620,7 +606,7 @@ int mga_dma_schedule(drm_device_t *dev, int locked)
} else {
DRM_DEBUG("I can't get the dispatch lock\n");
}
-
+
if (!locked) {
if (drm_lock_free(dev, &dev->lock.hw_lock->lock,
DRM_KERNEL_CONTEXT)) {
@@ -642,8 +628,8 @@ sch_out_wakeup:
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)) {
- DRM_DEBUG("Not waking buf_queue on %d %d\n",
- atomic_read(&dev->total_irq),
+ DRM_DEBUG("Not waking buf_queue on %d %d\n",
+ atomic_read(&dev->total_irq),
dev_priv->last_prim_age);
}
@@ -664,7 +650,7 @@ static void mga_dma_service(int irq, void *device, struct pt_regs *regs)
last_prim_buffer = dev_priv->last_prim;
last_prim_buffer->num_dwords = 0;
last_prim_buffer->sec_used = 0;
- dev_priv->sarea_priv->last_dispatch =
+ dev_priv->sarea_priv->last_dispatch =
dev_priv->last_prim_age = last_prim_buffer->prim_age;
clear_bit(MGA_BUF_IN_USE, &last_prim_buffer->buffer_status);
wake_up_interruptible(&dev_priv->wait_queue);
@@ -686,12 +672,12 @@ int mga_dma_cleanup(drm_device_t *dev)
DRM_DEBUG("%s\n", __FUNCTION__);
if(dev->dev_private) {
- drm_mga_private_t *dev_priv =
+ drm_mga_private_t *dev_priv =
(drm_mga_private_t *) dev->dev_private;
-
+
if(dev_priv->ioremap) {
- int temp = (dev_priv->warp_ucode_size +
- dev_priv->primary_size +
+ int temp = (dev_priv->warp_ucode_size +
+ dev_priv->primary_size +
PAGE_SIZE - 1) / PAGE_SIZE * PAGE_SIZE;
drm_ioremapfree((void *) dev_priv->ioremap, temp);
@@ -712,7 +698,7 @@ int mga_dma_cleanup(drm_device_t *dev)
}
}
drm_free(dev_priv->prim_bufs, sizeof(void *) *
- (MGA_NUM_PRIM_BUFS + 1),
+ (MGA_NUM_PRIM_BUFS + 1),
DRM_MEM_DRIVER);
}
if(dev_priv->head != NULL) {
@@ -720,7 +706,7 @@ int mga_dma_cleanup(drm_device_t *dev)
}
- drm_free(dev->dev_private, sizeof(drm_mga_private_t),
+ drm_free(dev->dev_private, sizeof(drm_mga_private_t),
DRM_MEM_DRIVER);
dev->dev_private = NULL;
}
@@ -747,12 +733,12 @@ static int mga_dma_initialize(drm_device_t *dev, drm_mga_init_t *init) {
DRM_DEBUG("reserved_map or buffer_map are invalid\n");
return -EINVAL;
}
-
+
dev_priv->reserved_map_idx = init->reserved_map_idx;
dev_priv->buffer_map_idx = init->buffer_map_idx;
sarea_map = dev->maplist[0];
- dev_priv->sarea_priv = (drm_mga_sarea_t *)
- ((u8 *)sarea_map->handle +
+ dev_priv->sarea_priv = (drm_mga_sarea_t *)
+ ((u8 *)sarea_map->handle +
init->sarea_priv_offset);
/* Scale primary size to the next page */
@@ -773,18 +759,18 @@ static int mga_dma_initialize(drm_device_t *dev, drm_mga_init_t *init) {
dev_priv->vertexsize = 0;
DRM_DEBUG("chipset: %d ucode_size: %d backOffset: %x depthOffset: %x\n",
- dev_priv->chipset, dev_priv->warp_ucode_size,
+ dev_priv->chipset, dev_priv->warp_ucode_size,
dev_priv->backOffset, dev_priv->depthOffset);
DRM_DEBUG("cpp: %d sgram: %d stride: %d maccess: %x\n",
- dev_priv->cpp, dev_priv->sgram, dev_priv->stride,
+ dev_priv->cpp, dev_priv->sgram, dev_priv->stride,
dev_priv->mAccess);
-
- memcpy(&dev_priv->WarpIndex, &init->WarpIndex,
+
+ memcpy(&dev_priv->WarpIndex, &init->WarpIndex,
sizeof(drm_mga_warp_index_t) * MGA_MAX_WARP_PIPES);
- for (i = 0 ; i < MGA_MAX_WARP_PIPES ; i++)
+ for (i = 0 ; i < MGA_MAX_WARP_PIPES ; i++)
DRM_DEBUG("warp pipe %d: installed: %d phys: %lx size: %x\n",
- i,
+ i,
dev_priv->WarpIndex[i].installed,
dev_priv->WarpIndex[i].phys_addr,
dev_priv->WarpIndex[i].size);
@@ -801,7 +787,7 @@ static int mga_dma_initialize(drm_device_t *dev, drm_mga_init_t *init) {
return -ENOMEM;
}
- dev_priv->status_page =
+ dev_priv->status_page =
ioremap_nocache(virt_to_bus((void *)dev_priv->real_status_page),
PAGE_SIZE);
@@ -812,15 +798,15 @@ static int mga_dma_initialize(drm_device_t *dev, drm_mga_init_t *init) {
}
/* Write status page when secend or softrap occurs */
- MGA_WRITE(MGAREG_PRIMPTR,
+ MGA_WRITE(MGAREG_PRIMPTR,
virt_to_bus((void *)dev_priv->real_status_page) | 0x00000003);
-
+
/* Private is now filled in, initialize the hardware */
{
PRIMLOCALS;
PRIMGETPTR( dev_priv );
-
+
PRIMOUTREG(MGAREG_DMAPAD, 0);
PRIMOUTREG(MGAREG_DMAPAD, 0);
PRIMOUTREG(MGAREG_DWGSYNC, 0x0100);
@@ -828,15 +814,14 @@ static int mga_dma_initialize(drm_device_t *dev, drm_mga_init_t *init) {
/* Poll for the first buffer to insure that
* the status register will be correct
*/
-
-#ifdef __i386__
+
mga_flush_write_combine();
-#endif
+
MGA_WRITE(MGAREG_PRIMADDRESS, phys_head | TT_GENERAL);
- MGA_WRITE(MGAREG_PRIMEND, ((phys_head + num_dwords * 4) |
+ MGA_WRITE(MGAREG_PRIMEND, ((phys_head + num_dwords * 4) |
PDEA_pagpxfer_enable));
-
+
while(MGA_READ(MGAREG_DWGSYNC) != 0x0100) ;
}
@@ -854,11 +839,12 @@ int mga_dma_init(struct inode *inode, struct file *filp,
drm_file_t *priv = filp->private_data;
drm_device_t *dev = priv->dev;
drm_mga_init_t init;
-
+
DRM_DEBUG("%s\n", __FUNCTION__);
- copy_from_user_ret(&init, (drm_mga_init_t *)arg, sizeof(init), -EFAULT);
-
+ if (copy_from_user(&init, (drm_mga_init_t *)arg, sizeof(init)))
+ return -EFAULT;
+
switch(init.func) {
case MGA_INIT_DMA:
return mga_dma_initialize(dev, &init);
@@ -874,7 +860,7 @@ int mga_irq_install(drm_device_t *dev, int irq)
int retcode;
if (!irq) return -EINVAL;
-
+
down(&dev->struct_sem);
if (dev->irq) {
up(&dev->struct_sem);
@@ -882,7 +868,7 @@ int mga_irq_install(drm_device_t *dev, int irq)
}
dev->irq = irq;
up(&dev->struct_sem);
-
+
DRM_DEBUG("install irq handler %d\n", irq);
dev->context_flag = 0;
@@ -923,7 +909,7 @@ int mga_irq_uninstall(drm_device_t *dev)
irq = dev->irq;
dev->irq = 0;
up(&dev->struct_sem);
-
+
if (!irq) return -EINVAL;
DRM_DEBUG("remove irq handler %d\n", irq);
MGA_WRITE(MGAREG_ICLEAR, 0x00000001);
@@ -938,8 +924,9 @@ int mga_control(struct inode *inode, struct file *filp, unsigned int cmd,
drm_file_t *priv = filp->private_data;
drm_device_t *dev = priv->dev;
drm_control_t ctl;
-
- copy_from_user_ret(&ctl, (drm_control_t *)arg, sizeof(ctl), -EFAULT);
+
+ if (copy_from_user(&ctl, (drm_control_t *)arg, sizeof(ctl)))
+ return -EFAULT;
DRM_DEBUG("%s\n", __FUNCTION__);
@@ -964,21 +951,21 @@ static int mga_flush_queue(drm_device_t *dev)
if(dev_priv == NULL) {
return 0;
}
-
+
if(dev_priv->next_prim->num_dwords != 0) {
current->state = TASK_INTERRUPTIBLE;
add_wait_queue(&dev_priv->flush_queue, &entry);
set_bit(MGA_IN_FLUSH, &dev_priv->dispatch_status);
mga_dma_schedule(dev, 0);
for (;;) {
- if (!test_bit(MGA_IN_FLUSH,
- &dev_priv->dispatch_status))
+ if (!test_bit(MGA_IN_FLUSH,
+ &dev_priv->dispatch_status))
break;
atomic_inc(&dev->total_sleeps);
schedule();
if (signal_pending(current)) {
ret = -EINTR; /* Can't restart */
- clear_bit(MGA_IN_FLUSH,
+ clear_bit(MGA_IN_FLUSH,
&dev_priv->dispatch_status);
break;
}
@@ -1006,11 +993,11 @@ void mga_reclaim_buffers(drm_device_t *dev, pid_t pid)
drm_buf_t *buf = dma->buflist[ i ];
drm_mga_buf_priv_t *buf_priv = buf->dev_private;
- /* Only buffers that need to get reclaimed ever
- * get set to free
+ /* Only buffers that need to get reclaimed ever
+ * get set to free
*/
if (buf->pid == pid && buf_priv) {
- if(buf_priv->my_freelist->age == MGA_BUF_USED)
+ if(buf_priv->my_freelist->age == MGA_BUF_USED)
buf_priv->my_freelist->age = MGA_BUF_FREE;
}
}
@@ -1026,14 +1013,15 @@ int mga_lock(struct inode *inode, struct file *filp, unsigned int cmd,
drm_lock_t lock;
DRM_DEBUG("%s\n", __FUNCTION__);
- copy_from_user_ret(&lock, (drm_lock_t *)arg, sizeof(lock), -EFAULT);
+ if (copy_from_user(&lock, (drm_lock_t *)arg, sizeof(lock)))
+ return -EFAULT;
if (lock.context == DRM_KERNEL_CONTEXT) {
DRM_ERROR("Process %d using kernel context %d\n",
current->pid, lock.context);
return -EINVAL;
}
-
+
DRM_DEBUG("%d (pid %d) requests lock (0x%08x), flags = 0x%08x\n",
lock.context, current->pid, dev->lock.hw_lock->lock,
lock.flags);
@@ -1041,7 +1029,7 @@ int mga_lock(struct inode *inode, struct file *filp, unsigned int cmd,
if (lock.context < 0) {
return -EINVAL;
}
-
+
/* Only one queue:
*/
@@ -1060,7 +1048,7 @@ int mga_lock(struct inode *inode, struct file *filp, unsigned int cmd,
atomic_inc(&dev->total_locks);
break; /* Got lock */
}
-
+
/* Contention */
atomic_inc(&dev->total_sleeps);
current->state = TASK_INTERRUPTIBLE;
@@ -1073,7 +1061,7 @@ int mga_lock(struct inode *inode, struct file *filp, unsigned int cmd,
current->state = TASK_RUNNING;
remove_wait_queue(&dev->lock.lock_queue, &entry);
}
-
+
if (!ret) {
sigemptyset(&dev->sigmask);
sigaddset(&dev->sigmask, SIGSTOP);
@@ -1090,12 +1078,12 @@ int mga_lock(struct inode *inode, struct file *filp, unsigned int cmd,
mga_dma_quiescent(dev);
}
}
-
+
DRM_DEBUG("%d %s\n", lock.context, ret ? "interrupted" : "has lock");
return ret;
}
-
-int mga_flush_ioctl(struct inode *inode, struct file *filp,
+
+int mga_flush_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg)
{
drm_file_t *priv = filp->private_data;
@@ -1104,7 +1092,8 @@ int mga_flush_ioctl(struct inode *inode, struct file *filp,
drm_mga_private_t *dev_priv = (drm_mga_private_t *)dev->dev_private;
DRM_DEBUG("%s\n", __FUNCTION__);
- copy_from_user_ret(&lock, (drm_lock_t *)arg, sizeof(lock), -EFAULT);
+ if (copy_from_user(&lock, (drm_lock_t *)arg, sizeof(lock)))
+ return -EFAULT;
if(!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) {
DRM_ERROR("mga_flush_ioctl called without lock held\n");