summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2005-11-29 03:12:12 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2005-11-29 03:12:12 +0000
commitf94dbdd04e11da76f1a4c1fab15919c3b2a2807d (patch)
tree5b7433ae08e1faa5ba45568b550b50671de0d326
parentadb4778804adba0245306281be53c4c3659bcb68 (diff)
Fix bus_dma code to eliminate my busted logic, align usage with man
page, adopt jason's suggestions and use the goto based unwind marco likes. Based on marco's original diff. ok marco@ jason@
-rw-r--r--sys/dev/ic/aic79xx.c81
-rw-r--r--sys/dev/ic/aic79xx.h4
2 files changed, 34 insertions, 51 deletions
diff --git a/sys/dev/ic/aic79xx.c b/sys/dev/ic/aic79xx.c
index 7878a6338f3..877f99ea699 100644
--- a/sys/dev/ic/aic79xx.c
+++ b/sys/dev/ic/aic79xx.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: aic79xx.c,v 1.30 2005/11/27 07:46:25 krw Exp $ */
+/* $OpenBSD: aic79xx.c,v 1.31 2005/11/29 03:12:11 krw Exp $ */
/*
* Copyright (c) 2004 Milos Urbanek, Kenneth R. Westerback & Marco Peereboom
@@ -10263,81 +10263,62 @@ ahd_createdmamem(struct ahd_softc *ahd, size_t size, struct map_node *map,
const char *what)
{
bus_dma_tag_t tag = ahd->parent_dmat;
- bus_dma_segment_t seg;
- uint8_t *vaddr;
- int nseg, error, level = 0;
+ int nseg, error;
bzero(map, sizeof(*map));
- if ((error = bus_dmamem_alloc(tag, size, PAGE_SIZE, 0, &seg, 1, &nseg,
- BUS_DMA_NOWAIT)) != 0) {
- printf("%s: failed to allocate DMA mem for %s, error = %d\n",
+ if ((error = bus_dmamap_create(tag, size, 1, size, 0, BUS_DMA_NOWAIT,
+ &map->dmamap)) != 0) {
+ printf("%s: failed to create DMA map for %s, error = %d\n",
ahd_name(ahd), what, error);
- goto out;
+ return (error);
}
- level++;
- if ((error = bus_dmamem_map(tag, &seg, nseg, size, (caddr_t *)&vaddr,
- BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
- printf("%s: failed to map DMA mem for %s, error = %d\n",
+ if ((error = bus_dmamem_alloc(tag, size, PAGE_SIZE, 0, &map->dmaseg,
+ 1, &nseg, BUS_DMA_NOWAIT)) != 0) {
+ printf("%s: failed to allocate DMA mem for %s, error = %d\n",
ahd_name(ahd), what, error);
- goto out;
+ goto destroy;
}
- map->vaddr = vaddr;
- level++;
- if ((error = bus_dmamap_create(tag, size, 1, size, 0, BUS_DMA_NOWAIT,
- &map->dmamap)) != 0) {
- printf("%s: failed to create DMA map for %s, error = %d\n",
+ if ((error = bus_dmamem_map(tag, &map->dmaseg, nseg, size,
+ (caddr_t *)&map->vaddr, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
+ printf("%s: failed to map DMA mem for %s, error = %d\n",
ahd_name(ahd), what, error);
- goto out;
+ goto free;
}
- level++;
- if ((error = bus_dmamap_load(tag, map->dmamap, vaddr, size, NULL,
+ if ((error = bus_dmamap_load(tag, map->dmamap, map->vaddr, size, NULL,
BUS_DMA_NOWAIT)) != 0) {
printf("%s: failed to load DMA map for %s, error = %d\n",
ahd_name(ahd), what, error);
- goto out;
+ goto unmap;
}
+
+ map->size = size;
map->busaddr = map->dmamap->dm_segs[0].ds_addr;
+ return (0);
- return 0;
-out:
- switch (level) {
- case 3:
- bus_dmamap_destroy(tag, map->dmamap);
- /* FALLTHROUGH */
- case 2:
- bus_dmamem_unmap(tag, vaddr, size);
- /* FALLTHROUGH */
- case 1:
- bus_dmamem_free(tag, &seg, nseg);
- break;
- default:
- break;
- }
+unmap:
+ bus_dmamem_unmap(tag, map->vaddr, size);
+free:
+ bus_dmamem_free(tag, &map->dmaseg, 1);
+destroy:
+ bus_dmamap_destroy(tag, map->dmamap);
- return error;
+ bzero(map, sizeof(*map));
+ return (error);
}
void
ahd_freedmamem(struct ahd_softc* ahd, struct map_node *map)
{
bus_dma_tag_t tag = ahd->parent_dmat;
- bus_dmamap_t dmamap = map->dmamap;
- size_t size = 0;
- int i;
- for(i = 0; i < dmamap->dm_nsegs; i++)
- size += dmamap->dm_segs[i].ds_len;
-
- /* i == dmamap->dm_nsegs, which is invalidated by bus_dmamap_unload. */
-
- bus_dmamap_unload(tag, dmamap);
- bus_dmamem_unmap(tag, map->vaddr, size);
- bus_dmamem_free(tag, dmamap->dm_segs, i);
- bus_dmamap_destroy(tag, dmamap);
+ bus_dmamap_unload(tag, map->dmamap);
+ bus_dmamem_unmap(tag, map->vaddr, map->size);
+ bus_dmamem_free(tag, &map->dmaseg, 1);
+ bus_dmamap_destroy(tag, map->dmamap);
}
char *
diff --git a/sys/dev/ic/aic79xx.h b/sys/dev/ic/aic79xx.h
index 1a917cf6eda..5b4f3404285 100644
--- a/sys/dev/ic/aic79xx.h
+++ b/sys/dev/ic/aic79xx.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: aic79xx.h,v 1.18 2004/12/30 17:29:55 krw Exp $ */
+/* $OpenBSD: aic79xx.h,v 1.19 2005/11/29 03:12:11 krw Exp $ */
/*
* Copyright (c) 2004 Milos Urbanek, Kenneth R. Westerback & Marco Peereboom
@@ -587,6 +587,8 @@ struct map_node {
bus_dmamap_t dmamap;
bus_addr_t busaddr;
uint8_t *vaddr;
+ bus_dma_segment_t dmaseg;
+ size_t size;
SLIST_ENTRY(map_node) links;
};