From 4e543dc21243ab3f7b1444dd28899ce4ce4f7a67 Mon Sep 17 00:00:00 2001 From: mux Date: Sun, 27 Jul 2003 13:52:10 +0000 Subject: [PATCH] - Introduce a new busdma flag BUS_DMA_ZERO to request for zero'ed memory in bus_dmamem_alloc(). This is possible now that contigmalloc() supports the M_ZERO flag. - Remove the locking of Giant around calls to contigmalloc() since contigmalloc() now grabs Giant itself. --- sys/alpha/alpha/busdma_machdep.c | 19 +++++++++++-------- sys/alpha/include/bus.h | 1 + sys/amd64/amd64/busdma_machdep.c | 19 +++++++++++-------- sys/amd64/include/bus_dma.h | 1 + sys/i386/i386/busdma_machdep.c | 19 +++++++++++-------- sys/i386/include/bus_dma.h | 1 + sys/ia64/ia64/busdma_machdep.c | 19 +++++++++++-------- sys/ia64/include/bus.h | 1 + sys/powerpc/include/bus.h | 1 + sys/powerpc/powerpc/busdma_machdep.c | 17 +++++++++++------ sys/sparc64/include/bus.h | 1 + sys/sparc64/sparc64/bus_machdep.c | 16 ++++++++++------ sys/sys/bus_dma.h | 1 + 13 files changed, 72 insertions(+), 44 deletions(-) diff --git a/sys/alpha/alpha/busdma_machdep.c b/sys/alpha/alpha/busdma_machdep.c index d743e8da1d0..279d3a68f20 100644 --- a/sys/alpha/alpha/busdma_machdep.c +++ b/sys/alpha/alpha/busdma_machdep.c @@ -413,24 +413,29 @@ int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, bus_dmamap_t *mapp) { + int mflags; + + if (flags & BUS_DMA_NOWAIT) + mflags = M_NOWAIT; + else + mflags = M_WAITOK; + if (flags & BUS_DMA_ZERO) + mflags |= M_ZERO; + /* If we succeed, no mapping/bouncing will be required */ *mapp = &nobounce_dmamap; if ((dmat->maxsize <= PAGE_SIZE) && dmat->lowaddr >= ptoa(Maxmem)) { - *vaddr = malloc(dmat->maxsize, M_DEVBUF, - (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK); + *vaddr = malloc(dmat->maxsize, M_DEVBUF, mflags); } else { /* * XXX Use Contigmalloc until it is merged into this facility * and handles multi-seg allocations. Nobody is doing * multi-seg allocations yet though. */ - mtx_lock(&Giant); - *vaddr = contigmalloc(dmat->maxsize, M_DEVBUF, - (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK, + *vaddr = contigmalloc(dmat->maxsize, M_DEVBUF, mflags, 0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : 1ul, dmat->boundary); - mtx_unlock(&Giant); } if (*vaddr == NULL) return (ENOMEM); @@ -894,13 +899,11 @@ alloc_bounce_pages(bus_dma_tag_t dmat, u_int numpages) if (bpage == NULL) break; - mtx_lock(&Giant); bpage->vaddr = (vm_offset_t)contigmalloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT, 0ul, dmat->lowaddr, PAGE_SIZE, dmat->boundary); - mtx_unlock(&Giant); if (bpage->vaddr == 0) { free(bpage, M_DEVBUF); break; diff --git a/sys/alpha/include/bus.h b/sys/alpha/include/bus.h index 582484c0b22..53eefd85754 100644 --- a/sys/alpha/include/bus.h +++ b/sys/alpha/include/bus.h @@ -470,6 +470,7 @@ void busspace_generic_barrier(struct alpha_busspace *space, #define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */ #define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */ #define BUS_DMA_COHERENT 0x04 /* hint: map memory in a coherent way */ +#define BUS_DMA_ZERO 0x08 /* allocate zero'ed memory */ #define BUS_DMA_ISA 0x10 /* map memory for ISA dma */ #define BUS_DMA_BUS2 0x20 /* placeholders for bus functions... */ #define BUS_DMA_BUS3 0x40 diff --git a/sys/amd64/amd64/busdma_machdep.c b/sys/amd64/amd64/busdma_machdep.c index 2339641d611..058210bd2b0 100644 --- a/sys/amd64/amd64/busdma_machdep.c +++ b/sys/amd64/amd64/busdma_machdep.c @@ -390,25 +390,30 @@ int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, bus_dmamap_t *mapp) { + int mflags; + + if (flags & BUS_DMA_NOWAIT) + mflags = M_NOWAIT; + else + mflags = M_WAITOK; + if (flags & BUS_DMA_ZERO) + mflags |= M_ZERO; + /* If we succeed, no mapping/bouncing will be required */ *mapp = NULL; if ((dmat->maxsize <= PAGE_SIZE) && dmat->lowaddr >= ptoa((vm_paddr_t)Maxmem)) { - *vaddr = malloc(dmat->maxsize, M_DEVBUF, - (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK); + *vaddr = malloc(dmat->maxsize, M_DEVBUF, mflags); } else { /* * XXX Use Contigmalloc until it is merged into this facility * and handles multi-seg allocations. Nobody is doing * multi-seg allocations yet though. */ - mtx_lock(&Giant); - *vaddr = contigmalloc(dmat->maxsize, M_DEVBUF, - (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK, + *vaddr = contigmalloc(dmat->maxsize, M_DEVBUF, mflags, 0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : 1ul, dmat->boundary); - mtx_unlock(&Giant); } if (*vaddr == NULL) return (ENOMEM); @@ -809,13 +814,11 @@ alloc_bounce_pages(bus_dma_tag_t dmat, u_int numpages) if (bpage == NULL) break; - mtx_lock(&Giant); bpage->vaddr = (vm_offset_t)contigmalloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT, 0ul, dmat->lowaddr, PAGE_SIZE, dmat->boundary); - mtx_unlock(&Giant); if (bpage->vaddr == 0) { free(bpage, M_DEVBUF); break; diff --git a/sys/amd64/include/bus_dma.h b/sys/amd64/include/bus_dma.h index b0928f1b075..b9129e97cf5 100644 --- a/sys/amd64/include/bus_dma.h +++ b/sys/amd64/include/bus_dma.h @@ -79,6 +79,7 @@ #define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */ #define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */ #define BUS_DMA_COHERENT 0x04 /* hint map memory in a coherent way */ +#define BUS_DMA_ZERO 0x08 /* allocate zero'ed memory */ #define BUS_DMA_BUS1 0x10 /* placeholders for bus functions... */ #define BUS_DMA_BUS2 0x20 #define BUS_DMA_BUS3 0x40 diff --git a/sys/i386/i386/busdma_machdep.c b/sys/i386/i386/busdma_machdep.c index 5ebaa003c46..8bf5b0b06c3 100644 --- a/sys/i386/i386/busdma_machdep.c +++ b/sys/i386/i386/busdma_machdep.c @@ -386,25 +386,30 @@ int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, bus_dmamap_t *mapp) { + int mflags; + + if (flags & BUS_DMA_NOWAIT) + mflags = M_NOWAIT; + else + mflags = M_WAITOK; + if (flags & BUS_DMA_ZERO) + mflags |= M_ZERO; + /* If we succeed, no mapping/bouncing will be required */ *mapp = NULL; if ((dmat->maxsize <= PAGE_SIZE) && dmat->lowaddr >= ptoa((vm_paddr_t)Maxmem)) { - *vaddr = malloc(dmat->maxsize, M_DEVBUF, - (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK); + *vaddr = malloc(dmat->maxsize, M_DEVBUF, mflags); } else { /* * XXX Use Contigmalloc until it is merged into this facility * and handles multi-seg allocations. Nobody is doing * multi-seg allocations yet though. */ - mtx_lock(&Giant); - *vaddr = contigmalloc(dmat->maxsize, M_DEVBUF, - (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK, + *vaddr = contigmalloc(dmat->maxsize, M_DEVBUF, mflags, 0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : 1ul, dmat->boundary); - mtx_unlock(&Giant); } if (*vaddr == NULL) return (ENOMEM); @@ -805,13 +810,11 @@ alloc_bounce_pages(bus_dma_tag_t dmat, u_int numpages) if (bpage == NULL) break; - mtx_lock(&Giant); bpage->vaddr = (vm_offset_t)contigmalloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT, 0ul, dmat->lowaddr, PAGE_SIZE, dmat->boundary); - mtx_unlock(&Giant); if (bpage->vaddr == 0) { free(bpage, M_DEVBUF); break; diff --git a/sys/i386/include/bus_dma.h b/sys/i386/include/bus_dma.h index 3539a33cc6d..9b75eae9aea 100644 --- a/sys/i386/include/bus_dma.h +++ b/sys/i386/include/bus_dma.h @@ -79,6 +79,7 @@ #define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */ #define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */ #define BUS_DMA_COHERENT 0x04 /* hint: map memory in a coherent way */ +#define BUS_DMA_ZERO 0x08 /* allocate zero'ed memory */ #define BUS_DMA_BUS1 0x10 /* placeholders for bus functions... */ #define BUS_DMA_BUS2 0x20 #define BUS_DMA_BUS3 0x40 diff --git a/sys/ia64/ia64/busdma_machdep.c b/sys/ia64/ia64/busdma_machdep.c index 231ac3b1dec..29ade1f8720 100644 --- a/sys/ia64/ia64/busdma_machdep.c +++ b/sys/ia64/ia64/busdma_machdep.c @@ -413,24 +413,29 @@ int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, bus_dmamap_t *mapp) { + int mflags; + + if (flags & BUS_DMA_NOWAIT) + mflags = M_NOWAIT; + else + mflags = M_WAITOK; + if (flags & BUS_DMA_ZERO) + mflags |= M_ZERO; + /* If we succeed, no mapping/bouncing will be required */ *mapp = &nobounce_dmamap; if ((dmat->maxsize <= PAGE_SIZE) && dmat->lowaddr >= ptoa(Maxmem)) { - *vaddr = malloc(dmat->maxsize, M_DEVBUF, - (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK); + *vaddr = malloc(dmat->maxsize, M_DEVBUF, mflags); } else { /* * XXX Use Contigmalloc until it is merged into this facility * and handles multi-seg allocations. Nobody is doing * multi-seg allocations yet though. */ - mtx_lock(&Giant); - *vaddr = contigmalloc(dmat->maxsize, M_DEVBUF, - (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK, + *vaddr = contigmalloc(dmat->maxsize, M_DEVBUF, mflags, 0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : 1ul, dmat->boundary); - mtx_unlock(&Giant); } if (*vaddr == NULL) return (ENOMEM); @@ -896,13 +901,11 @@ alloc_bounce_pages(bus_dma_tag_t dmat, u_int numpages) if (bpage == NULL) break; - mtx_lock(&Giant); bpage->vaddr = (vm_offset_t)contigmalloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT, 0ul, dmat->lowaddr, PAGE_SIZE, dmat->boundary); - mtx_unlock(&Giant); if (bpage->vaddr == 0) { free(bpage, M_DEVBUF); break; diff --git a/sys/ia64/include/bus.h b/sys/ia64/include/bus.h index 7a5c0f47ada..0db84a489c8 100644 --- a/sys/ia64/include/bus.h +++ b/sys/ia64/include/bus.h @@ -852,6 +852,7 @@ bus_space_copy_region_8(bus_space_tag_t bst, bus_space_handle_t bsh1, #define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */ #define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */ #define BUS_DMA_COHERENT 0x04 /* hint: map memory in a coherent way */ +#define BUS_DMA_ZERO 0x08 /* allocate zero'ed memory */ #define BUS_DMA_ISA 0x10 /* map memory for ISA dma */ #define BUS_DMA_BUS2 0x20 /* placeholders for bus functions... */ #define BUS_DMA_BUS3 0x40 diff --git a/sys/powerpc/include/bus.h b/sys/powerpc/include/bus.h index 3ee2de59309..bb5f35776d0 100644 --- a/sys/powerpc/include/bus.h +++ b/sys/powerpc/include/bus.h @@ -744,6 +744,7 @@ bus_space_set_region_stream_4(bus_space_tag_t tag, bus_space_handle_t bsh, #define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */ #define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */ #define BUS_DMA_COHERENT 0x04 /* hint: map memory DMA coherent */ +#define BUS_DMA_ZERO 0x08 /* allocate zero'ed memory */ #define BUS_DMA_BUS1 0x10 /* placeholders for bus functions... */ #define BUS_DMA_BUS2 0x20 #define BUS_DMA_BUS3 0x40 diff --git a/sys/powerpc/powerpc/busdma_machdep.c b/sys/powerpc/powerpc/busdma_machdep.c index f3ef3e3b343..829d29ab3db 100644 --- a/sys/powerpc/powerpc/busdma_machdep.c +++ b/sys/powerpc/powerpc/busdma_machdep.c @@ -254,23 +254,28 @@ int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, bus_dmamap_t *mapp) { + int mflags; + + if (flags & BUS_DMA_NOWAIT) + mflags = M_NOWAIT; + else + mflags = M_WAITOK; + if (flags & BUS_DMA_ZERO) + mflags |= M_ZERO; + *mapp = NULL; if (dmat->maxsize <= PAGE_SIZE) { - *vaddr = malloc(dmat->maxsize, M_DEVBUF, - (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK); + *vaddr = malloc(dmat->maxsize, M_DEVBUF, mflags); } else { /* * XXX Use Contigmalloc until it is merged into this facility * and handles multi-seg allocations. Nobody is doing * multi-seg allocations yet though. */ - mtx_lock(&Giant); - *vaddr = contigmalloc(dmat->maxsize, M_DEVBUF, - (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK, + *vaddr = contigmalloc(dmat->maxsize, M_DEVBUF, mflags, 0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : 1ul, dmat->boundary); - mtx_unlock(&Giant); } if (*vaddr == NULL) diff --git a/sys/sparc64/include/bus.h b/sys/sparc64/include/bus.h index f97c13be53d..90d33ab4157 100644 --- a/sys/sparc64/include/bus.h +++ b/sys/sparc64/include/bus.h @@ -900,6 +900,7 @@ memsetw(void *d, int val, size_t size) #define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */ #define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */ #define BUS_DMA_COHERENT 0x004 /* hint: map memory in a coherent way */ +#define BUS_DMA_ZERO 0x008 /* allocate zero'ed memory */ #define BUS_DMA_BUS1 0x010 #define BUS_DMA_BUS2 0x020 #define BUS_DMA_BUS3 0x040 diff --git a/sys/sparc64/sparc64/bus_machdep.c b/sys/sparc64/sparc64/bus_machdep.c index 5843b73ab28..e0655e2a970 100644 --- a/sys/sparc64/sparc64/bus_machdep.c +++ b/sys/sparc64/sparc64/bus_machdep.c @@ -612,23 +612,27 @@ static int nexus_dmamem_alloc(bus_dma_tag_t dmat, void **vaddr, int flags, bus_dmamap_t *mapp) { + int mflags; + + if (flags & BUS_DMA_NOWAIT) + mflags = M_NOWAIT; + else + mflags = M_WAITOK; + if (flags & BUS_DMA_ZERO) + mflags |= M_ZERO; if ((dmat->dt_maxsize <= PAGE_SIZE)) { - *vaddr = malloc(dmat->dt_maxsize, M_DEVBUF, - (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK); + *vaddr = malloc(dmat->dt_maxsize, M_DEVBUF, mflags); } else { /* * XXX: Use contigmalloc until it is merged into this facility * and handles multi-seg allocations. Nobody is doing multi-seg * allocations yet though. */ - mtx_lock(&Giant); - *vaddr = contigmalloc(dmat->dt_maxsize, M_DEVBUF, - (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK, + *vaddr = contigmalloc(dmat->dt_maxsize, M_DEVBUF, mflags, 0ul, dmat->dt_lowaddr, dmat->dt_alignment ? dmat->dt_alignment : 1UL, dmat->dt_boundary); - mtx_unlock(&Giant); } if (*vaddr == NULL) return (ENOMEM); diff --git a/sys/sys/bus_dma.h b/sys/sys/bus_dma.h index 3539a33cc6d..9b75eae9aea 100644 --- a/sys/sys/bus_dma.h +++ b/sys/sys/bus_dma.h @@ -79,6 +79,7 @@ #define BUS_DMA_NOWAIT 0x01 /* not safe to sleep */ #define BUS_DMA_ALLOCNOW 0x02 /* perform resource allocation now */ #define BUS_DMA_COHERENT 0x04 /* hint: map memory in a coherent way */ +#define BUS_DMA_ZERO 0x08 /* allocate zero'ed memory */ #define BUS_DMA_BUS1 0x10 /* placeholders for bus functions... */ #define BUS_DMA_BUS2 0x20 #define BUS_DMA_BUS3 0x40 -- 2.45.2