diff options
author | Owain Ainsworth <oga@cvs.openbsd.org> | 2008-02-05 19:34:02 +0000 |
---|---|---|
committer | Owain Ainsworth <oga@cvs.openbsd.org> | 2008-02-05 19:34:02 +0000 |
commit | f289dc3bef96d354edcd20bc6d7913fc4296a8b1 (patch) | |
tree | b369b4c83a195e5f51d0ad5c7eb2fb2aeb214566 /sys/dev/pci/drm | |
parent | bb050295fa2117ae556f13f21af826736ac73f5d (diff) |
drm_pci_alloc allocates memory using bus_dma, but then doesn't use dmamaps.
This is unportable to some architectures, fix it. While i'm here, kill
he defines for netbsd aprint_ and just use the DRM_* macros.
ok miod@
Diffstat (limited to 'sys/dev/pci/drm')
-rw-r--r-- | sys/dev/pci/drm/drmP.h | 3 | ||||
-rw-r--r-- | sys/dev/pci/drm/drm_irq.c | 2 | ||||
-rw-r--r-- | sys/dev/pci/drm/drm_pci.c | 60 |
3 files changed, 40 insertions, 25 deletions
diff --git a/sys/dev/pci/drm/drmP.h b/sys/dev/pci/drm/drmP.h index c3f1f5f2ce4..f60c46e277d 100644 --- a/sys/dev/pci/drm/drmP.h +++ b/sys/dev/pci/drm/drmP.h @@ -275,8 +275,6 @@ extern drm_device_t *drm_units[]; #define DRM_SYSCTL_HANDLER_ARGS (int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, \ size_t newlen, struct proc *p) /* Deal with netbsd code where only the print statements differ */ -#define aprint_error printf -#define aprint_normal printf #define printk printf #define __unused /* nothing */ /* @@ -594,6 +592,7 @@ typedef struct drm_dma_handle { bus_dma_tag_t tag; bus_dmamap_t map; #elif defined(__NetBSD__) || defined(__OpenBSD__) + bus_dmamap_t dmamap; bus_dma_segment_t seg; void *addr; bus_addr_t dmaaddr; diff --git a/sys/dev/pci/drm/drm_irq.c b/sys/dev/pci/drm/drm_irq.c index 4910bae2187..a1573c723a3 100644 --- a/sys/dev/pci/drm/drm_irq.c +++ b/sys/dev/pci/drm/drm_irq.c @@ -175,7 +175,7 @@ drm_irq_install(drm_device_t *dev) retcode = ENOENT; goto err; } - aprint_normal("%s: interrupting at %s\n", dev->device.dv_xname, istr); + DRM_DEBUG("%s: interrupting at %s\n", dev->device.dv_xname, istr); #endif /* After installing handler */ diff --git a/sys/dev/pci/drm/drm_pci.c b/sys/dev/pci/drm/drm_pci.c index 08aad19fc5f..4adcd27e9c1 100644 --- a/sys/dev/pci/drm/drm_pci.c +++ b/sys/dev/pci/drm/drm_pci.c @@ -100,39 +100,53 @@ drm_pci_alloc(drm_device_t *dev, size_t size, size_t align, dma_addr_t maxaddr) free(dmah, M_DRM); return NULL; } + + return dmah; #elif defined(__NetBSD__) || defined(__OpenBSD__) - ret = bus_dmamem_alloc(dev->pa.pa_dmat, size, align, 0, - &dmah->seg, 1, &nsegs, BUS_DMA_NOWAIT); - if (ret != 0) { - aprint_error("%s: bus_dmamem_alloc(%zd, %zd) returned %d\n", - __func__, size, align, ret); - free(dmah, M_DRM); - return NULL; + if (bus_dmamap_create(dev->pa.pa_dmat, size, 1, size, 0, + BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &dmah->dmamap) != 0) + goto dmahfree; + + if (bus_dmamem_alloc(dev->pa.pa_dmat, size, align, 0, + &dmah->seg, 1, &nsegs, BUS_DMA_NOWAIT) != 0) { + DRM_ERROR("bus_dmamem_alloc(%zd, %zd) returned %d\n", + size, align, ret); + goto destroy; } if(nsegs != 1) { - aprint_error("%s: bus_dmamem_alloc(%zd) returned %d segments\n", - __func__, size, nsegs); - bus_dmamem_free(dev->pa.pa_dmat, &dmah->seg, nsegs); - free(dmah, M_DRM); - return NULL; + DRM_ERROR("bus_dmamem_alloc(%zd) returned %d segments\n", + size, nsegs); + goto free; } - ret = bus_dmamem_map(dev->pa.pa_dmat, &dmah->seg, 1, size, (caddr_t*)&dmah->addr, - BUS_DMA_NOWAIT); - if (ret != 0) { - bus_dmamem_free(dev->pa.pa_dmat, &dmah->seg, 1); - aprint_error("%s: bus_dmamem_map() failed %d\n", __func__, - ret); - free(dmah, M_DRM); - return NULL; + if (bus_dmamem_map(dev->pa.pa_dmat, &dmah->seg, 1, size, + (caddr_t*)&dmah->addr, BUS_DMA_NOWAIT) != 0) { + DRM_ERROR("bus_dmamem_map() failed %d\n", ret); + goto free; } - dmah->busaddr = dmah->seg.ds_addr; + if (bus_dmamap_load(dev->pa.pa_dmat, dmah->dmamap, dmah->addr, size, + NULL, BUS_DMA_NOWAIT) != 0) + goto unmap; + + dmah->busaddr = dmah->dmamap->dm_segs[0].ds_addr; dmah->vaddr = dmah->addr; dmah->size = size; -#endif return dmah; + +unmap: + bus_dmamem_unmap(dev->pa.pa_dmat, dmah->addr, size); +free: + bus_dmamem_free(dev->pa.pa_dmat, &dmah->seg, 1); +destroy: + bus_dmamap_destroy(dev->pa.pa_dmat, dmah->dmamap); +dmahfree: + free(dmah, M_DRM); + + return (NULL); +#endif + } /** @@ -148,8 +162,10 @@ drm_pci_free(drm_device_t *dev, drm_dma_handle_t *dmah) bus_dmamem_free(dmah->tag, dmah->vaddr, dmah->map); bus_dma_tag_destroy(dmah->tag); #elif defined(__NetBSD__) || defined(__OpenBSD__) + bus_dmamap_unload(dev->pa.pa_dmat, dmah->dmamap); bus_dmamem_unmap(dev->pa.pa_dmat, dmah->vaddr, dmah->size); bus_dmamem_free(dev->pa.pa_dmat, &dmah->seg, 1); + bus_dmamap_destroy(dev->pa.pa_dmat, dmah->dmamap); #endif free(dmah, M_DRM); |