| 516 | } |
| 517 | |
| 518 | static struct dmar_ctx * |
| 519 | dmar_get_ctx_for_dev1(struct dmar_unit *dmar, device_t dev, uint16_t rid, |
| 520 | int dev_domain, int dev_busno, const void *dev_path, int dev_path_len, |
| 521 | bool id_mapped, bool rmrr_init) |
| 522 | { |
| 523 | struct dmar_domain *domain, *domain1; |
| 524 | struct dmar_ctx *ctx, *ctx1; |
| 525 | struct iommu_unit *unit; |
| 526 | dmar_ctx_entry_t *ctxp; |
| 527 | struct sf_buf *sf; |
| 528 | int bus, slot, func, error; |
| 529 | bool enable; |
| 530 | |
| 531 | if (dev != NULL) { |
| 532 | bus = pci_get_bus(dev); |
| 533 | slot = pci_get_slot(dev); |
| 534 | func = pci_get_function(dev); |
| 535 | } else { |
| 536 | bus = PCI_RID2BUS(rid); |
| 537 | slot = PCI_RID2SLOT(rid); |
| 538 | func = PCI_RID2FUNC(rid); |
| 539 | } |
| 540 | enable = false; |
| 541 | TD_PREP_PINNED_ASSERT; |
| 542 | unit = DMAR2IOMMU(dmar); |
| 543 | DMAR_LOCK(dmar); |
| 544 | KASSERT(!iommu_is_buswide_ctx(unit, bus) || (slot == 0 && func == 0), |
| 545 | ("iommu%d pci%d:%d:%d get_ctx for buswide", dmar->iommu.unit, bus, |
| 546 | slot, func)); |
| 547 | ctx = dmar_find_ctx_locked(dmar, rid); |
| 548 | error = 0; |
| 549 | if (ctx == NULL) { |
| 550 | /* |
| 551 | * Perform the allocations which require sleep or have |
| 552 | * higher chance to succeed if the sleep is allowed. |
| 553 | */ |
| 554 | DMAR_UNLOCK(dmar); |
| 555 | dmar_ensure_ctx_page(dmar, PCI_RID2BUS(rid)); |
| 556 | domain1 = dmar_domain_alloc(dmar, id_mapped); |
| 557 | if (domain1 == NULL) { |
| 558 | TD_PINNED_ASSERT; |
| 559 | return (NULL); |
| 560 | } |
| 561 | if (!id_mapped) { |
| 562 | error = domain_init_rmrr(domain1, dev, bus, |
| 563 | slot, func, dev_domain, dev_busno, dev_path, |
| 564 | dev_path_len); |
| 565 | if (error == 0) |
| 566 | error = dmar_reserve_pci_regions(domain1, dev); |
| 567 | if (error != 0) { |
| 568 | dmar_domain_destroy(domain1); |
| 569 | TD_PINNED_ASSERT; |
| 570 | return (NULL); |
| 571 | } |
| 572 | } |
| 573 | ctx1 = dmar_ctx_alloc(domain1, rid); |
| 574 | ctxp = dmar_map_ctx_entry(ctx1, &sf); |
| 575 | DMAR_LOCK(dmar); |
no test coverage detected