From nobody Wed Dec 06 23:21:43 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SlthR3cBVz538v1; Wed, 6 Dec 2023 23:21:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SlthR35r1z4FBn; Wed, 6 Dec 2023 23:21:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701904903; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pahnn88B631617buOddU2yJ0mh3pF0Yr3mSXQxXa5TY=; b=JioAKqQcLenVmtjYNOVcsxPP7mqwJxjJdNGNB5uerhY60ehWIeGY7ojPbd5FN9SzCTwZwo /PrkvMECB+LQVLWTqZFcbIRLPh85G2Lh7+7RZhA4Y30C/Xhb9eferfqVLNIoF3GJyMBHPf Sp/8ep42o/ExQF3hBHBJdZRgFIZzfjFHpncF067NqINRKyzoNkto172L9eTO4A9Fb/eswY mW8MlRxxG2B719oNvNA+G6LoTudq6QdfwxNLO4OucZqORx1dXSC75KF2KtqPCCdRwEEWvh /jVKJPWzGTVNiRtn9Bkw55AxqCCFmp+6s6GW2EZ2RSIO4Kbk2vm2frRzugivSg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1701904903; a=rsa-sha256; cv=none; b=Nl8W/UKv9rFsupEciNP9MpWk/aDo+V7le1he3yZEhM7TNgBu8NR1BJWBo3bRQJ1VfzHG8Q wDD3FE1O88aiQImHyXlkIMmWqheg8UKTYMW2k4piTXW3zW+hVppoeblew4olouhf9LHVV+ GLrqZB5qd1UTQKcAKuYZRzTc8WGzhWQhUTW07Baknj88dJzP2C6a0TjKRFdNLB5ihXIBEP C1GJEUzsNas4yHWMGZtQ2vGFBXaBgzJZqkaGpC/N67oPRIDLA2EQqJ/NHD4n+ldpG+s6Ze 3Xa0M4d/gMzlMVHY4+uUhN5jyItae/Py9B2/aZf5LZczIJSAz3bXfjw9xfgNCw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701904903; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pahnn88B631617buOddU2yJ0mh3pF0Yr3mSXQxXa5TY=; b=soCXQ8yMlXa+f526rFdEpnngoxQsw/QEkCFYPOhRWuF5gmbQetSog9PQhcSAYmPAKBQrPN VcIJSospFA0xiQf2hQOQ9Bk1PZWJE2Pmr26Ee8l9FirhF12n9xwrXWOX9JbpbdpE8+4uuG mQ8lANjRwRxPPfh4r+a4ClLOiDezPaBY5CB4qiswZBbPUEDktmKrH+bVGjH3hamXVuE0yn b+NrlD3bFZ3qaN6JQpym4TWrB3gFr3nes04vhy/AM0kW2jw/3wCxfalfGMb+OChD9aZhks 2I7N3MtTHGUou+wDLg0m5PY/GuJ5307mDlD2Rh8tCGeYi2+Nf8//uutqIzXhqg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4SlthR1v39z1CJd; Wed, 6 Dec 2023 23:21:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3B6NLhPI018003; Wed, 6 Dec 2023 23:21:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3B6NLhv3018000; Wed, 6 Dec 2023 23:21:43 GMT (envelope-from git) Date: Wed, 6 Dec 2023 23:21:43 GMT Message-Id: <202312062321.3B6NLhv3018000@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 1228b93b410a - main - busdma: remove parent tag tracking List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1228b93b410a299cc2a730fe4b065bcffeb162c2 Auto-Submitted: auto-generated The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=1228b93b410a299cc2a730fe4b065bcffeb162c2 commit 1228b93b410a299cc2a730fe4b065bcffeb162c2 Author: Mitchell Horne AuthorDate: 2023-12-06 23:08:51 +0000 Commit: Mitchell Horne CommitDate: 2023-12-06 23:11:39 +0000 busdma: remove parent tag tracking Without filter functions, we do not need to keep track of tag ancestry. All inheritance of the parent tag's parameters occurs when creating the new child tag. Reviewed by: jhb Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D42895 --- sys/arm/arm/busdma_machdep.c | 60 +++++------------------------------- sys/arm64/arm64/busdma_bounce.c | 33 +++----------------- sys/arm64/arm64/busdma_machdep.c | 17 ++-------- sys/arm64/include/bus_dma_impl.h | 2 -- sys/dev/iommu/busdma_iommu.c | 23 +++++--------- sys/powerpc/powerpc/busdma_machdep.c | 50 +++++------------------------- sys/riscv/include/bus_dma_impl.h | 2 -- sys/riscv/riscv/busdma_bounce.c | 29 +++-------------- sys/riscv/riscv/busdma_machdep.c | 19 ++---------- sys/x86/include/busdma_impl.h | 2 -- sys/x86/iommu/intel_ctx.c | 1 - sys/x86/x86/busdma_bounce.c | 29 +++-------------- sys/x86/x86/busdma_machdep.c | 22 +++---------- 13 files changed, 48 insertions(+), 241 deletions(-) diff --git a/sys/arm/arm/busdma_machdep.c b/sys/arm/arm/busdma_machdep.c index cf1fd0209734..dd31f7779b21 100644 --- a/sys/arm/arm/busdma_machdep.c +++ b/sys/arm/arm/busdma_machdep.c @@ -77,7 +77,6 @@ struct bounce_page; 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 @@ struct bus_dma_tag { 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 @@ might_bounce(bus_dma_tag_t dmat, bus_dmamap_t map, bus_addr_t addr, * * 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 @@ must_bounce(bus_dma_tag_t dmat, bus_dmamap_t map, bus_addr_t paddr, 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 @@ bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, 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 @@ bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, 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 @@ bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, 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 @@ bus_dma_template_clone(bus_dma_template_t *t, bus_dma_tag_t dmat) 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 @@ bus_dma_tag_set_domain(bus_dma_tag_t dmat, int domain) 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 index 7585d950fcbb..3b5521a31b92 100644 --- a/sys/arm64/arm64/busdma_bounce.c +++ b/sys/arm64/arm64/busdma_bounce.c @@ -309,42 +309,19 @@ bounce_bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, 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 index aa5359b4552a..c88b28aa3e22 100644 --- a/sys/arm64/arm64/busdma_machdep.c +++ b/sys/arm64/arm64/busdma_machdep.c @@ -61,12 +61,8 @@ int 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_bus_dma_tag_create(struct bus_dma_tag_common *parent, 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_bus_dma_tag_create(struct bus_dma_tag_common *parent, 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_bus_dma_tag_create(struct bus_dma_tag_common *parent, 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 @@ bus_dma_template_clone(bus_dma_template_t *t, bus_dma_tag_t dmat) 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 index 1abce30b5b4c..55af1b477979 100644 --- 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 @@ struct bus_dma_tag_common { 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 index f041838eac39..d870e2af3984 100644 --- a/sys/dev/iommu/busdma_iommu.c +++ b/sys/dev/iommu/busdma_iommu.c @@ -394,33 +394,24 @@ iommu_bus_dma_tag_set_domain(bus_dma_tag_t dmat) 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 index 3065526427e2..a4c30ee9470c 100644 --- a/sys/powerpc/powerpc/busdma_machdep.c +++ b/sys/powerpc/powerpc/busdma_machdep.c @@ -63,7 +63,6 @@ struct bounce_page; 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 @@ struct bus_dma_tag { 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 @@ run_filter(bus_dma_tag_t dmat, bus_addr_t paddr) 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 @@ bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, 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 @@ bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, 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 @@ bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, 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 @@ bus_dma_template_clone(bus_dma_template_t *t, bus_dma_tag_t dmat) 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 @@ bus_dma_tag_set_domain(bus_dma_tag_t dmat, int domain) 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 @@ bus_dma_tag_destroy(bus_dma_tag_t dmat) 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 index d6e1d4ed632e..550ba648615c 100644 --- 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 @@ struct bus_dma_tag_common { 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 index 6ac9a9cd678a..e9801a8a732e 100644 --- a/sys/riscv/riscv/busdma_bounce.c +++ b/sys/riscv/riscv/busdma_bounce.c @@ -196,38 +196,19 @@ bounce_bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, 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 index e992803f3ff2..630938a394e1 100644 --- a/sys/riscv/riscv/busdma_machdep.c +++ b/sys/riscv/riscv/busdma_machdep.c @@ -62,13 +62,10 @@ bus_dma_run_filter(struct bus_dma_tag_common *tc, bus_addr_t paddr) 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_bus_dma_tag_create(struct bus_dma_tag_common *parent, 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_bus_dma_tag_create(struct bus_dma_tag_common *parent, 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_bus_dma_tag_create(struct bus_dma_tag_common *parent, 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 @@ bus_dma_template_clone(bus_dma_template_t *t, bus_dma_tag_t dmat) 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 index 4718c67dacc1..2e4c83b04d72 100644 --- 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 @@ struct bus_dma_tag_common { 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 index 30771e061ec9..76a53f6bbd1a 100644 --- a/sys/x86/iommu/intel_ctx.c +++ b/sys/x86/iommu/intel_ctx.c @@ -128,7 +128,6 @@ device_tag_init(struct dmar_ctx *ctx, device_t dev) 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 index 01e799a1133d..992f455ceb96 100644 --- a/sys/x86/x86/busdma_bounce.c +++ b/sys/x86/x86/busdma_bounce.c @@ -227,38 +227,19 @@ bounce_bus_dma_tag_set_domain(bus_dma_tag_t dmat) 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 index bb1b6a393fb0..6fe49367f7d8 100644 --- a/sys/x86/x86/busdma_machdep.c +++ b/sys/x86/x86/busdma_machdep.c @@ -67,14 +67,11 @@ bus_dma_run_filter(struct bus_dma_tag_common *tc, vm_paddr_t paddr) 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_bus_dma_tag_create(struct bus_dma_tag_common *parent, 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_bus_dma_tag_create(struct bus_dma_tag_common *parent, 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_bus_dma_tag_create(struct bus_dma_tag_common *parent, 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 @@ bus_dma_template_clone(bus_dma_template_t *t, bus_dma_tag_t dmat) 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;