From 72479f6bf9a62eb21e966e657a4cd25060d8dde5 Mon Sep 17 00:00:00 2001 From: Ruslan Bukin Date: Fri, 9 Oct 2020 13:11:14 +0000 Subject: [PATCH] Add iommu_get_dev_ctx() helper that allows to instantiate an iommu context for a given device_t. Submitted by: andrew Reviewed by: kib Sponsored by: DARPA, AFRL --- sys/dev/iommu/busdma_iommu.c | 24 +++++++++++++++++------- sys/dev/iommu/iommu.h | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/sys/dev/iommu/busdma_iommu.c b/sys/dev/iommu/busdma_iommu.c index d82a3ac97072..959238b33445 100644 --- a/sys/dev/iommu/busdma_iommu.c +++ b/sys/dev/iommu/busdma_iommu.c @@ -269,14 +269,12 @@ iommu_instantiate_ctx(struct iommu_unit *unit, device_t dev, bool rmrr) return (ctx); } -bus_dma_tag_t -iommu_get_dma_tag(device_t dev, device_t child) +struct iommu_ctx * +iommu_get_dev_ctx(device_t dev) { struct iommu_unit *unit; - struct iommu_ctx *ctx; - bus_dma_tag_t res; - unit = iommu_find(child, bootverbose); + unit = iommu_find(dev, bootverbose); /* Not in scope of any IOMMU ? */ if (unit == NULL) return (NULL); @@ -288,8 +286,20 @@ iommu_get_dma_tag(device_t dev, device_t child) dmar_instantiate_rmrr_ctxs(unit); #endif - ctx = iommu_instantiate_ctx(unit, child, false); - res = ctx == NULL ? NULL : (bus_dma_tag_t)ctx->tag; + return (iommu_instantiate_ctx(unit, dev, false)); +} + +bus_dma_tag_t +iommu_get_dma_tag(device_t dev, device_t child) +{ + struct iommu_ctx *ctx; + bus_dma_tag_t res; + + ctx = iommu_get_dev_ctx(child); + if (ctx == NULL) + return (NULL); + + res = (bus_dma_tag_t)ctx->tag; return (res); } diff --git a/sys/dev/iommu/iommu.h b/sys/dev/iommu/iommu.h index 6dfb23410722..dfb4c3073e58 100644 --- a/sys/dev/iommu/iommu.h +++ b/sys/dev/iommu/iommu.h @@ -233,6 +233,7 @@ int bus_dma_iommu_load_ident(bus_dma_tag_t dmat, bus_dmamap_t map, vm_paddr_t start, vm_size_t length, int flags); bus_dma_tag_t iommu_get_dma_tag(device_t dev, device_t child); +struct iommu_ctx *iommu_get_dev_ctx(device_t dev); SYSCTL_DECL(_hw_iommu);