int drm_rmctx(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_ctx_t ctx; drm_queue_t *q; drm_buf_t *buf; if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx))) return -EFAULT; DRM_DEBUG("%d\n", ctx.handle); if (ctx.handle >= dev->queue_count) return -EINVAL; q = dev->queuelist[ctx.handle]; atomic_inc(&q->use_count); if (atomic_read(&q->use_count) == 1) { /* No longer in use */ atomic_dec(&q->use_count); return -EINVAL; } atomic_inc(&q->finalization); /* Mark queue in finalization state */ atomic_sub(2, &q->use_count); /* Mark queue as unused (pending finalization) */ while (test_and_set_bit(0, &dev->interrupt_flag)) { schedule(); if (signal_pending(current)) { clear_bit(0, &dev->interrupt_flag); return -EINTR; } } /* Remove queued buffers */ while ((buf = drm_waitlist_get(&q->waitlist))) { drm_free_buffer(dev, buf); } clear_bit(0, &dev->interrupt_flag); /* Wakeup blocked processes */ wake_up_interruptible(&q->read_queue); wake_up_interruptible(&q->write_queue); wake_up_interruptible(&q->flush_queue); /* Finalization over. Queue is made available when both use_count and finalization become 0, which won't happen until all the waiting processes stop waiting. */ atomic_dec(&q->finalization); return 0; }
void drm_reclaim_buffers(drm_device_t *dev, pid_t pid) { drm_device_dma_t *dma = dev->dma; int i; if (!dma) return; for (i = 0; i < dma->buf_count; i++) { if (dma->buflist[i]->pid == pid) { switch (dma->buflist[i]->list) { case DRM_LIST_NONE: drm_free_buffer(dev, dma->buflist[i]); break; case DRM_LIST_WAIT: dma->buflist[i]->list = DRM_LIST_RECLAIM; break; default: /* Buffer already on hardware. */ break; } } } }
int mga_freebufs(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_device_dma_t *dma = dev->dma; drm_buf_free_t request; int i; int idx; drm_buf_t *buf; if (!dma) return -EINVAL; if (copy_from_user(&request, (drm_buf_free_t *)arg, sizeof(request))) return -EFAULT; for (i = 0; i < request.count; i++) { if (copy_from_user(&idx, &request.list[i], sizeof(idx))) return -EFAULT; if (idx < 0 || idx >= dma->buf_count) { DRM_ERROR("Index %d (of %d max)\n", idx, dma->buf_count - 1); return -EINVAL; } buf = dma->buflist[idx]; if (buf->pid != current->pid) { DRM_ERROR("Process %d freeing buffer owned by %d\n", current->pid, buf->pid); return -EINVAL; } drm_free_buffer(dev, buf); } return 0; }
/** * Reclaim the buffers. * * \param file_priv DRM file private. * * Frees each buffer associated with \p file_priv not already on the hardware. */ void drm_core_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv) { struct drm_device_dma *dma = dev->dma; int i; if (!dma) return; for (i = 0; i < dma->buf_count; i++) { if (dma->buflist[i]->file_priv == file_priv) { switch (dma->buflist[i]->list) { case DRM_LIST_NONE: drm_free_buffer(dev, dma->buflist[i]); break; case DRM_LIST_WAIT: dma->buflist[i]->list = DRM_LIST_RECLAIM; break; default: /* Buffer already on hardware. */ break; } } } }