From 3708f8da9c3447c4031a062c179ab695c2d9e3e2 Mon Sep 17 00:00:00 2001 From: Bill Paul Date: Wed, 15 Aug 2001 17:26:54 +0000 Subject: [PATCH] Teach bus_dmamem_free() about contigfree(). This is a bit of a hack, but it's better than the buggy behavior we have now. If we contigmalloc() buffers in bus_dmamem_alloc(), then we must configfree() them in bus_dmamem_free(). Trying to free() them is wrong, and will cause a panic (at least, it does on the alpha.) I tripped over this when trying to kldunload my busdma-ified if_rl driver. --- sys/alpha/alpha/busdma_machdep.c | 5 ++++- sys/amd64/amd64/busdma_machdep.c | 3 +++ sys/i386/i386/busdma_machdep.c | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/sys/alpha/alpha/busdma_machdep.c b/sys/alpha/alpha/busdma_machdep.c index ea984c35e1a9..71256360ae59 100644 --- a/sys/alpha/alpha/busdma_machdep.c +++ b/sys/alpha/alpha/busdma_machdep.c @@ -384,7 +384,10 @@ bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map) */ if (map != &nobounce_dmamap) panic("bus_dmamem_free: Invalid map freed\n"); - free(vaddr, M_DEVBUF); + if ((dmat->maxsize <= PAGE_SIZE) && dmat->lowaddr >= ptoa(Maxmem)) { + free(vaddr, M_DEVBUF); + else + contigfree(vaddr, dmat->maxsize, M_DEVBUF); } #define BUS_DMAMAP_NSEGS ((BUS_SPACE_MAXSIZE / PAGE_SIZE) + 1) diff --git a/sys/amd64/amd64/busdma_machdep.c b/sys/amd64/amd64/busdma_machdep.c index d99e22ad625d..f20e80fff6da 100644 --- a/sys/amd64/amd64/busdma_machdep.c +++ b/sys/amd64/amd64/busdma_machdep.c @@ -359,8 +359,11 @@ bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map) if (map != NULL) panic("bus_dmamem_free: Invalid map freed\n"); /* XXX There is no "contigfree" and "free" doesn't work */ + /* There is too a contigfree, and we need to use it here. */ if ((dmat->maxsize <= PAGE_SIZE) && dmat->lowaddr >= ptoa(Maxmem)) free(vaddr, M_DEVBUF); + else + contigfree(vaddr, dmat->maxsize, M_DEVBUF); } #define BUS_DMAMAP_NSEGS ((BUS_SPACE_MAXSIZE / PAGE_SIZE) + 1) diff --git a/sys/i386/i386/busdma_machdep.c b/sys/i386/i386/busdma_machdep.c index d99e22ad625d..f20e80fff6da 100644 --- a/sys/i386/i386/busdma_machdep.c +++ b/sys/i386/i386/busdma_machdep.c @@ -359,8 +359,11 @@ bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map) if (map != NULL) panic("bus_dmamem_free: Invalid map freed\n"); /* XXX There is no "contigfree" and "free" doesn't work */ + /* There is too a contigfree, and we need to use it here. */ if ((dmat->maxsize <= PAGE_SIZE) && dmat->lowaddr >= ptoa(Maxmem)) free(vaddr, M_DEVBUF); + else + contigfree(vaddr, dmat->maxsize, M_DEVBUF); } #define BUS_DMAMAP_NSEGS ((BUS_SPACE_MAXSIZE / PAGE_SIZE) + 1)