2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2002-04-27 20:47:57 +00:00
|
|
|
* Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
|
|
|
|
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* 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
|
|
|
|
* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Rickard E. (Rik) Faith <faith@valinux.com>
|
|
|
|
* Gareth Hughes <gareth@valinux.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-11-28 23:13:57 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
/** @file drm_dma.c
|
|
|
|
* Support code for DMA buffer management.
|
|
|
|
*
|
|
|
|
* The implementation used to be significantly more complicated, but the
|
|
|
|
* complexity has been moved into the drivers as different buffer management
|
|
|
|
* schemes evolved.
|
|
|
|
*/
|
|
|
|
|
2002-04-27 20:47:57 +00:00
|
|
|
#include "dev/drm/drmP.h"
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
int drm_dma_setup(struct drm_device *dev)
|
2002-04-27 20:47:57 +00:00
|
|
|
{
|
|
|
|
|
2008-10-13 18:03:27 +00:00
|
|
|
dev->dma = malloc(sizeof(*dev->dma), DRM_MEM_DRIVER, M_NOWAIT | M_ZERO);
|
2003-10-24 01:48:17 +00:00
|
|
|
if (dev->dma == NULL)
|
2008-08-23 20:59:12 +00:00
|
|
|
return ENOMEM;
|
2002-04-27 20:47:57 +00:00
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
DRM_SPININIT(&dev->dma_lock, "drmdma");
|
2002-04-27 20:47:57 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
void drm_dma_takedown(struct drm_device *dev)
|
2002-04-27 20:47:57 +00:00
|
|
|
{
|
|
|
|
drm_device_dma_t *dma = dev->dma;
|
|
|
|
int i, j;
|
|
|
|
|
2003-10-24 01:48:17 +00:00
|
|
|
if (dma == NULL)
|
|
|
|
return;
|
2002-04-27 20:47:57 +00:00
|
|
|
|
2008-10-03 16:59:11 +00:00
|
|
|
/* Clear dma buffers */
|
2002-04-27 20:47:57 +00:00
|
|
|
for (i = 0; i <= DRM_MAX_ORDER; i++) {
|
|
|
|
if (dma->bufs[i].seg_count) {
|
|
|
|
DRM_DEBUG("order %d: buf_count = %d,"
|
2008-10-03 16:59:11 +00:00
|
|
|
" seg_count = %d\n", i, dma->bufs[i].buf_count,
|
|
|
|
dma->bufs[i].seg_count);
|
2002-04-27 20:47:57 +00:00
|
|
|
for (j = 0; j < dma->bufs[i].seg_count; j++) {
|
2005-11-28 23:13:57 +00:00
|
|
|
drm_pci_free(dev, dma->bufs[i].seglist[j]);
|
2002-04-27 20:47:57 +00:00
|
|
|
}
|
2008-10-13 18:03:27 +00:00
|
|
|
free(dma->bufs[i].seglist, DRM_MEM_SEGS);
|
2002-04-27 20:47:57 +00:00
|
|
|
}
|
2003-08-19 02:57:31 +00:00
|
|
|
|
|
|
|
if (dma->bufs[i].buf_count) {
|
|
|
|
for (j = 0; j < dma->bufs[i].buf_count; j++) {
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
free(dma->bufs[i].buflist[j].dev_private,
|
2008-10-13 18:03:27 +00:00
|
|
|
DRM_MEM_BUFS);
|
2002-04-27 20:47:57 +00:00
|
|
|
}
|
2008-10-13 18:03:27 +00:00
|
|
|
free(dma->bufs[i].buflist, DRM_MEM_BUFS);
|
2002-04-27 20:47:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-13 18:03:27 +00:00
|
|
|
free(dma->buflist, DRM_MEM_BUFS);
|
|
|
|
free(dma->pagelist, DRM_MEM_PAGES);
|
|
|
|
free(dev->dma, DRM_MEM_DRIVER);
|
2002-04-27 20:47:57 +00:00
|
|
|
dev->dma = NULL;
|
2008-08-23 20:59:12 +00:00
|
|
|
DRM_SPINUNINIT(&dev->dma_lock);
|
2002-04-27 20:47:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
void drm_free_buffer(struct drm_device *dev, drm_buf_t *buf)
|
2002-04-27 20:47:57 +00:00
|
|
|
{
|
2008-10-03 16:59:11 +00:00
|
|
|
if (!buf)
|
|
|
|
return;
|
2002-04-27 20:47:57 +00:00
|
|
|
|
|
|
|
buf->pending = 0;
|
2008-08-23 20:59:12 +00:00
|
|
|
buf->file_priv= NULL;
|
2002-04-27 20:47:57 +00:00
|
|
|
buf->used = 0;
|
|
|
|
}
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
void drm_reclaim_buffers(struct drm_device *dev, struct drm_file *file_priv)
|
2002-04-27 20:47:57 +00:00
|
|
|
{
|
|
|
|
drm_device_dma_t *dma = dev->dma;
|
|
|
|
int i;
|
|
|
|
|
2008-10-03 16:59:11 +00:00
|
|
|
if (!dma)
|
|
|
|
return;
|
|
|
|
|
2002-04-27 20:47:57 +00:00
|
|
|
for (i = 0; i < dma->buf_count; i++) {
|
2008-08-23 20:59:12 +00:00
|
|
|
if (dma->buflist[i]->file_priv == file_priv) {
|
2002-04-27 20:47:57 +00:00
|
|
|
switch (dma->buflist[i]->list) {
|
|
|
|
case DRM_LIST_NONE:
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
drm_free_buffer(dev, dma->buflist[i]);
|
2002-04-27 20:47:57 +00:00
|
|
|
break;
|
|
|
|
case DRM_LIST_WAIT:
|
|
|
|
dma->buflist[i]->list = DRM_LIST_RECLAIM;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Buffer already on hardware. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
/* Call into the driver-specific DMA handler */
|
2008-08-23 20:59:12 +00:00
|
|
|
int drm_dma(struct drm_device *dev, void *data, struct drm_file *file_priv)
|
2003-03-09 02:08:30 +00:00
|
|
|
{
|
|
|
|
|
2008-10-03 16:59:11 +00:00
|
|
|
if (dev->driver->dma_ioctl) {
|
2008-08-23 20:59:12 +00:00
|
|
|
/* shared code returns -errno */
|
2008-10-03 16:59:11 +00:00
|
|
|
return -dev->driver->dma_ioctl(dev, data, file_priv);
|
Update to DRM CVS as of 2005-04-12, bringing many changes:
- Split core DRM routines back into their own module, rather than using the
nasty templated system like before.
- Development-class R300 support in radeon driver (requires userland pieces, of
course).
- Mach64 driver (haven't tested in a while -- my mach64s no longer fit in the
testbox). Covers Rage Pros, Rage Mobility P/M, Rage XL, and some others.
- i915 driver files, which just need to get drm_drv.c fixed to allow attachment
to the drmsub device. Covers i830 through i915 integrated graphics.
- savage driver files, which should require minimal changes to work. Covers the
Savage3D, Savage IX/MX, Savage 4, ProSavage.
- Support for color and texture tiling and HyperZ features of Radeon.
Thanks to: scottl (much p4 handholding)
Jung-uk Kim (helpful prodding)
PR: [1] kern/76879, [2] kern/72548
Submitted by: [1] Alex, lesha at intercaf dot ru
[2] Shaun Jurrens, shaun at shamz dot net
2005-04-16 03:44:47 +00:00
|
|
|
} else {
|
|
|
|
DRM_DEBUG("DMA ioctl on driver with no dma handler\n");
|
|
|
|
return EINVAL;
|
2002-04-27 20:47:57 +00:00
|
|
|
}
|
|
|
|
}
|