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>
35 #include "dev/drm/drmP.h"
37 int drm_dma_setup(drm_device_t *dev)
40 dev->dma = malloc(sizeof(*dev->dma), M_DRM, M_NOWAIT | M_ZERO);
42 return DRM_ERR(ENOMEM);
44 DRM_SPININIT(dev->dma_lock, "drmdma");
49 void drm_dma_takedown(drm_device_t *dev)
51 drm_device_dma_t *dma = dev->dma;
57 /* Clear dma buffers */
58 for (i = 0; i <= DRM_MAX_ORDER; i++) {
59 if (dma->bufs[i].seg_count) {
60 DRM_DEBUG("order %d: buf_count = %d,"
63 dma->bufs[i].buf_count,
64 dma->bufs[i].seg_count);
65 for (j = 0; j < dma->bufs[i].seg_count; j++) {
66 drm_pci_free(dev, dma->bufs[i].buf_size,
67 (void *)dma->bufs[i].seglist[j],
68 dma->bufs[i].seglist_bus[j]);
70 free(dma->bufs[i].seglist, M_DRM);
71 free(dma->bufs[i].seglist_bus, M_DRM);
74 if (dma->bufs[i].buf_count) {
75 for (j = 0; j < dma->bufs[i].buf_count; j++) {
76 free(dma->bufs[i].buflist[j].dev_private,
79 free(dma->bufs[i].buflist, M_DRM);
83 free(dma->buflist, M_DRM);
84 free(dma->pagelist, M_DRM);
85 free(dev->dma, M_DRM);
87 DRM_SPINUNINIT(dev->dma_lock);
91 void drm_free_buffer(drm_device_t *dev, drm_buf_t *buf)
100 void drm_reclaim_buffers(drm_device_t *dev, DRMFILE filp)
102 drm_device_dma_t *dma = dev->dma;
106 for (i = 0; i < dma->buf_count; i++) {
107 if (dma->buflist[i]->filp == filp) {
108 switch (dma->buflist[i]->list) {
110 drm_free_buffer(dev, dma->buflist[i]);
113 dma->buflist[i]->list = DRM_LIST_RECLAIM;
116 /* Buffer already on hardware. */
123 /* Call into the driver-specific DMA handler */
124 int drm_dma(DRM_IOCTL_ARGS)
128 if (dev->dma_ioctl) {
129 return dev->dma_ioctl(kdev, cmd, data, flags, p, filp);
131 DRM_DEBUG("DMA ioctl on driver with no dma handler\n");