From 120bf54d08ddffd4bf40b8156231f58ff26b26aa Mon Sep 17 00:00:00 2001 From: rstone Date: Tue, 1 Apr 2014 15:06:03 +0000 Subject: Revert PCI RID changes. My PCI RID changes somehow got intermixed with my PCI ARI patch when I committed it. I may have accidentally applied a patch to a non-clean working tree. Revert everything while I figure out what went wrong. Pointy hat to: rstone --- sys/x86/iommu/busdma_dmar.c | 24 ++++++++++++++---------- sys/x86/iommu/intel_ctx.c | 40 +++++++++++++++++----------------------- sys/x86/iommu/intel_dmar.h | 11 +++++++---- sys/x86/iommu/intel_drv.c | 10 +++------- sys/x86/iommu/intel_fault.c | 19 ++++--------------- sys/x86/iommu/intel_utils.c | 7 ++----- 6 files changed, 47 insertions(+), 64 deletions(-) (limited to 'sys/x86/iommu') diff --git a/sys/x86/iommu/busdma_dmar.c b/sys/x86/iommu/busdma_dmar.c index a397f42..488c7bb 100644 --- a/sys/x86/iommu/busdma_dmar.c +++ b/sys/x86/iommu/busdma_dmar.c @@ -93,7 +93,7 @@ dmar_bus_dma_is_dev_disabled(int domain, int bus, int slot, int func) * bounce mapping. */ static device_t -dmar_get_requester(device_t dev, uint16_t *rid) +dmar_get_requester(device_t dev, int *bus, int *slot, int *func) { devclass_t pci_class; device_t pci, pcib, requester; @@ -102,7 +102,9 @@ dmar_get_requester(device_t dev, uint16_t *rid) pci_class = devclass_find("pci"); requester = dev; - *rid = pci_get_rid(dev); + *bus = pci_get_bus(dev); + *slot = pci_get_slot(dev); + *func = pci_get_function(dev); /* * Walk the bridge hierarchy from the target device to the @@ -159,7 +161,8 @@ dmar_get_requester(device_t dev, uint16_t *rid) * same page tables for taken and * non-taken transactions. */ - *rid = PCI_RID(pci_get_bus(dev), 0, 0); + *bus = pci_get_bus(dev); + *slot = *func = 0; } else { /* * Neither the device nor the bridge @@ -168,7 +171,9 @@ dmar_get_requester(device_t dev, uint16_t *rid) * will use the bridge's BSF as the * requester ID. */ - *rid = pci_get_rid(pcib); + *bus = pci_get_bus(pcib); + *slot = pci_get_slot(pcib); + *func = pci_get_function(pcib); } } /* @@ -188,9 +193,9 @@ dmar_instantiate_ctx(struct dmar_unit *dmar, device_t dev, bool rmrr) device_t requester; struct dmar_ctx *ctx; bool disabled; - uint16_t rid; + int bus, slot, func; - requester = dmar_get_requester(dev, &rid); + requester = dmar_get_requester(dev, &bus, &slot, &func); /* * If the user requested the IOMMU disabled for the device, we @@ -199,10 +204,9 @@ dmar_instantiate_ctx(struct dmar_unit *dmar, device_t dev, bool rmrr) * Instead provide the identity mapping for the device * context. */ - disabled = dmar_bus_dma_is_dev_disabled(pci_get_domain(requester), - pci_get_bus(requester), pci_get_slot(requester), - pci_get_function(requester)); - ctx = dmar_get_ctx(dmar, requester, rid, disabled, rmrr); + disabled = dmar_bus_dma_is_dev_disabled(pci_get_domain(dev), bus, + slot, func); + ctx = dmar_get_ctx(dmar, requester, bus, slot, func, disabled, rmrr); if (ctx == NULL) return (NULL); if (disabled) { 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 #include #include -#include #include 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); diff --git a/sys/x86/iommu/intel_dmar.h b/sys/x86/iommu/intel_dmar.h index 1f842d4..0b68024 100644 --- a/sys/x86/iommu/intel_dmar.h +++ b/sys/x86/iommu/intel_dmar.h @@ -74,7 +74,9 @@ RB_PROTOTYPE(dmar_gas_entries_tree, dmar_map_entry, rb_entry, #define DMAR_MAP_ENTRY_TM 0x8000 /* Transient */ struct dmar_ctx { - uint16_t rid; /* pci RID */ + int bus; /* pci bus/slot/func */ + int slot; + int func; int domain; /* DID */ int mgaw; /* Real max address width */ int agaw; /* Adjusted guest address width */ @@ -267,11 +269,12 @@ void ctx_free_pgtbl(struct dmar_ctx *ctx); struct dmar_ctx *dmar_instantiate_ctx(struct dmar_unit *dmar, device_t dev, bool rmrr); -struct dmar_ctx *dmar_get_ctx(struct dmar_unit *dmar, device_t dev, - uint16_t rid, bool id_mapped, bool rmrr_init); +struct dmar_ctx *dmar_get_ctx(struct dmar_unit *dmar, device_t dev, + int bus, int slot, int func, bool id_mapped, bool rmrr_init); void dmar_free_ctx_locked(struct dmar_unit *dmar, struct dmar_ctx *ctx); void dmar_free_ctx(struct dmar_ctx *ctx); -struct dmar_ctx *dmar_find_ctx_locked(struct dmar_unit *dmar, uint16_t rid); +struct dmar_ctx *dmar_find_ctx_locked(struct dmar_unit *dmar, int bus, + int slot, int func); void dmar_ctx_unload_entry(struct dmar_map_entry *entry, bool free); void dmar_ctx_unload(struct dmar_ctx *ctx, struct dmar_map_entries_tailq *entries, bool cansleep); diff --git a/sys/x86/iommu/intel_drv.c b/sys/x86/iommu/intel_drv.c index ce3f284..a846b92 100644 --- a/sys/x86/iommu/intel_drv.c +++ b/sys/x86/iommu/intel_drv.c @@ -1005,9 +1005,7 @@ dmar_print_ctx(struct dmar_ctx *ctx, bool show_mappings) db_printf( " @%p pci%d:%d:%d dom %d mgaw %d agaw %d pglvl %d end %jx\n" " refs %d flags %x pgobj %p map_ents %u loads %lu unloads %lu\n", - ctx, pci_get_bus(ctx->ctx_tag.owner), - pci_get_slot(ctx->ctx_tag.owner), - pci_get_function(ctx->ctx_tag.owner), ctx->domain, ctx->mgaw, + ctx, ctx->bus, ctx->slot, ctx->func, ctx->domain, ctx->mgaw, ctx->agaw, ctx->pglvl, (uintmax_t)ctx->end, ctx->refs, ctx->flags, ctx->pgtbl_obj, ctx->entries_cnt, ctx->loads, ctx->unloads); @@ -1080,10 +1078,8 @@ DB_FUNC(dmar_ctx, db_dmar_print_ctx, db_show_table, CS_OWN, NULL) for (i = 0; i < dmar_devcnt; i++) { unit = device_get_softc(dmar_devs[i]); LIST_FOREACH(ctx, &unit->contexts, link) { - if (domain == unit->segment && - bus == pci_get_bus(ctx->ctx_tag.owner) && - device == pci_get_slot(ctx->ctx_tag.owner) && - function == pci_get_function(ctx->ctx_tag.owner)) { + if (domain == unit->segment && bus == ctx->bus && + device == ctx->slot && function == ctx->func) { dmar_print_ctx(ctx, show_mappings); goto out; } diff --git a/sys/x86/iommu/intel_fault.c b/sys/x86/iommu/intel_fault.c index af18010..18f8fef 100644 --- a/sys/x86/iommu/intel_fault.c +++ b/sys/x86/iommu/intel_fault.c @@ -45,8 +45,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include -#include #include #include #include @@ -205,28 +203,19 @@ dmar_fault_task(void *arg, int pending __unused) DMAR_FAULT_UNLOCK(unit); sid = DMAR_FRCD2_SID(fault_rec[1]); + bus = (sid >> 8) & 0xf; + slot = (sid >> 3) & 0x1f; + func = sid & 0x7; printf("DMAR%d: ", unit->unit); DMAR_LOCK(unit); - ctx = dmar_find_ctx_locked(unit, sid); + ctx = dmar_find_ctx_locked(unit, bus, slot, func); if (ctx == NULL) { printf(":"); - - /* - * Note that the slot and function will not be correct - * if ARI is in use, but without a ctx entry we have - * no way of knowing whether ARI is in use or not. - */ - bus = PCI_RID2BUS(sid); - slot = PCI_RID2SLOT(sid); - func = PCI_RID2FUNC(sid); } else { ctx->flags |= DMAR_CTX_FAULTED; ctx->last_fault_rec[0] = fault_rec[0]; ctx->last_fault_rec[1] = fault_rec[1]; device_print_prettyname(ctx->ctx_tag.owner); - bus = pci_get_bus(ctx->ctx_tag.owner); - slot = pci_get_slot(ctx->ctx_tag.owner); - func = pci_get_function(ctx->ctx_tag.owner); } DMAR_UNLOCK(unit); printf( diff --git a/sys/x86/iommu/intel_utils.c b/sys/x86/iommu/intel_utils.c index e221a1e..d81ec04 100644 --- a/sys/x86/iommu/intel_utils.c +++ b/sys/x86/iommu/intel_utils.c @@ -47,7 +47,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include @@ -130,10 +129,8 @@ ctx_set_agaw(struct dmar_ctx *ctx, int mgaw) } device_printf(ctx->dmar->dev, "context request mgaw %d for pci%d:%d:%d:%d, " - "no agaw found, sagaw %x\n", mgaw, ctx->dmar->segment, - pci_get_bus(ctx->ctx_tag.owner), - pci_get_slot(ctx->ctx_tag.owner), - pci_get_function(ctx->ctx_tag.owner), sagaw); + "no agaw found, sagaw %x\n", mgaw, ctx->dmar->segment, ctx->bus, + ctx->slot, ctx->func, sagaw); return (EINVAL); } -- cgit v1.1