1 /* drm_dma.c -- DMA IOCTL and function support -*- linux-c -*-
2 * Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
5 * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
6 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
29 * Rickard E. (Rik) Faith <faith@valinux.com>
30 * Gareth Hughes <gareth@valinux.com>
36 int drm_dma_setup(drm_device_t *dev)
39 dev->dma = malloc(sizeof(*dev->dma), M_DRM, M_NOWAIT | M_ZERO);
43 DRM_SPININIT(&dev->dma_lock, "drmdma");
48 void drm_dma_takedown(drm_device_t *dev)
50 drm_device_dma_t *dma = dev->dma;
56 /* Clear dma buffers */
57 for (i = 0; i <= DRM_MAX_ORDER; i++) {
58 if (dma->bufs[i].seg_count) {
59 DRM_DEBUG("order %d: buf_count = %d,"
62 dma->bufs[i].buf_count,
63 dma->bufs[i].seg_count);
64 for (j = 0; j < dma->bufs[i].seg_count; j++) {
65 drm_pci_free(dev, dma->bufs[i].seglist[j]);
67 free(dma->bufs[i].seglist, M_DRM);
70 if (dma->bufs[i].buf_count) {
71 for (j = 0; j < dma->bufs[i].buf_count; j++) {
72 free(dma->bufs[i].buflist[j].dev_private,
75 free(dma->bufs[i].buflist, M_DRM);
79 free(dma->buflist, M_DRM);
80 free(dma->pagelist, M_DRM);
81 free(dev->dma, M_DRM);
83 DRM_SPINUNINIT(&dev->dma_lock);
87 void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf)
96 void drm_reclaim_buffers(drm_device_t *dev, struct drm_file *file_priv)
98 drm_device_dma_t *dma = dev->dma;
102 for (i = 0; i < dma->buf_count; i++) {
103 if (dma->buflist[i]->file_priv == file_priv) {
104 switch (dma->buflist[i]->list) {
106 drm_free_buffer(dev, dma->buflist[i]);
109 dma->buflist[i]->list = DRM_LIST_RECLAIM;
112 /* Buffer already on hardware. */
119 /* Call into the driver-specific DMA handler */
120 int drm_dma(drm_device_t *dev, void *data, struct drm_file *file_priv)
123 if (dev->driver.dma_ioctl) {
124 return -dev->driver.dma_ioctl(dev, data, file_priv);
126 DRM_DEBUG("DMA ioctl on driver with no dma handler\n");