Changeset View
Changeset View
Standalone View
Standalone View
sys/x86/x86/busdma_bounce.c
Show First 20 Lines • Show All 401 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
static int | static int | ||||
bounce_bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, | bounce_bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags, | ||||
bus_dmamap_t *mapp) | bus_dmamap_t *mapp) | ||||
{ | { | ||||
vm_memattr_t attr; | vm_memattr_t attr; | ||||
int mflags; | int mflags; | ||||
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "%s", __func__); | |||||
cem: This one might be reasonable without BUS_DMA_NOWAIT, since we will allocate sleepable in that… | |||||
Done Inline ActionsYeah, UMA directly issues the same WITNESS_WARN for sleepable allocations, and kmem_alloc_contig() will go through msleep() if it needs to wait for pages. jah: Yeah, UMA directly issues the same WITNESS_WARN for sleepable allocations, and… | |||||
Not Done Inline ActionsExcellent! :-) cem: Excellent! :-) | |||||
Done Inline ActionsEven better, the !M_NOWAIT case of kmem_alloc_* gets a WITNESS check through vmem_alloc(), which will catch abusers even if backing pages are readily available. Otherwise I was going to add one in kmem_alloc_contig_pages(). jah: Even better, the !M_NOWAIT case of kmem_alloc_* gets a WITNESS check through vmem_alloc()… | |||||
if (flags & BUS_DMA_NOWAIT) | if (flags & BUS_DMA_NOWAIT) | ||||
mflags = M_NOWAIT; | mflags = M_NOWAIT; | ||||
else | else | ||||
mflags = M_WAITOK; | mflags = M_WAITOK; | ||||
/* If we succeed, no mapping/bouncing will be required */ | /* If we succeed, no mapping/bouncing will be required */ | ||||
*mapp = NULL; | *mapp = NULL; | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | if (*vaddr == NULL) { | ||||
printf("bus_dmamem_alloc failed to align memory properly.\n"); | printf("bus_dmamem_alloc failed to align memory properly.\n"); | ||||
} | } | ||||
CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", | CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d", | ||||
__func__, dmat, dmat->common.flags, 0); | __func__, dmat, dmat->common.flags, 0); | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Free a piece of memory and it's allociated dmamap, that was allocated | * Free a piece of memory and its allociated dmamap, that was allocated | ||||
Not Done Inline ActionsMight fix "allociated" if you're doing typos on this line cem: Might fix "allociated" if you're doing typos on this line | |||||
Done Inline ActionsHa! My brain just substituted "associated" when I read that. jah: Ha! My brain just substituted "associated" when I read that. | |||||
* via bus_dmamem_alloc. Make the same choice for free/contigfree. | * via bus_dmamem_alloc. Make the same choice for free/contigfree. | ||||
*/ | */ | ||||
static void | static void | ||||
bounce_bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map) | bounce_bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map) | ||||
{ | { | ||||
/* | /* | ||||
* dmamem does not need to be bounced, so the map should be | * dmamem does not need to be bounced, so the map should be | ||||
* NULL and the BUS_DMA_KMEM_ALLOC flag cleared if malloc() | * NULL and the BUS_DMA_KMEM_ALLOC flag cleared if malloc() | ||||
▲ Show 20 Lines • Show All 845 Lines • Show Last 20 Lines |
This one might be reasonable without BUS_DMA_NOWAIT, since we will allocate sleepable in that context. But I suppose we'll just get the exact same warning from malloc(9), so maybe this was redundant?