From 024859acd22a3d016b8fd5450f32b37974da21b0 Mon Sep 17 00:00:00 2001 From: marcel Date: Fri, 8 Jun 2007 04:46:50 +0000 Subject: [PATCH] Sync with other platforms: add kluge to use contigmalloc when the alignment is larger than the size and print a diagnostic when we didn't satisfy the alignment. --- sys/powerpc/powerpc/busdma_machdep.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/sys/powerpc/powerpc/busdma_machdep.c b/sys/powerpc/powerpc/busdma_machdep.c index 2fe0a6d6d9d3..802b2105b546 100644 --- a/sys/powerpc/powerpc/busdma_machdep.c +++ b/sys/powerpc/powerpc/busdma_machdep.c @@ -263,9 +263,18 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, mflags |= M_ZERO; *mapp = NULL; - - if (dmat->maxsize <= PAGE_SIZE) { - *vaddr = malloc(dmat->maxsize, M_DEVBUF, mflags); + + /* + * XXX: + * (dmat->alignment < dmat->maxsize) is just a quick hack; the exact + * alignment guarantees of malloc need to be nailed down, and the + * code below should be rewritten to take that into account. + * + * In the meantime, we'll return an error if malloc gets it wrong. + */ + if (dmat->maxsize <= PAGE_SIZE && + dmat->alignment < dmat->maxsize) { + *vaddr = malloc(dmat->maxsize, M_DEVBUF, mflags); } else { /* * XXX Use Contigmalloc until it is merged into this facility @@ -280,6 +289,9 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, if (*vaddr == NULL) return (ENOMEM); + if ((uintptr_t)*vaddr % dmat->alignment) + printf("XXX: %s: alignment not respected!\n", __func__); + return (0); } @@ -292,11 +304,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"); - if (dmat->maxsize <= PAGE_SIZE) + if (dmat->maxsize <= PAGE_SIZE && + dmat->alignment < dmat->maxsize) free(vaddr, M_DEVBUF); - else { + else contigfree(vaddr, dmat->maxsize, M_DEVBUF); - } } /*