diff options
Diffstat (limited to 'sys/x86/iommu/intel_ctx.c')
-rw-r--r-- | sys/x86/iommu/intel_ctx.c | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/sys/x86/iommu/intel_ctx.c b/sys/x86/iommu/intel_ctx.c index 8947b7b..0b3adeb 100644 --- a/sys/x86/iommu/intel_ctx.c +++ b/sys/x86/iommu/intel_ctx.c @@ -63,7 +63,6 @@ __FBSDID("$FreeBSD$"); #include <x86/iommu/intel_reg.h> #include <x86/iommu/busdma_dmar.h> #include <x86/iommu/intel_dmar.h> -#include <dev/pci/pcireg.h> #include <dev/pci/pcivar.h> static MALLOC_DEFINE(M_DMAR_CTX, "dmar_ctx", "Intel DMAR Context"); @@ -106,14 +105,14 @@ dmar_map_ctx_entry(struct dmar_ctx *ctx, struct sf_buf **sfp) { dmar_ctx_entry_t *ctxp; - ctxp = dmar_map_pgtbl(ctx->dmar->ctx_obj, 1 + PCI_RID2BUS(ctx->rid), + ctxp = dmar_map_pgtbl(ctx->dmar->ctx_obj, 1 + ctx->bus, DMAR_PGF_NOALLOC | DMAR_PGF_WAITOK, sfp); - ctxp += ctx->rid & 0xff; + ctxp += ((ctx->slot & 0x1f) << 3) + (ctx->func & 0x7); return (ctxp); } static void -ctx_tag_init(struct dmar_ctx *ctx, device_t dev) +ctx_tag_init(struct dmar_ctx *ctx) { bus_addr_t maxaddr; @@ -127,7 +126,6 @@ ctx_tag_init(struct dmar_ctx *ctx, device_t dev) ctx->ctx_tag.common.nsegments = BUS_SPACE_UNRESTRICTED; ctx->ctx_tag.common.maxsegsz = maxaddr; ctx->ctx_tag.ctx = ctx; - ctx->ctx_tag.owner = dev; /* XXXKIB initialize tag further */ } @@ -140,10 +138,7 @@ ctx_id_entry_init(struct dmar_ctx *ctx, dmar_ctx_entry_t *ctxp) unit = ctx->dmar; KASSERT(ctxp->ctx1 == 0 && ctxp->ctx2 == 0, ("dmar%d: initialized ctx entry %d:%d:%d 0x%jx 0x%jx", - unit->unit, pci_get_bus(ctx->ctx_tag.owner), - pci_get_slot(ctx->ctx_tag.owner), - pci_get_function(ctx->ctx_tag.owner), - ctxp->ctx1, + unit->unit, ctx->bus, ctx->slot, ctx->func, ctxp->ctx1, ctxp->ctx2)); ctxp->ctx2 = DMAR_CTX2_DID(ctx->domain); ctxp->ctx2 |= ctx->awlvl; @@ -232,7 +227,7 @@ ctx_init_rmrr(struct dmar_ctx *ctx, device_t dev) } static struct dmar_ctx * -dmar_get_ctx_alloc(struct dmar_unit *dmar, uint16_t rid) +dmar_get_ctx_alloc(struct dmar_unit *dmar, int bus, int slot, int func) { struct dmar_ctx *ctx; @@ -242,7 +237,9 @@ dmar_get_ctx_alloc(struct dmar_unit *dmar, uint16_t rid) TASK_INIT(&ctx->unload_task, 0, dmar_ctx_unload_task, ctx); mtx_init(&ctx->lock, "dmarctx", NULL, MTX_DEF); ctx->dmar = dmar; - ctx->rid = rid; + ctx->bus = bus; + ctx->slot = slot; + ctx->func = func; return (ctx); } @@ -265,22 +262,19 @@ dmar_ctx_dtr(struct dmar_ctx *ctx, bool gas_inited, bool pgtbl_inited) } struct dmar_ctx * -dmar_get_ctx(struct dmar_unit *dmar, device_t dev, uint16_t rid, bool id_mapped, - bool rmrr_init) +dmar_get_ctx(struct dmar_unit *dmar, device_t dev, int bus, int slot, int func, + bool id_mapped, bool rmrr_init) { struct dmar_ctx *ctx, *ctx1; dmar_ctx_entry_t *ctxp; struct sf_buf *sf; - int bus, slot, func, error, mgaw; + int error, mgaw; bool enable; - bus = pci_get_bus(dev); - slot = pci_get_slot(dev); - func = pci_get_function(dev); enable = false; TD_PREP_PINNED_ASSERT; DMAR_LOCK(dmar); - ctx = dmar_find_ctx_locked(dmar, rid); + ctx = dmar_find_ctx_locked(dmar, bus, slot, func); error = 0; if (ctx == NULL) { /* @@ -289,7 +283,7 @@ dmar_get_ctx(struct dmar_unit *dmar, device_t dev, uint16_t rid, bool id_mapped, */ DMAR_UNLOCK(dmar); dmar_ensure_ctx_page(dmar, bus); - ctx1 = dmar_get_ctx_alloc(dmar, rid); + ctx1 = dmar_get_ctx_alloc(dmar, bus, slot, func); if (id_mapped) { /* @@ -357,7 +351,7 @@ dmar_get_ctx(struct dmar_unit *dmar, device_t dev, uint16_t rid, bool id_mapped, * Recheck the contexts, other thread might have * already allocated needed one. */ - ctx = dmar_find_ctx_locked(dmar, rid); + ctx = dmar_find_ctx_locked(dmar, bus, slot, func); if (ctx == NULL) { ctx = ctx1; ctx->ctx_tag.owner = dev; @@ -369,7 +363,7 @@ dmar_get_ctx(struct dmar_unit *dmar, device_t dev, uint16_t rid, bool id_mapped, TD_PINNED_ASSERT; return (NULL); } - ctx_tag_init(ctx, dev); + ctx_tag_init(ctx); /* * This is the first activated context for the @@ -530,14 +524,14 @@ dmar_free_ctx(struct dmar_ctx *ctx) } struct dmar_ctx * -dmar_find_ctx_locked(struct dmar_unit *dmar, uint16_t rid) +dmar_find_ctx_locked(struct dmar_unit *dmar, int bus, int slot, int func) { struct dmar_ctx *ctx; DMAR_ASSERT_LOCKED(dmar); LIST_FOREACH(ctx, &dmar->contexts, link) { - if (ctx->rid == rid) + if (ctx->bus == bus && ctx->slot == slot && ctx->func == func) return (ctx); } return (NULL); |