git: d97838b7c2a6 - main - iommu: eliminate iommu_free_ctx()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 03 Nov 2024 19:47:46 UTC
The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=d97838b7c2a605932b6edf36f87abe7ccce74314 commit d97838b7c2a605932b6edf36f87abe7ccce74314 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2024-11-03 14:50:01 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2024-11-03 19:38:19 +0000 iommu: eliminate iommu_free_ctx() iommu_free_ctx_locked() alone is enough Sponsored by: Advanced Micro Devices (AMD) Sponsored by: The FreeBSD Foundation MFC after: 1 week --- sys/arm64/iommu/iommu.c | 19 +++---------------- sys/dev/iommu/busdma_iommu.c | 10 ++++++++-- sys/x86/iommu/amd_ctx.c | 19 ------------------- sys/x86/iommu/amd_drv.c | 1 - sys/x86/iommu/amd_iommu.h | 1 - sys/x86/iommu/intel_ctx.c | 19 ------------------- sys/x86/iommu/intel_dmar.h | 1 - sys/x86/iommu/intel_drv.c | 1 - sys/x86/iommu/iommu_utils.c | 6 ------ sys/x86/iommu/x86_iommu.h | 1 - 10 files changed, 11 insertions(+), 67 deletions(-) diff --git a/sys/arm64/iommu/iommu.c b/sys/arm64/iommu/iommu.c index 0fe59c5d10b6..5db48b3bc276 100644 --- a/sys/arm64/iommu/iommu.c +++ b/sys/arm64/iommu/iommu.c @@ -373,32 +373,19 @@ void iommu_free_ctx_locked(struct iommu_unit *iommu, struct iommu_ctx *ioctx) { struct bus_dma_tag_iommu *tag; + int error; IOMMU_ASSERT_LOCKED(iommu); tag = ioctx->tag; IOMMU_CTX_FREE(iommu->dev, ioctx); + IOMMU_UNLOCK(iommu); free(tag, M_IOMMU); -} - -void -iommu_free_ctx(struct iommu_ctx *ioctx) -{ - struct iommu_unit *iommu; - struct iommu_domain *iodom; - int error; - - iodom = ioctx->domain; - iommu = iodom->iommu; - - IOMMU_LOCK(iommu); - iommu_free_ctx_locked(iommu, ioctx); - IOMMU_UNLOCK(iommu); /* Since we have a domain per each ctx, remove the domain too. */ - error = iommu_domain_free(iodom); + error = iommu_domain_free(ioctx->domain); if (error) device_printf(iommu->dev, "Could not free a domain\n"); } diff --git a/sys/dev/iommu/busdma_iommu.c b/sys/dev/iommu/busdma_iommu.c index 4d295ed7c6b2..6856b0551dde 100644 --- a/sys/dev/iommu/busdma_iommu.c +++ b/sys/dev/iommu/busdma_iommu.c @@ -397,6 +397,8 @@ static int iommu_bus_dma_tag_destroy(bus_dma_tag_t dmat1) { struct bus_dma_tag_iommu *dmat; + struct iommu_unit *iommu; + struct iommu_ctx *ctx; int error; error = 0; @@ -407,8 +409,12 @@ iommu_bus_dma_tag_destroy(bus_dma_tag_t dmat1) error = EBUSY; goto out; } - if (dmat == dmat->ctx->tag) - iommu_free_ctx(dmat->ctx); + ctx = dmat->ctx; + if (dmat == ctx->tag) { + iommu = ctx->domain->iommu; + IOMMU_LOCK(iommu); + iommu_free_ctx_locked(iommu, dmat->ctx); + } free(dmat->segments, M_IOMMU_DMAMAP); free(dmat, M_DEVBUF); } diff --git a/sys/x86/iommu/amd_ctx.c b/sys/x86/iommu/amd_ctx.c index b3e85350a995..7e41ecf2dc04 100644 --- a/sys/x86/iommu/amd_ctx.c +++ b/sys/x86/iommu/amd_ctx.c @@ -398,16 +398,6 @@ amdiommu_free_ctx_locked(struct amdiommu_unit *unit, struct amdiommu_ctx *ctx) amdiommu_unref_domain_locked(unit, domain); } -static void -amdiommu_free_ctx(struct amdiommu_ctx *ctx) -{ - struct amdiommu_unit *unit; - - unit = CTX2AMD(ctx); - AMDIOMMU_LOCK(unit); - amdiommu_free_ctx_locked(unit, ctx); -} - static void amdiommu_unref_domain_locked(struct amdiommu_unit *unit, struct amdiommu_domain *domain) @@ -628,12 +618,3 @@ amdiommu_free_ctx_locked_method(struct iommu_unit *iommu, ctx = IOCTX2CTX(context); amdiommu_free_ctx_locked(unit, ctx); } - -void -amdiommu_free_ctx_method(struct iommu_ctx *context) -{ - struct amdiommu_ctx *ctx; - - ctx = IOCTX2CTX(context); - amdiommu_free_ctx(ctx); -} diff --git a/sys/x86/iommu/amd_drv.c b/sys/x86/iommu/amd_drv.c index 395cefc65caa..62315902fcd9 100644 --- a/sys/x86/iommu/amd_drv.c +++ b/sys/x86/iommu/amd_drv.c @@ -1072,7 +1072,6 @@ static struct x86_iommu amd_x86_iommu = { .domain_unload = amdiommu_domain_unload, .get_ctx = amdiommu_get_ctx, .free_ctx_locked = amdiommu_free_ctx_locked_method, - .free_ctx = amdiommu_free_ctx_method, .alloc_msi_intr = amdiommu_alloc_msi_intr, .map_msi_intr = amdiommu_map_msi_intr, .unmap_msi_intr = amdiommu_unmap_msi_intr, diff --git a/sys/x86/iommu/amd_iommu.h b/sys/x86/iommu/amd_iommu.h index 2b0db4f8fe6d..64dd13db9745 100644 --- a/sys/x86/iommu/amd_iommu.h +++ b/sys/x86/iommu/amd_iommu.h @@ -222,7 +222,6 @@ struct amdiommu_ctx *amdiommu_find_ctx_locked(struct amdiommu_unit *unit, uint16_t rid); void amdiommu_free_ctx_locked_method(struct iommu_unit *iommu, struct iommu_ctx *context); -void amdiommu_free_ctx_method(struct iommu_ctx *context); struct amdiommu_domain *amdiommu_find_domain(struct amdiommu_unit *unit, uint16_t rid); diff --git a/sys/x86/iommu/intel_ctx.c b/sys/x86/iommu/intel_ctx.c index c2371d4d9c4f..2bc5f8a9d361 100644 --- a/sys/x86/iommu/intel_ctx.c +++ b/sys/x86/iommu/intel_ctx.c @@ -803,16 +803,6 @@ dmar_free_ctx_locked(struct dmar_unit *dmar, struct dmar_ctx *ctx) TD_PINNED_ASSERT; } -static void -dmar_free_ctx(struct dmar_ctx *ctx) -{ - struct dmar_unit *dmar; - - dmar = CTX2DMAR(ctx); - DMAR_LOCK(dmar); - dmar_free_ctx_locked(dmar, ctx); -} - /* * Returns with the domain locked. */ @@ -941,12 +931,3 @@ dmar_free_ctx_locked_method(struct iommu_unit *iommu, ctx = IOCTX2CTX(context); dmar_free_ctx_locked(dmar, ctx); } - -void -dmar_free_ctx_method(struct iommu_ctx *context) -{ - struct dmar_ctx *ctx; - - ctx = IOCTX2CTX(context); - dmar_free_ctx(ctx); -} diff --git a/sys/x86/iommu/intel_dmar.h b/sys/x86/iommu/intel_dmar.h index 1a9b5041975c..57a66aae69b2 100644 --- a/sys/x86/iommu/intel_dmar.h +++ b/sys/x86/iommu/intel_dmar.h @@ -237,7 +237,6 @@ struct dmar_ctx *dmar_get_ctx_for_devpath(struct dmar_unit *dmar, uint16_t rid, int dmar_move_ctx_to_domain(struct dmar_domain *domain, struct dmar_ctx *ctx); void dmar_free_ctx_locked_method(struct iommu_unit *dmar, struct iommu_ctx *ctx); -void dmar_free_ctx_method(struct iommu_ctx *ctx); struct dmar_ctx *dmar_find_ctx_locked(struct dmar_unit *dmar, uint16_t rid); struct iommu_ctx *dmar_get_ctx(struct iommu_unit *iommu, device_t dev, uint16_t rid, bool id_mapped, bool rmrr_init); diff --git a/sys/x86/iommu/intel_drv.c b/sys/x86/iommu/intel_drv.c index 22d04029f9ae..b21c8460e830 100644 --- a/sys/x86/iommu/intel_drv.c +++ b/sys/x86/iommu/intel_drv.c @@ -1317,7 +1317,6 @@ static struct x86_iommu dmar_x86_iommu = { .domain_unload = dmar_domain_unload, .get_ctx = dmar_get_ctx, .free_ctx_locked = dmar_free_ctx_locked_method, - .free_ctx = dmar_free_ctx_method, .find = dmar_find_method, .alloc_msi_intr = dmar_alloc_msi_intr, .map_msi_intr = dmar_map_msi_intr, diff --git a/sys/x86/iommu/iommu_utils.c b/sys/x86/iommu/iommu_utils.c index 479e8637ee8e..2db02a98ca91 100644 --- a/sys/x86/iommu/iommu_utils.c +++ b/sys/x86/iommu/iommu_utils.c @@ -288,12 +288,6 @@ iommu_free_ctx_locked(struct iommu_unit *iommu, struct iommu_ctx *context) x86_iommu->free_ctx_locked(iommu, context); } -void -iommu_free_ctx(struct iommu_ctx *context) -{ - x86_iommu->free_ctx(context); -} - struct iommu_unit * iommu_find(device_t dev, bool verbose) { diff --git a/sys/x86/iommu/x86_iommu.h b/sys/x86/iommu/x86_iommu.h index eb4a9907a5d6..431228512fd8 100644 --- a/sys/x86/iommu/x86_iommu.h +++ b/sys/x86/iommu/x86_iommu.h @@ -81,7 +81,6 @@ struct x86_iommu { device_t dev, uint16_t rid, bool id_mapped, bool rmrr_init); void (*free_ctx_locked)(struct iommu_unit *iommu, struct iommu_ctx *context); - void (*free_ctx)(struct iommu_ctx *context); struct iommu_unit *(*find)(device_t dev, bool verbose); int (*alloc_msi_intr)(device_t src, u_int *cookies, u_int count); int (*map_msi_intr)(device_t src, u_int cpu, u_int vector,