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
This commit is contained in:
Konstantin Belousov 2024-11-03 16:50:01 +02:00
parent 57aebec4f7
commit d97838b7c2
10 changed files with 12 additions and 68 deletions

View File

@ -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);
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);
free(tag, M_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");
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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,

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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,

View File

@ -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)
{

View File

@ -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,