2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2003-08-19 02:57:31 +00:00
|
|
|
* Copyright 2003 Eric Anholt.
|
|
|
|
* 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 THE
|
|
|
|
* AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
2005-11-28 23:13:57 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2008-08-23 20:59:12 +00:00
|
|
|
/**
|
|
|
|
* \file drm_pci.h
|
|
|
|
* \brief PCI consistent, DMA-accessible memory allocation.
|
|
|
|
*
|
|
|
|
* \author Eric Anholt <anholt@FreeBSD.org>
|
|
|
|
*/
|
|
|
|
|
2003-08-19 02:57:31 +00:00
|
|
|
#include "dev/drm/drmP.h"
|
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
/** \name PCI memory */
|
|
|
|
/*@{*/
|
|
|
|
|
2005-11-28 23:13:57 +00:00
|
|
|
static void
|
|
|
|
drm_pci_busdma_callback(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
|
|
|
|
{
|
|
|
|
drm_dma_handle_t *dmah = arg;
|
|
|
|
|
|
|
|
if (error != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
KASSERT(nsegs == 1, ("drm_pci_busdma_callback: bad dma segment count"));
|
|
|
|
dmah->busaddr = segs[0].ds_addr;
|
|
|
|
}
|
|
|
|
|
2003-08-19 02:57:31 +00:00
|
|
|
/**
|
|
|
|
* \brief Allocate a physically contiguous DMA-accessible consistent
|
|
|
|
* memory block.
|
|
|
|
*/
|
2005-11-28 23:13:57 +00:00
|
|
|
drm_dma_handle_t *
|
2008-08-23 20:59:12 +00:00
|
|
|
drm_pci_alloc(struct drm_device *dev, size_t size,
|
|
|
|
size_t align, dma_addr_t maxaddr)
|
2003-08-19 02:57:31 +00:00
|
|
|
{
|
2005-11-28 23:13:57 +00:00
|
|
|
drm_dma_handle_t *dmah;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Need power-of-two alignment, so fail the allocation if it isn't. */
|
|
|
|
if ((align & (align - 1)) != 0) {
|
|
|
|
DRM_ERROR("drm_pci_alloc with non-power-of-two alignment %d\n",
|
|
|
|
(int)align);
|
|
|
|
return NULL;
|
|
|
|
}
|
2003-08-19 02:57:31 +00:00
|
|
|
|
2008-10-13 18:03:27 +00:00
|
|
|
dmah = malloc(sizeof(drm_dma_handle_t), DRM_MEM_DMA, M_ZERO | M_NOWAIT);
|
2005-11-28 23:13:57 +00:00
|
|
|
if (dmah == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2008-09-09 02:05:03 +00:00
|
|
|
/* Make sure we aren't holding locks here */
|
2008-10-03 16:59:11 +00:00
|
|
|
mtx_assert(&dev->dev_lock, MA_NOTOWNED);
|
2008-09-09 02:05:03 +00:00
|
|
|
if (mtx_owned(&dev->dev_lock))
|
|
|
|
DRM_ERROR("called while holding dev_lock\n");
|
2008-10-03 16:59:11 +00:00
|
|
|
mtx_assert(&dev->dma_lock, MA_NOTOWNED);
|
2008-09-09 02:05:03 +00:00
|
|
|
if (mtx_owned(&dev->dma_lock))
|
|
|
|
DRM_ERROR("called while holding dma_lock\n");
|
|
|
|
|
2005-11-28 23:13:57 +00:00
|
|
|
ret = bus_dma_tag_create(NULL, align, 0, /* tag, align, boundary */
|
|
|
|
maxaddr, BUS_SPACE_MAXADDR, /* lowaddr, highaddr */
|
|
|
|
NULL, NULL, /* filtfunc, filtfuncargs */
|
|
|
|
size, 1, size, /* maxsize, nsegs, maxsegsize */
|
2009-03-09 07:47:03 +00:00
|
|
|
0, NULL, NULL, /* flags, lockfunc, lockfuncargs */
|
2005-11-28 23:13:57 +00:00
|
|
|
&dmah->tag);
|
|
|
|
if (ret != 0) {
|
2008-10-13 18:03:27 +00:00
|
|
|
free(dmah, DRM_MEM_DMA);
|
2005-11-28 23:13:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-03-09 07:47:03 +00:00
|
|
|
ret = bus_dmamem_alloc(dmah->tag, &dmah->vaddr,
|
2009-03-30 18:01:42 +00:00
|
|
|
BUS_DMA_WAITOK | BUS_DMA_ZERO | BUS_DMA_NOCACHE, &dmah->map);
|
2005-11-28 23:13:57 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
bus_dma_tag_destroy(dmah->tag);
|
2008-10-13 18:03:27 +00:00
|
|
|
free(dmah, DRM_MEM_DMA);
|
2005-11-28 23:13:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2008-09-09 02:05:03 +00:00
|
|
|
|
2005-11-28 23:13:57 +00:00
|
|
|
ret = bus_dmamap_load(dmah->tag, dmah->map, dmah->vaddr, size,
|
2009-03-09 07:47:03 +00:00
|
|
|
drm_pci_busdma_callback, dmah, BUS_DMA_NOWAIT);
|
2005-11-28 23:13:57 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
bus_dmamem_free(dmah->tag, dmah->vaddr, dmah->map);
|
|
|
|
bus_dma_tag_destroy(dmah->tag);
|
2008-10-13 18:03:27 +00:00
|
|
|
free(dmah, DRM_MEM_DMA);
|
2005-11-28 23:13:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dmah;
|
2003-08-19 02:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Free a DMA-accessible consistent memory block.
|
|
|
|
*/
|
|
|
|
void
|
2008-08-23 20:59:12 +00:00
|
|
|
drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah)
|
2003-08-19 02:57:31 +00:00
|
|
|
{
|
2005-11-28 23:13:57 +00:00
|
|
|
if (dmah == NULL)
|
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
|
|
|
return;
|
2005-11-28 23:13:57 +00:00
|
|
|
|
|
|
|
bus_dmamem_free(dmah->tag, dmah->vaddr, dmah->map);
|
|
|
|
bus_dma_tag_destroy(dmah->tag);
|
|
|
|
|
2008-10-13 18:03:27 +00:00
|
|
|
free(dmah, DRM_MEM_DMA);
|
2003-08-19 02:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*@}*/
|