Instead of all memory allocations using M_DEVBUF, use new categories
M_BUSDMA for allocations of metadata (tags, maps, segment tracking lists), and M_BOUNCE for bounce pages.
This commit is contained in:
parent
3ee4e41b74
commit
a569108b72
@ -217,6 +217,10 @@ static void dma_dcache_sync(struct sync_list *sl, bus_dmasync_op_t op);
|
||||
|
||||
static busdma_bufalloc_t coherent_allocator; /* Cache of coherent buffers */
|
||||
static busdma_bufalloc_t standard_allocator; /* Cache of standard buffers */
|
||||
|
||||
MALLOC_DEFINE(M_BUSDMA, "busdma", "busdma metadata");
|
||||
MALLOC_DEFINE(M_BOUNCE, "bounce", "busdma bounce pages");
|
||||
|
||||
static void
|
||||
busdma_init(void *dummy)
|
||||
{
|
||||
@ -260,7 +264,7 @@ busdma_init(void *dummy)
|
||||
|
||||
/*
|
||||
* This init historically used SI_SUB_VM, but now the init code requires
|
||||
* malloc(9) using M_DEVBUF memory and the pcpu zones for counter(9), which get
|
||||
* malloc(9) using M_BUSDMA memory and the pcpu zones for counter(9), which get
|
||||
* set up by SI_SUB_KMEM and SI_ORDER_LAST, so we'll go right after that by
|
||||
* using SI_SUB_KMEM+1.
|
||||
*/
|
||||
@ -481,7 +485,7 @@ bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment,
|
||||
/* Return a NULL tag on failure */
|
||||
*dmat = NULL;
|
||||
|
||||
newtag = (bus_dma_tag_t)malloc(sizeof(*newtag), M_DEVBUF,
|
||||
newtag = (bus_dma_tag_t)malloc(sizeof(*newtag), M_BUSDMA,
|
||||
M_ZERO | M_NOWAIT);
|
||||
if (newtag == NULL) {
|
||||
CTR4(KTR_BUSDMA, "%s returned tag %p tag flags 0x%x error %d",
|
||||
@ -557,7 +561,7 @@ bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment,
|
||||
maxsize = roundup2(maxsize, PAGE_SIZE) + PAGE_SIZE;
|
||||
|
||||
if ((error = alloc_bounce_zone(newtag)) != 0) {
|
||||
free(newtag, M_DEVBUF);
|
||||
free(newtag, M_BUSDMA);
|
||||
return (error);
|
||||
}
|
||||
bz = newtag->bounce_zone;
|
||||
@ -577,7 +581,7 @@ bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment,
|
||||
newtag->bounce_zone = NULL;
|
||||
|
||||
if (error != 0) {
|
||||
free(newtag, M_DEVBUF);
|
||||
free(newtag, M_BUSDMA);
|
||||
} else {
|
||||
atomic_add_32(&tags_total, 1);
|
||||
*dmat = newtag;
|
||||
@ -610,7 +614,7 @@ bus_dma_tag_destroy(bus_dma_tag_t dmat)
|
||||
atomic_subtract_int(&dmat->ref_count, 1);
|
||||
if (dmat->ref_count == 0) {
|
||||
atomic_subtract_32(&tags_total, 1);
|
||||
free(dmat, M_DEVBUF);
|
||||
free(dmat, M_BUSDMA);
|
||||
/*
|
||||
* Last reference count, so
|
||||
* release our reference
|
||||
@ -683,7 +687,7 @@ allocate_map(bus_dma_tag_t dmat, int mflags)
|
||||
dmat->nsegments, MAX_DMA_SEGMENTS));
|
||||
segsize = sizeof(struct bus_dma_segment) * dmat->nsegments;
|
||||
mapsize = sizeof(*map) + sizeof(struct sync_list) * dmat->nsegments;
|
||||
map = malloc(mapsize + segsize, M_DEVBUF, mflags | M_ZERO);
|
||||
map = malloc(mapsize + segsize, M_BUSDMA, mflags | M_ZERO);
|
||||
if (map == NULL) {
|
||||
CTR3(KTR_BUSDMA, "%s: tag %p error %d", __func__, dmat, ENOMEM);
|
||||
return (NULL);
|
||||
@ -717,7 +721,7 @@ bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
|
||||
*/
|
||||
error = allocate_bz_and_pages(dmat, map);
|
||||
if (error != 0) {
|
||||
free(map, M_DEVBUF);
|
||||
free(map, M_BUSDMA);
|
||||
*mapp = NULL;
|
||||
return (error);
|
||||
}
|
||||
@ -746,7 +750,7 @@ bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map)
|
||||
if (map->flags & DMAMAP_COHERENT)
|
||||
atomic_subtract_32(&maps_coherent, 1);
|
||||
atomic_subtract_32(&maps_total, 1);
|
||||
free(map, M_DEVBUF);
|
||||
free(map, M_BUSDMA);
|
||||
dmat->map_count--;
|
||||
CTR2(KTR_BUSDMA, "%s: tag %p error 0", __func__, dmat);
|
||||
return (0);
|
||||
@ -830,7 +834,7 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
|
||||
if (*vaddr == NULL) {
|
||||
CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d",
|
||||
__func__, dmat, dmat->flags, ENOMEM);
|
||||
free(map, M_DEVBUF);
|
||||
free(map, M_BUSDMA);
|
||||
*mapp = NULL;
|
||||
return (ENOMEM);
|
||||
}
|
||||
@ -873,7 +877,7 @@ bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
|
||||
atomic_subtract_32(&maps_coherent, 1);
|
||||
atomic_subtract_32(&maps_total, 1);
|
||||
atomic_subtract_32(&maps_dmamem, 1);
|
||||
free(map, M_DEVBUF);
|
||||
free(map, M_BUSDMA);
|
||||
CTR3(KTR_BUSDMA, "%s: tag %p flags 0x%x", __func__, dmat, dmat->flags);
|
||||
}
|
||||
|
||||
@ -1517,7 +1521,7 @@ alloc_bounce_zone(bus_dma_tag_t dmat)
|
||||
}
|
||||
}
|
||||
|
||||
if ((bz = (struct bounce_zone *)malloc(sizeof(*bz), M_DEVBUF,
|
||||
if ((bz = (struct bounce_zone *)malloc(sizeof(*bz), M_BUSDMA,
|
||||
M_NOWAIT | M_ZERO)) == NULL)
|
||||
return (ENOMEM);
|
||||
|
||||
@ -1588,15 +1592,15 @@ alloc_bounce_pages(bus_dma_tag_t dmat, u_int numpages)
|
||||
while (numpages > 0) {
|
||||
struct bounce_page *bpage;
|
||||
|
||||
bpage = (struct bounce_page *)malloc(sizeof(*bpage), M_DEVBUF,
|
||||
bpage = (struct bounce_page *)malloc(sizeof(*bpage), M_BUSDMA,
|
||||
M_NOWAIT | M_ZERO);
|
||||
|
||||
if (bpage == NULL)
|
||||
break;
|
||||
bpage->vaddr = (vm_offset_t)contigmalloc(PAGE_SIZE, M_DEVBUF,
|
||||
bpage->vaddr = (vm_offset_t)contigmalloc(PAGE_SIZE, M_BOUNCE,
|
||||
M_NOWAIT, 0ul, bz->lowaddr, PAGE_SIZE, 0);
|
||||
if (bpage->vaddr == 0) {
|
||||
free(bpage, M_DEVBUF);
|
||||
free(bpage, M_BUSDMA);
|
||||
break;
|
||||
}
|
||||
bpage->busaddr = pmap_kextract(bpage->vaddr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user