Add work-in-progress of NetBSD-specific code. I will be committing a lot
more changes shortly (as soon as I work out the mmap offset insanity).
This commit is contained in:
parent
91174b68e0
commit
c693c2b2dd
|
@ -0,0 +1,132 @@
|
|||
/* $NetBSD: drm_netbsd.c,v 1.1 2008/05/28 04:52:48 bjs Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Blair Sadewitz.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <dev/drm/drmP.h>
|
||||
|
||||
/* XXX Most everything the DRM wants is expressed in pages. There are possible
|
||||
scenarios where e.g. the page size does not equal the page size of the GART,
|
||||
but our DRM does not work on those platforms yet. */
|
||||
|
||||
struct drm_dmamem *
|
||||
drm_dmamem_pgalloc(drm_device_t *dev, size_t pages)
|
||||
{
|
||||
struct drm_dmamem *mem = NULL;
|
||||
size_t size = pages << PAGE_SHIFT;
|
||||
int ret = 0;
|
||||
|
||||
mem = malloc(sizeof(*mem), M_DRM, M_NOWAIT | M_ZERO);
|
||||
if (mem == NULL)
|
||||
return NULL;
|
||||
|
||||
mem->phase = 0;
|
||||
|
||||
mem->dd_segs = malloc(sizeof(*mem->dd_segs) * pages, M_DRM,
|
||||
M_NOWAIT | M_ZERO);
|
||||
if (mem->dd_segs == NULL)
|
||||
goto error;
|
||||
|
||||
mem->dd_dmat = dev->pa.pa_dmat;
|
||||
mem->dd_size = size;
|
||||
|
||||
if (bus_dmamap_create(dev->pa.pa_dmat, size, pages, PAGE_SIZE, 0,
|
||||
BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &mem->dd_dmam) != 0)
|
||||
goto error;
|
||||
mem->phase++;
|
||||
|
||||
if ((ret = bus_dmamem_alloc(dev->pa.pa_dmat, size, PAGE_SIZE, 0,
|
||||
mem->dd_segs, pages, &mem->dd_nsegs, BUS_DMA_NOWAIT)) != 0) {
|
||||
goto error;
|
||||
}
|
||||
mem->phase++;
|
||||
|
||||
if (bus_dmamem_map(dev->pa.pa_dmat, mem->dd_segs, mem->dd_nsegs, size,
|
||||
&mem->dd_kva, BUS_DMA_COHERENT|BUS_DMA_NOWAIT) != 0)
|
||||
goto error;
|
||||
mem->phase++;
|
||||
|
||||
if (bus_dmamap_load(dev->pa.pa_dmat, mem->dd_dmam, mem->dd_kva, size,
|
||||
NULL, BUS_DMA_NOWAIT) != 0)
|
||||
goto error;
|
||||
mem->phase++;
|
||||
|
||||
memset(mem->dd_kva, 0, size);
|
||||
|
||||
return mem;
|
||||
error:
|
||||
DRM_DEBUG("allocation failed; teardown sequence follows:\n");
|
||||
drm_dmamem_free(mem);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
drm_dmamem_free(struct drm_dmamem *mem)
|
||||
{
|
||||
if (mem == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (mem->phase) {
|
||||
case DRM_DMAMAP_LOAD:
|
||||
DRM_DEBUG("bus_dmamap_unload: tag (%p), map (%p)\n",
|
||||
(void *)mem->dd_dmat, (void *)mem->dd_dmam);
|
||||
bus_dmamap_unload(mem->dd_dmat, mem->dd_dmam);
|
||||
/* FALLTHRU */
|
||||
case DRM_DMAMEM_MAP:
|
||||
DRM_DEBUG("bus_dmamem_unmap: tag (%p), kva (%p), size (%zd)\n",
|
||||
mem->dd_dmat, mem->dd_kva, mem->dd_size);
|
||||
bus_dmamem_unmap(mem->dd_dmat, mem->dd_kva, mem->dd_size);
|
||||
/* FALLTHRU */
|
||||
case DRM_DMAMEM_ALLOC:
|
||||
DRM_DEBUG("bus_dmamem_free: tag (%p), segs (%p), nsegs (%i)\n",
|
||||
mem->dd_dmat, mem->dd_segs, mem->dd_nsegs);
|
||||
bus_dmamem_free(mem->dd_dmat, mem->dd_segs,
|
||||
mem->dd_nsegs);
|
||||
/* FALLTHRU */
|
||||
case DRM_DMAMAP_CREATE:
|
||||
DRM_DEBUG("bus_dmamap_destroy: tag (%p), map (%p)\n",
|
||||
(void *)mem->dd_dmat, (void *)mem->dd_dmam);
|
||||
bus_dmamap_destroy(mem->dd_dmat, mem->dd_dmam);
|
||||
/* FALLTHRU */
|
||||
case DRM_DMAMEM_INIT:
|
||||
if (mem->dd_segs != NULL) {
|
||||
free(mem->dd_segs, M_DRM);
|
||||
mem->dd_segs = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
free(mem, M_DRM);
|
||||
mem = NULL;
|
||||
|
||||
return;
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/* $NetBSD: drm_netbsd.h,v 1.1 2008/05/28 04:52:48 bjs Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Blair Sadewitz.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#ifndef _DEV_DRM_DRMNETBSD_H_
|
||||
#define _DEV_DRM_DRMNETBSD_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/bus.h>
|
||||
|
||||
#define DRM_DMAMEM_INIT 0x000
|
||||
#define DRM_DMAMAP_CREATE 0x001
|
||||
#define DRM_DMAMEM_ALLOC 0x002
|
||||
#define DRM_DMAMEM_MAP 0x004
|
||||
#define DRM_DMAMAP_LOAD 0x008
|
||||
|
||||
#define DRM_DMAMEM_BUSADDR(__m) ((__m)->dd_dmam->dm_segs[0].ds_addr)
|
||||
#define DRM_DMAMEM_SEGADDR(__m, __s) ((__m)->dd_dmam->dm_segs[__s].ds_addr)
|
||||
#define DRM_DMAMEM_SEGSIZE(__m, __s) ((__m)->dd_dmam->dm_segs[__s].ds_len)
|
||||
#define DRM_DMAMEM_KERNADDR(__m) ((__m)->dd_kva)
|
||||
|
||||
#define RWLOCK_CONTENTION(rwlock) do { } while (!rw_tryupgrade(rwlock))
|
||||
|
||||
/* for dma_lock */
|
||||
|
||||
struct drm_dmamem {
|
||||
bus_dma_tag_t dd_dmat;
|
||||
bus_dmamap_t dd_dmam;
|
||||
bus_dma_segment_t *dd_segs;
|
||||
int dd_nsegs;
|
||||
size_t dd_size;
|
||||
void *dd_kva;
|
||||
unsigned int phase;
|
||||
};
|
||||
|
||||
struct drm_dmamem *drm_dmamem_pgalloc(struct drm_device *, size_t);
|
||||
void drm_dmamem_free(struct drm_dmamem *);
|
||||
|
||||
#endif /* _DEV_DRM_DRMNETBSD_H_ */
|
Loading…
Reference in New Issue