diff --git a/sys/arm/arm/busdma_machdep.c b/sys/arm/arm/busdma_machdep.c --- a/sys/arm/arm/busdma_machdep.c +++ b/sys/arm/arm/busdma_machdep.c @@ -77,7 +77,6 @@ struct bounce_zone; struct bus_dma_tag { - bus_dma_tag_t parent; bus_size_t alignment; bus_addr_t boundary; bus_addr_t lowaddr; @@ -86,7 +85,6 @@ u_int nsegments; bus_size_t maxsegsz; int flags; - int ref_count; int map_count; bus_dma_lock_t *lockfunc; void *lockfuncarg; @@ -332,10 +330,7 @@ * * Bouncing can be triggered by DMA that doesn't begin and end on cacheline * boundaries, or doesn't begin on an alignment boundary, or falls within the - * exclusion zone of any tag in the ancestry chain. - * - * For exclusions, walk the chain of tags comparing paddr to the exclusion zone - * within each tag. + * exclusion zone of the tag. */ static int must_bounce(bus_dma_tag_t dmat, bus_dmamap_t map, bus_addr_t paddr, @@ -353,17 +348,11 @@ return (1); /* - * Even though each tag has an exclusion zone that is a superset of its - * own and all its ancestors' exclusions, the exclusion zone of each tag - * up the chain must be checked within the loop, because the busdma - * rules say the filter function is called only when the address lies - * within the low-highaddr range of the tag that filterfunc belongs to. + * Check the tag's exclusion zone. */ - while (dmat != NULL && exclusion_bounce(dmat)) { - if (paddr >= dmat->lowaddr && paddr <= dmat->highaddr) - return (1); - dmat = dmat->parent; - } + if (exclusion_bounce(dmat) && + paddr >= dmat->lowaddr && paddr <= dmat->highaddr) + return (1); return (0); } @@ -405,7 +394,6 @@ return (ENOMEM); } - newtag->parent = parent; newtag->alignment = alignment; newtag->boundary = boundary; newtag->lowaddr = trunc_page((vm_paddr_t)lowaddr) + (PAGE_SIZE - 1); @@ -415,7 +403,6 @@ newtag->nsegments = nsegments; newtag->maxsegsz = maxsegsz; newtag->flags = flags; - newtag->ref_count = 1; /* Count ourself */ newtag->map_count = 0; if (lockfunc != NULL) { newtag->lockfunc = lockfunc; @@ -437,14 +424,6 @@ else if (parent->boundary != 0) newtag->boundary = MIN(parent->boundary, newtag->boundary); - - /* - * Short circuit to looking at our parent directly since we - * have encapsulated all of its information. - */ - newtag->parent = parent->parent; - if (newtag->parent != NULL) - atomic_add_int(&parent->ref_count, 1); } if (exclusion_bounce_check(newtag->lowaddr, newtag->highaddr)) @@ -504,7 +483,6 @@ if (t == NULL || dmat == NULL) return; - t->parent = dmat->parent; t->alignment = dmat->alignment; t->boundary = dmat->boundary; t->lowaddr = dmat->lowaddr; @@ -527,39 +505,17 @@ int bus_dma_tag_destroy(bus_dma_tag_t dmat) { -#ifdef KTR - bus_dma_tag_t dmat_copy = dmat; -#endif - int error; - - error = 0; + int error = 0; if (dmat != NULL) { if (dmat->map_count != 0) { error = EBUSY; goto out; } - - while (dmat != NULL) { - bus_dma_tag_t parent; - - parent = dmat->parent; - atomic_subtract_int(&dmat->ref_count, 1); - if (dmat->ref_count == 0) { - atomic_subtract_32(&tags_total, 1); - free(dmat, M_BUSDMA); - /* - * Last reference count, so - * release our reference - * count on our parent. - */ - dmat = parent; - } else - dmat = NULL; - } + free(dmat, M_BUSDMA); } out: - CTR3(KTR_BUSDMA, "%s tag %p error %d", __func__, dmat_copy, error); + CTR3(KTR_BUSDMA, "%s tag %p error %d", __func__, dmat, error); return (error); } diff --git a/sys/arm64/arm64/busdma_bounce.c b/sys/arm64/arm64/busdma_bounce.c --- a/sys/arm64/arm64/busdma_bounce.c +++ b/sys/arm64/arm64/busdma_bounce.c @@ -309,42 +309,19 @@ static int bounce_bus_dma_tag_destroy(bus_dma_tag_t dmat) { -#ifdef KTR - bus_dma_tag_t dmat_copy; -#endif - bus_dma_tag_t parent; - int error; - - error = 0; -#ifdef KTR - dmat_copy = dmat; -#endif - + int error = 0; if (dmat != NULL) { if (dmat->map_count != 0) { error = EBUSY; goto out; } - while (dmat != NULL) { - parent = (bus_dma_tag_t)dmat->common.parent; - atomic_subtract_int(&dmat->common.ref_count, 1); - if (dmat->common.ref_count == 0) { - if (dmat->segments != NULL) - free(dmat->segments, M_DEVBUF); - free(dmat, M_DEVBUF); - /* - * Last reference count, so - * release our reference - * count on our parent. - */ - dmat = parent; - } else - dmat = NULL; - } + if (dmat->segments != NULL) + free(dmat->segments, M_DEVBUF); + free(dmat, M_DEVBUF); } out: - CTR3(KTR_BUSDMA, "%s tag %p error %d", __func__, dmat_copy, error); + CTR3(KTR_BUSDMA, "%s tag %p error %d", __func__, dmat, error); return (error); } diff --git a/sys/arm64/arm64/busdma_machdep.c b/sys/arm64/arm64/busdma_machdep.c --- a/sys/arm64/arm64/busdma_machdep.c +++ b/sys/arm64/arm64/busdma_machdep.c @@ -61,12 +61,8 @@ bus_dma_run_filter(struct bus_dma_tag_common *tc, bus_addr_t paddr) { - while (tc != NULL) { - if (paddr > tc->lowaddr && paddr <= tc->highaddr) - return (1); - - tc = tc->parent; - } + if (paddr > tc->lowaddr && paddr <= tc->highaddr) + return (1); return (0); } @@ -99,7 +95,6 @@ common = newtag; common->impl = &bus_dma_bounce_impl; - common->parent = parent; common->alignment = alignment; common->boundary = boundary; common->lowaddr = trunc_page((vm_paddr_t)lowaddr) + (PAGE_SIZE - 1); @@ -108,7 +103,6 @@ common->nsegments = nsegments; common->maxsegsz = maxsegsz; common->flags = flags; - common->ref_count = 1; /* Count ourself */ if (lockfunc != NULL) { common->lockfunc = lockfunc; common->lockfuncarg = lockfuncarg; @@ -130,13 +124,7 @@ common->boundary); } - /* - * Short circuit looking at our parent directly since we have - * encapsulated all of its information. - */ - common->parent = parent->parent; common->domain = parent->domain; - atomic_add_int(&parent->ref_count, 1); } common->domain = vm_phys_domain_match(common->domain, 0ul, common->lowaddr); @@ -184,7 +172,6 @@ common = (struct bus_dma_tag_common *)dmat; - t->parent = (bus_dma_tag_t)common->parent; t->alignment = common->alignment; t->boundary = common->boundary; t->lowaddr = common->lowaddr; diff --git a/sys/arm64/include/bus_dma_impl.h b/sys/arm64/include/bus_dma_impl.h --- a/sys/arm64/include/bus_dma_impl.h +++ b/sys/arm64/include/bus_dma_impl.h @@ -31,7 +31,6 @@ struct bus_dma_tag_common { struct bus_dma_impl *impl; - struct bus_dma_tag_common *parent; bus_size_t alignment; bus_addr_t boundary; bus_addr_t lowaddr; @@ -42,7 +41,6 @@ int flags; bus_dma_lock_t *lockfunc; void *lockfuncarg; - int ref_count; int domain; }; diff --git a/sys/dev/iommu/busdma_iommu.c b/sys/dev/iommu/busdma_iommu.c --- a/sys/dev/iommu/busdma_iommu.c +++ b/sys/dev/iommu/busdma_iommu.c @@ -394,33 +394,24 @@ static int iommu_bus_dma_tag_destroy(bus_dma_tag_t dmat1) { - struct bus_dma_tag_iommu *dmat, *parent; - struct bus_dma_tag_iommu *dmat_copy __unused; + struct bus_dma_tag_iommu *dmat; int error; error = 0; - dmat_copy = dmat = (struct bus_dma_tag_iommu *)dmat1; + dmat = (struct bus_dma_tag_iommu *)dmat1; if (dmat != NULL) { if (dmat->map_count != 0) { error = EBUSY; goto out; } - while (dmat != NULL) { - parent = (struct bus_dma_tag_iommu *)dmat->common.parent; - if (atomic_fetchadd_int(&dmat->common.ref_count, -1) == - 1) { - if (dmat == dmat->ctx->tag) - iommu_free_ctx(dmat->ctx); - free(dmat->segments, M_IOMMU_DMAMAP); - free(dmat, M_DEVBUF); - dmat = parent; - } else - dmat = NULL; - } + if (dmat == dmat->ctx->tag) + iommu_free_ctx(dmat->ctx); + free(dmat->segments, M_IOMMU_DMAMAP); + free(dmat, M_DEVBUF); } out: - CTR3(KTR_BUSDMA, "%s tag %p error %d", __func__, dmat_copy, error); + CTR3(KTR_BUSDMA, "%s tag %p error %d", __func__, dmat, error); return (error); } diff --git a/sys/powerpc/powerpc/busdma_machdep.c b/sys/powerpc/powerpc/busdma_machdep.c --- a/sys/powerpc/powerpc/busdma_machdep.c +++ b/sys/powerpc/powerpc/busdma_machdep.c @@ -63,7 +63,6 @@ struct bounce_zone; struct bus_dma_tag { - bus_dma_tag_t parent; bus_size_t alignment; bus_addr_t boundary; bus_addr_t lowaddr; @@ -72,7 +71,6 @@ bus_size_t maxsegsz; u_int nsegments; int flags; - int ref_count; int map_count; bus_dma_lock_t *lockfunc; void *lockfuncarg; @@ -126,15 +124,12 @@ retval = 0; - do { - if (dmat->iommu == NULL && - paddr > dmat->lowaddr && paddr <= dmat->highaddr) - retval = 1; - if (!vm_addr_align_ok(paddr, dmat->alignment)) - retval = 1; + if (dmat->iommu == NULL && + paddr > dmat->lowaddr && paddr <= dmat->highaddr) + retval = 1; + if (!vm_addr_align_ok(paddr, dmat->alignment)) + retval = 1; - dmat = dmat->parent; - } while (retval == 0 && dmat != NULL); return (retval); } @@ -177,7 +172,6 @@ return (ENOMEM); } - newtag->parent = parent; newtag->alignment = alignment; newtag->boundary = boundary; newtag->lowaddr = trunc_page((vm_paddr_t)lowaddr) + (PAGE_SIZE - 1); @@ -186,7 +180,6 @@ newtag->nsegments = nsegments; newtag->maxsegsz = maxsegsz; newtag->flags = flags; - newtag->ref_count = 1; /* Count ourself */ newtag->map_count = 0; if (lockfunc != NULL) { newtag->lockfunc = lockfunc; @@ -206,13 +199,6 @@ newtag->boundary = MIN(parent->boundary, newtag->boundary); - /* - * Short circuit looking at our parent directly since we have - * encapsulated all of its information. - */ - newtag->parent = parent->parent; - if (newtag->parent != NULL) - atomic_add_int(&parent->ref_count, 1); newtag->iommu = parent->iommu; newtag->iommu_cookie = parent->iommu_cookie; } @@ -265,7 +251,6 @@ if (t == NULL || dmat == NULL) return; - t->parent = dmat->parent; t->alignment = dmat->alignment; t->boundary = dmat->boundary; t->lowaddr = dmat->lowaddr; @@ -288,11 +273,7 @@ int bus_dma_tag_destroy(bus_dma_tag_t dmat) { - bus_dma_tag_t dmat_copy __unused; - int error; - - error = 0; - dmat_copy = dmat; + int error = 0; if (dmat != NULL) { if (dmat->map_count != 0) { @@ -300,25 +281,10 @@ goto out; } - while (dmat != NULL) { - bus_dma_tag_t parent; - - parent = dmat->parent; - atomic_subtract_int(&dmat->ref_count, 1); - if (dmat->ref_count == 0) { - free(dmat, M_DEVBUF); - /* - * Last reference count, so - * release our reference - * count on our parent. - */ - dmat = parent; - } else - dmat = NULL; - } + free(dmat, M_DEVBUF); } out: - CTR3(KTR_BUSDMA, "%s tag %p error %d", __func__, dmat_copy, error); + CTR3(KTR_BUSDMA, "%s tag %p error %d", __func__, dmat, error); return (error); } diff --git a/sys/riscv/include/bus_dma_impl.h b/sys/riscv/include/bus_dma_impl.h --- a/sys/riscv/include/bus_dma_impl.h +++ b/sys/riscv/include/bus_dma_impl.h @@ -31,7 +31,6 @@ struct bus_dma_tag_common { struct bus_dma_impl *impl; - struct bus_dma_tag_common *parent; bus_size_t alignment; bus_addr_t boundary; bus_addr_t lowaddr; @@ -42,7 +41,6 @@ int flags; bus_dma_lock_t *lockfunc; void *lockfuncarg; - int ref_count; }; struct bus_dma_impl { diff --git a/sys/riscv/riscv/busdma_bounce.c b/sys/riscv/riscv/busdma_bounce.c --- a/sys/riscv/riscv/busdma_bounce.c +++ b/sys/riscv/riscv/busdma_bounce.c @@ -196,38 +196,19 @@ static int bounce_bus_dma_tag_destroy(bus_dma_tag_t dmat) { -#ifdef KTR - bus_dma_tag_t dmat_copy = dmat; -#endif - bus_dma_tag_t parent; - int error; - - error = 0; + int error = 0; if (dmat != NULL) { if (dmat->map_count != 0) { error = EBUSY; goto out; } - while (dmat != NULL) { - parent = (bus_dma_tag_t)dmat->common.parent; - atomic_subtract_int(&dmat->common.ref_count, 1); - if (dmat->common.ref_count == 0) { - if (dmat->segments != NULL) - free(dmat->segments, M_DEVBUF); - free(dmat, M_DEVBUF); - /* - * Last reference count, so - * release our reference - * count on our parent. - */ - dmat = parent; - } else - dmat = NULL; - } + if (dmat->segments != NULL) + free(dmat->segments, M_DEVBUF); + free(dmat, M_DEVBUF); } out: - CTR3(KTR_BUSDMA, "%s tag %p error %d", __func__, dmat_copy, error); + CTR3(KTR_BUSDMA, "%s tag %p error %d", __func__, dmat, error); return (error); } diff --git a/sys/riscv/riscv/busdma_machdep.c b/sys/riscv/riscv/busdma_machdep.c --- a/sys/riscv/riscv/busdma_machdep.c +++ b/sys/riscv/riscv/busdma_machdep.c @@ -62,13 +62,10 @@ int retval; retval = 0; - do { - if ((paddr > tc->lowaddr && paddr <= tc->highaddr) || - !vm_addr_align_ok(paddr, tc->alignment)) - retval = 1; + if ((paddr > tc->lowaddr && paddr <= tc->highaddr) || + !vm_addr_align_ok(paddr, tc->alignment)) + retval = 1; - tc = tc->parent; - } while (retval == 0 && tc != NULL); return (retval); } @@ -100,7 +97,6 @@ common = newtag; common->impl = &bus_dma_bounce_impl; - common->parent = parent; common->alignment = alignment; common->boundary = boundary; common->lowaddr = trunc_page((vm_paddr_t)lowaddr) + (PAGE_SIZE - 1); @@ -109,7 +105,6 @@ common->nsegments = nsegments; common->maxsegsz = maxsegsz; common->flags = flags; - common->ref_count = 1; /* Count ourself */ if (lockfunc != NULL) { common->lockfunc = lockfunc; common->lockfuncarg = lockfuncarg; @@ -129,13 +124,6 @@ common->boundary = MIN(parent->boundary, common->boundary); } - - /* - * Short circuit looking at our parent directly since we have - * encapsulated all of its information. - */ - common->parent = parent->parent; - atomic_add_int(&parent->ref_count, 1); } *dmat = common; return (0); @@ -181,7 +169,6 @@ common = (struct bus_dma_tag_common *)dmat; - t->parent = (bus_dma_tag_t)common->parent; t->alignment = common->alignment; t->boundary = common->boundary; t->lowaddr = common->lowaddr; diff --git a/sys/x86/include/busdma_impl.h b/sys/x86/include/busdma_impl.h --- a/sys/x86/include/busdma_impl.h +++ b/sys/x86/include/busdma_impl.h @@ -33,7 +33,6 @@ struct bus_dma_tag_common { struct bus_dma_impl *impl; - struct bus_dma_tag_common *parent; bus_size_t alignment; bus_addr_t boundary; bus_addr_t lowaddr; @@ -44,7 +43,6 @@ int flags; bus_dma_lock_t *lockfunc; void *lockfuncarg; - int ref_count; int domain; }; diff --git a/sys/x86/iommu/intel_ctx.c b/sys/x86/iommu/intel_ctx.c --- a/sys/x86/iommu/intel_ctx.c +++ b/sys/x86/iommu/intel_ctx.c @@ -128,7 +128,6 @@ domain = CTX2DOM(ctx); maxaddr = MIN(domain->iodom.end, BUS_SPACE_MAXADDR); - ctx->context.tag->common.ref_count = 1; /* Prevent free */ ctx->context.tag->common.impl = &bus_dma_iommu_impl; ctx->context.tag->common.boundary = 0; ctx->context.tag->common.lowaddr = maxaddr; diff --git a/sys/x86/x86/busdma_bounce.c b/sys/x86/x86/busdma_bounce.c --- a/sys/x86/x86/busdma_bounce.c +++ b/sys/x86/x86/busdma_bounce.c @@ -227,38 +227,19 @@ static int bounce_bus_dma_tag_destroy(bus_dma_tag_t dmat) { -#ifdef KTR - bus_dma_tag_t dmat_copy = dmat; -#endif - bus_dma_tag_t parent; - int error; - - error = 0; + int error = 0; if (dmat != NULL) { if (dmat->map_count != 0) { error = EBUSY; goto out; } - while (dmat != NULL) { - parent = (bus_dma_tag_t)dmat->common.parent; - atomic_subtract_int(&dmat->common.ref_count, 1); - if (dmat->common.ref_count == 0) { - if (dmat->segments != NULL) - free(dmat->segments, M_DEVBUF); - free(dmat, M_DEVBUF); - /* - * Last reference count, so - * release our reference - * count on our parent. - */ - dmat = parent; - } else - dmat = NULL; - } + if (dmat->segments != NULL) + free(dmat->segments, M_DEVBUF); + free(dmat, M_DEVBUF); } out: - CTR3(KTR_BUSDMA, "%s tag %p error %d", __func__, dmat_copy, error); + CTR3(KTR_BUSDMA, "%s tag %p error %d", __func__, dmat, error); return (error); } diff --git a/sys/x86/x86/busdma_machdep.c b/sys/x86/x86/busdma_machdep.c --- a/sys/x86/x86/busdma_machdep.c +++ b/sys/x86/x86/busdma_machdep.c @@ -67,14 +67,11 @@ int retval; retval = 0; - do { - if (paddr >= BUS_SPACE_MAXADDR || - (paddr > tc->lowaddr && paddr <= tc->highaddr) || - !vm_addr_align_ok(paddr, tc->alignment)) - retval = 1; - - tc = tc->parent; - } while (retval == 0 && tc != NULL); + if (paddr >= BUS_SPACE_MAXADDR || + (paddr > tc->lowaddr && paddr <= tc->highaddr) || + !vm_addr_align_ok(paddr, tc->alignment)) + retval = 1; + return (retval); } @@ -106,7 +103,6 @@ common = newtag; common->impl = &bus_dma_bounce_impl; - common->parent = parent; common->alignment = alignment; common->boundary = boundary; common->lowaddr = trunc_page((vm_paddr_t)lowaddr) + (PAGE_SIZE - 1); @@ -115,7 +111,6 @@ common->nsegments = nsegments; common->maxsegsz = maxsegsz; common->flags = flags; - common->ref_count = 1; /* Count ourself */ if (lockfunc != NULL) { common->lockfunc = lockfunc; common->lockfuncarg = lockfuncarg; @@ -136,13 +131,7 @@ common->boundary); } - /* - * Short circuit looking at our parent directly since we have - * encapsulated all of its information. - */ - common->parent = parent->parent; common->domain = parent->domain; - atomic_add_int(&parent->ref_count, 1); } common->domain = vm_phys_domain_match(common->domain, 0ul, common->lowaddr); @@ -204,7 +193,6 @@ common = (struct bus_dma_tag_common *)dmat; - t->parent = (bus_dma_tag_t)common->parent; t->alignment = common->alignment; t->boundary = common->boundary; t->lowaddr = common->lowaddr;