2 * drm_dma.c -- DMA IOCTL and function support -*- linux-c -*-
3 * Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
6 * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
7 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice (including the next
18 * paragraph) shall be included in all copies or substantial portions of the
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
30 * Rickard E. (Rik) Faith <faith@valinux.com>
31 * Gareth Hughes <gareth@valinux.com>
36 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
37 * Use is subject to license terms.
40 #pragma ident "%Z%%M% %I% %E% SMI"
45 drm_dma_setup(drm_device_t
*dev
)
48 drm_buf_entry_t
*pbuf
;
50 dev
->dma
= drm_calloc(1, sizeof (*dev
->dma
), DRM_MEM_DMA
);
54 mutex_init(&dev
->dma_lock
, NULL
, MUTEX_DRIVER
, NULL
);
55 pbuf
= &(dev
->dma
->bufs
[0]);
56 for (i
= 0; i
<= DRM_MAX_ORDER
; i
++, pbuf
++)
57 bzero(pbuf
, sizeof (drm_buf_entry_t
));
63 drm_dma_takedown(drm_device_t
*dev
)
65 drm_device_dma_t
*dma
= dev
->dma
;
71 /* Clear dma buffers */
72 for (i
= 0; i
<= DRM_MAX_ORDER
; i
++) {
73 if (dma
->bufs
[i
].seg_count
) {
74 drm_free(dma
->bufs
[i
].seglist
,
75 dma
->bufs
[i
].seg_count
*
76 sizeof (*dma
->bufs
[0].seglist
), DRM_MEM_SEGS
);
79 for (j
= 0; j
< dma
->bufs
[i
].buf_count
; j
++) {
80 if (dma
->bufs
[i
].buflist
[j
].dev_private
) {
81 drm_free(dma
->bufs
[i
].buflist
[j
].dev_private
,
82 dma
->bufs
[i
].buflist
[j
].dev_priv_size
,
86 if (dma
->bufs
[i
].buf_count
)
87 drm_free(dma
->bufs
[i
].buflist
,
88 dma
->bufs
[i
].buf_count
*
89 sizeof (*dma
->bufs
[0].buflist
), DRM_MEM_BUFS
);
92 drm_free(dma
->buflist
,
93 dma
->buf_count
*sizeof (*dma
->buflist
),
98 drm_free(dma
->pagelist
,
99 dma
->page_count
*sizeof (*dma
->pagelist
),
103 drm_free(dev
->dma
, sizeof (*dev
->dma
), DRM_MEM_DRIVER
);
105 mutex_destroy(&dev
->dma_lock
);
111 drm_free_buffer(drm_device_t
*dev
, drm_buf_t
*buf
)
122 drm_reclaim_buffers(drm_device_t
*dev
, drm_file_t
*fpriv
)
124 drm_device_dma_t
*dma
= dev
->dma
;
129 for (i
= 0; i
< dma
->buf_count
; i
++) {
130 if (dma
->buflist
[i
]->filp
== fpriv
) {
131 switch (dma
->buflist
[i
]->list
) {
133 drm_free_buffer(dev
, dma
->buflist
[i
]);
136 dma
->buflist
[i
]->list
= DRM_LIST_RECLAIM
;
139 /* Buffer already on hardware. */
146 /* Call into the driver-specific DMA handler */
148 drm_dma(DRM_IOCTL_ARGS
)
152 if (dev
->driver
->dma_ioctl
) {
153 return (dev
->driver
->dma_ioctl(dev
, data
, fpriv
, mode
));