mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-11 14:10:34 +00:00
After much discussion with mjacob and scottl, change bus_dmamem_alloc so
that it just warns the user with a printf when it misaligns a piece of memory that was requested through a busdma tag. Some drivers (such as mpt, and probably others) were asking for alignments that could not be satisfied, but as far as driver operation was concerned, that did not matter. In the theory that other drivers will fall into this same category, we agreed that panicing or making the allocation fail will cause more hardship than is necessary. The printf should be sufficient motivation to get the driver glitch fixed.
This commit is contained in:
parent
829b898c7c
commit
f25d341cfb
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=159130
@ -469,7 +469,7 @@ int
|
||||
bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
bus_dmamap_t *mapp)
|
||||
{
|
||||
int mflags, malloc_used, swasnull = 0;
|
||||
int mflags;
|
||||
|
||||
if (flags & BUS_DMA_NOWAIT)
|
||||
mflags = M_NOWAIT;
|
||||
@ -490,7 +490,6 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
__func__, dmat, dmat->flags, ENOMEM);
|
||||
return (ENOMEM);
|
||||
}
|
||||
swasnull = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -499,13 +498,12 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
* 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.
|
||||
* In the meantime, we'll warn the user if malloc gets it wrong.
|
||||
*/
|
||||
if ((dmat->maxsize <= PAGE_SIZE) &&
|
||||
(dmat->alignment < dmat->maxsize) &&
|
||||
dmat->lowaddr >= ptoa((vm_paddr_t)Maxmem)) {
|
||||
*vaddr = malloc(dmat->maxsize, M_DEVBUF, mflags);
|
||||
malloc_used = 1;
|
||||
} else {
|
||||
/*
|
||||
* XXX Use Contigmalloc until it is merged into this facility
|
||||
@ -516,29 +514,13 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
*vaddr = contigmalloc(dmat->maxsize, M_DEVBUF, mflags,
|
||||
0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : 1ul,
|
||||
dmat->boundary);
|
||||
malloc_used = 0;
|
||||
}
|
||||
if (*vaddr == NULL) {
|
||||
if (swasnull) {
|
||||
free(dmat->segments, M_DEVBUF);
|
||||
dmat->segments = NULL;
|
||||
}
|
||||
CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d",
|
||||
__func__, dmat, dmat->flags, ENOMEM);
|
||||
return (ENOMEM);
|
||||
}
|
||||
if ((uintptr_t)*vaddr & (dmat->alignment - 1)) {
|
||||
} else if ((uintptr_t)*vaddr & (dmat->alignment - 1)) {
|
||||
printf("bus_dmamem_alloc failed to align memory properly.");
|
||||
if (malloc_used) {
|
||||
free(*vaddr, M_DEVBUF);
|
||||
} else {
|
||||
contigfree(*vaddr, dmat->maxsize, M_DEVBUF);
|
||||
}
|
||||
if (swasnull) {
|
||||
free(dmat->segments, M_DEVBUF);
|
||||
dmat->segments = NULL;
|
||||
}
|
||||
return (EINVAL);
|
||||
}
|
||||
CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d",
|
||||
__func__, dmat, dmat->flags, ENOMEM);
|
||||
|
@ -472,7 +472,7 @@ int
|
||||
bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
bus_dmamap_t *mapp)
|
||||
{
|
||||
int mflags, malloc_used, swasnull = 0;
|
||||
int mflags;
|
||||
|
||||
if (flags & BUS_DMA_NOWAIT)
|
||||
mflags = M_NOWAIT;
|
||||
@ -493,7 +493,6 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
__func__, dmat, dmat->flags, ENOMEM);
|
||||
return (ENOMEM);
|
||||
}
|
||||
swasnull = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -502,13 +501,12 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
* 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.
|
||||
* In the meantime, we'll warn the user if malloc gets it wrong.
|
||||
*/
|
||||
if ((dmat->maxsize <= PAGE_SIZE) &&
|
||||
(dmat->alignment < dmat->maxsize) &&
|
||||
dmat->lowaddr >= ptoa((vm_paddr_t)Maxmem)) {
|
||||
*vaddr = malloc(dmat->maxsize, M_DEVBUF, mflags);
|
||||
malloc_used = 1;
|
||||
} else {
|
||||
/*
|
||||
* XXX Use Contigmalloc until it is merged into this facility
|
||||
@ -519,29 +517,13 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
*vaddr = contigmalloc(dmat->maxsize, M_DEVBUF, mflags,
|
||||
0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : 1ul,
|
||||
dmat->boundary);
|
||||
malloc_used = 0;
|
||||
}
|
||||
if (*vaddr == NULL) {
|
||||
if (swasnull) {
|
||||
free(dmat->segments, M_DEVBUF);
|
||||
dmat->segments = NULL;
|
||||
}
|
||||
CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d",
|
||||
__func__, dmat, dmat->flags, ENOMEM);
|
||||
return (ENOMEM);
|
||||
}
|
||||
if ((uintptr_t)*vaddr & (dmat->alignment - 1)) {
|
||||
} else if ((uintptr_t)*vaddr & (dmat->alignment - 1)) {
|
||||
printf("bus_dmamem_alloc failed to align memory properly.");
|
||||
if (malloc_used) {
|
||||
free(*vaddr, M_DEVBUF);
|
||||
} else {
|
||||
contigfree(*vaddr, dmat->maxsize, M_DEVBUF);
|
||||
}
|
||||
if (swasnull) {
|
||||
free(dmat->segments, M_DEVBUF);
|
||||
dmat->segments = NULL;
|
||||
}
|
||||
return (EINVAL);
|
||||
}
|
||||
CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d",
|
||||
__func__, dmat, dmat->flags, ENOMEM);
|
||||
|
@ -410,7 +410,7 @@ int
|
||||
bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
bus_dmamap_t *mapp)
|
||||
{
|
||||
int mflags, malloc_used, swasnull = 0;
|
||||
int mflags;
|
||||
|
||||
if (flags & BUS_DMA_NOWAIT)
|
||||
mflags = M_NOWAIT;
|
||||
@ -424,11 +424,10 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
|
||||
if (dmat->segments == NULL) {
|
||||
dmat->segments = (bus_dma_segment_t *)malloc(
|
||||
sizeof (bus_dma_segment_t) * dmat->nsegments,
|
||||
M_DEVBUF, M_NOWAIT);
|
||||
sizeof(bus_dma_segment_t) * dmat->nsegments, M_DEVBUF,
|
||||
M_NOWAIT);
|
||||
if (dmat->segments == NULL)
|
||||
return (ENOMEM);
|
||||
swasnull = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -437,13 +436,12 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
* 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.
|
||||
* In the meantime, we'll warn the user if malloc gets it wrong.
|
||||
*/
|
||||
if ((dmat->maxsize <= PAGE_SIZE) &&
|
||||
(dmat->alignment < dmat->maxsize) &&
|
||||
dmat->lowaddr >= ptoa((vm_paddr_t)Maxmem)) {
|
||||
dmat->lowaddr >= ptoa(Maxmem)) {
|
||||
*vaddr = malloc(dmat->maxsize, M_DEVBUF, mflags);
|
||||
malloc_used = 1;
|
||||
} else {
|
||||
/*
|
||||
* XXX Use Contigmalloc until it is merged into this facility
|
||||
@ -454,28 +452,11 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
*vaddr = contigmalloc(dmat->maxsize, M_DEVBUF, mflags,
|
||||
0ul, dmat->lowaddr, dmat->alignment? dmat->alignment : 1ul,
|
||||
dmat->boundary);
|
||||
malloc_used = 0;
|
||||
}
|
||||
if (*vaddr == NULL) {
|
||||
if (swasnull) {
|
||||
free(dmat->segments, M_DEVBUF);
|
||||
dmat->segments = NULL;
|
||||
}
|
||||
if (*vaddr == NULL)
|
||||
return (ENOMEM);
|
||||
}
|
||||
if ((uintptr_t)*vaddr & (dmat->alignment - 1)) {
|
||||
else if ((uintptr_t)*vaddr & (dmat->alignment - 1))
|
||||
printf("bus_dmamem_alloc failed to align memory properly.");
|
||||
if (malloc_used) {
|
||||
free(*vaddr, M_DEVBUF);
|
||||
} else {
|
||||
contigfree(*vaddr, dmat->maxsize, M_DEVBUF);
|
||||
}
|
||||
if (swasnull) {
|
||||
free(dmat->segments, M_DEVBUF);
|
||||
dmat->segments = NULL;
|
||||
}
|
||||
return (EINVAL);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -486,18 +467,15 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
void
|
||||
bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
|
||||
{
|
||||
malloc_used = 0;
|
||||
/*
|
||||
* dmamem does not need to be bounced, so the map should be
|
||||
if (swasnull) {
|
||||
free(dmat->segments, M_DEVBUF);
|
||||
dmat->segments = NULL;
|
||||
}
|
||||
* NULL
|
||||
*/
|
||||
if (map != NULL)
|
||||
panic("bus_dmamem_free: Invalid map freed\n");
|
||||
if ((dmat->maxsize <= PAGE_SIZE) && dmat->lowaddr >= ptoa(Maxmem))
|
||||
if ((dmat->maxsize <= PAGE_SIZE) &&
|
||||
(dmat->alignment < dmat->maxsize) &&
|
||||
dmat->lowaddr >= ptoa(Maxmem)) {
|
||||
free(vaddr, M_DEVBUF);
|
||||
else {
|
||||
contigfree(vaddr, dmat->maxsize, M_DEVBUF);
|
||||
|
Loading…
Reference in New Issue
Block a user