Lines Matching +full:msi +full:- +full:specifier
1 // SPDX-License-Identifier: GPL-2.0
8 * This driver acts as a paravirtual front-end for PCI Express root buses.
9 * When a PCI Express function (either an entire device or an SR-IOV
13 * VM within Hyper-V, there may seem to be no PCI bus at all in the VM
18 * to the VM using this front-end will appear at "device 0", the domain will
24 * MSI or MSI-X) associated with the functions on the bus. As interrupts are
28 * vector. This driver does not support level-triggered (line-based)
32 * The rest of this driver mostly maps PCI concepts onto underlying Hyper-V
34 * by Hyper-V is mapped into a single page of memory space, and the
37 * the PCI back-end driver in Hyper-V.
43 #include <linux/pci-ecam.h>
47 #include <linux/msi.h>
70 #define CPU_AFFINITY_ALL -1ULL
73 * Supported protocol versions in the order of probing - highest go
85 #define CFG_PAGE_SIZE (PCI_CONFIG_MMIO_LENGTH - CFG_PAGE_OFFSET)
152 * Function numbers are 8-bits wide on Express, as interpreted through ARI,
155 * the Hyper-V parent partition.
208 * occupied by this Message-Signaled
209 * Interrupt. For "MSI", as first defined
211 * 32. For "MSI-X," as first defined in PCI
212 * 3.0, this must be 1, as each MSI-X table
226 * struct hv_msi_desc2 - 1.2 version of hv_msi_desc
232 * occupied by this Message-Signaled
233 * Interrupt. For "MSI", as first defined
235 * 32. For "MSI-X," as first defined in PCI
236 * 3.0, this must be 1, as each MSI-X table
250 * struct hv_msi_desc3 - 1.3 version of hv_msi_desc
270 * a message-signaled interrupt, either MSI
271 * or MSI-X.
611 return cfg->vector; in hv_msi_get_int_vector()
621 * CPU vectors is not needed for multi-MSI in hv_msi_prepare()
623 if (info->type == X86_IRQ_ALLOC_TYPE_PCI_MSI) in hv_msi_prepare()
624 info->flags &= ~X86_IRQ_ALLOC_CONTIGUOUS_VECTORS; in hv_msi_prepare()
630 * hv_arch_irq_unmask() - "Unmask" the IRQ by setting its current
634 * Build new a destination for the MSI and make a hypercall to
656 pbus = pdev->bus; in hv_arch_irq_unmask()
657 hbus = container_of(pbus->sysdata, struct hv_pcibus_device, sysdata); in hv_arch_irq_unmask()
658 int_desc = data->chip_data; in hv_arch_irq_unmask()
660 spin_lock_irqsave(&hbus->retarget_msi_interrupt_lock, flags); in hv_arch_irq_unmask()
662 params = &hbus->retarget_msi_interrupt_params; in hv_arch_irq_unmask()
664 params->partition_id = HV_PARTITION_ID_SELF; in hv_arch_irq_unmask()
665 params->int_entry.source = HV_INTERRUPT_SOURCE_MSI; in hv_arch_irq_unmask()
666 params->int_entry.msi_entry.address.as_uint32 = int_desc->address & 0xffffffff; in hv_arch_irq_unmask()
667 params->int_entry.msi_entry.data.as_uint32 = int_desc->data; in hv_arch_irq_unmask()
668 params->device_id = (hbus->hdev->dev_instance.b[5] << 24) | in hv_arch_irq_unmask()
669 (hbus->hdev->dev_instance.b[4] << 16) | in hv_arch_irq_unmask()
670 (hbus->hdev->dev_instance.b[7] << 8) | in hv_arch_irq_unmask()
671 (hbus->hdev->dev_instance.b[6] & 0xf8) | in hv_arch_irq_unmask()
672 PCI_FUNC(pdev->devfn); in hv_arch_irq_unmask()
673 params->int_target.vector = hv_msi_get_int_vector(data); in hv_arch_irq_unmask()
676 * Honoring apic->delivery_mode set to APIC_DELIVERY_MODE_FIXED by in hv_arch_irq_unmask()
682 if (hbus->protocol_version >= PCI_PROTOCOL_VERSION_1_2) { in hv_arch_irq_unmask()
690 params->int_target.flags |= in hv_arch_irq_unmask()
699 nr_bank = cpumask_to_vpset(¶ms->int_target.vp_set, tmp); in hv_arch_irq_unmask()
708 * var-sized hypercall, var-size starts after vp_mask (thus in hv_arch_irq_unmask()
715 params->int_target.vp_mask |= in hv_arch_irq_unmask()
724 spin_unlock_irqrestore(&hbus->retarget_msi_interrupt_lock, flags); in hv_arch_irq_unmask()
731 * refer to cpu_disable_common() -> fixup_irqs() -> in hv_arch_irq_unmask()
732 * irq_migrate_all_off_this_cpu() -> migrate_one_irq(). in hv_arch_irq_unmask()
737 * into the irqdata data structure in migrate_one_irq() -> in hv_arch_irq_unmask()
738 * irq_do_set_affinity() -> hv_set_affinity(), so later when the VM in hv_arch_irq_unmask()
742 if (!hv_result_success(res) && hbus->state != hv_pcibus_removing) in hv_arch_irq_unmask()
743 dev_err(&hbus->hdev->device, in hv_arch_irq_unmask()
750 * starting with a power of two to satisfy power of 2 multi-MSI requirement.
753 #define HV_PCI_MSI_SPI_NR (1020 - HV_PCI_MSI_SPI_START)
764 /* Hyper-V vPCI MSI GIC IRQ domain */
767 /* Hyper-V PCI MSI IRQ chip */
769 .name = "MSI",
778 return irqd->parent_data->hwirq; in hv_msi_get_int_vector()
792 struct hv_pci_chip_data *chip_data = domain->host_data; in hv_pci_vec_irq_free()
794 int first = d->hwirq - HV_PCI_MSI_SPI_START; in hv_pci_vec_irq_free()
797 mutex_lock(&chip_data->map_lock); in hv_pci_vec_irq_free()
798 bitmap_release_region(chip_data->spi_map, in hv_pci_vec_irq_free()
801 mutex_unlock(&chip_data->map_lock); in hv_pci_vec_irq_free()
822 struct hv_pci_chip_data *chip_data = domain->host_data; in hv_pci_vec_alloc_device_irq()
826 mutex_lock(&chip_data->map_lock); in hv_pci_vec_alloc_device_irq()
827 index = bitmap_find_free_region(chip_data->spi_map, in hv_pci_vec_alloc_device_irq()
830 mutex_unlock(&chip_data->map_lock); in hv_pci_vec_alloc_device_irq()
832 return -ENOSPC; in hv_pci_vec_alloc_device_irq()
847 fwspec.fwnode = domain->parent->fwnode; in hv_pci_vec_irq_gic_domain_alloc()
857 * Since the interrupt specifier is not coming from ACPI or DT, the in hv_pci_vec_irq_gic_domain_alloc()
861 d = irq_domain_get_irq_data(domain->parent, virq); in hv_pci_vec_irq_gic_domain_alloc()
863 return d->chip->irq_set_type(d, IRQ_TYPE_EDGE_RISING); in hv_pci_vec_irq_gic_domain_alloc()
889 domain->host_data); in hv_pci_vec_irq_domain_alloc()
898 * composing MSI from the hypervisor. GIC will eventually set the right
922 int ret = -ENOMEM; in hv_pci_irqchip_init()
928 mutex_init(&chip_data->map_lock); in hv_pci_irqchip_init()
943 pr_err("Failed to create Hyper-V arm64 vPCI MSI IRQ domain\n"); in hv_pci_irqchip_init()
964 * registers which Hyper-V already supports, so no hypercall needed.
970 * hv_pci_generic_compl() - Invoked for a completion packet
984 comp_pkt->completion_status = resp->status; in hv_pci_generic_compl()
985 complete(&comp_pkt->host_event); in hv_pci_generic_compl()
993 refcount_inc(&hpdev->refs); in get_pcichild()
998 if (refcount_dec_and_test(&hpdev->refs)) in put_pcichild()
1010 if (hdev->channel->rescind) { in wait_for_response()
1011 dev_warn_once(&hdev->device, "The device is gone.\n"); in wait_for_response()
1012 return -ENODEV; in wait_for_response()
1023 * devfn_to_wslot() - Convert from Linux PCI slot to Windows
1042 * wslot_to_devfn() - Convert from Windows PCI slot to Linux
1059 * of pages in memory-mapped I/O space. Writing to the first page chooses
1066 * _hv_pcifront_read_config() - Internal PCI config read
1076 void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + where; in _hv_pcifront_read_config()
1082 memcpy(val, ((u8 *)&hpdev->desc.v_id) + where, size); in _hv_pcifront_read_config()
1085 memcpy(val, ((u8 *)&hpdev->desc.rev) + where - in _hv_pcifront_read_config()
1089 memcpy(val, (u8 *)&hpdev->desc.subsystem_id + where - in _hv_pcifront_read_config()
1098 * Interrupt Line and Interrupt PIN are hard-wired to zero in _hv_pcifront_read_config()
1099 * because this front-end only supports message-signaled in _hv_pcifront_read_config()
1104 spin_lock_irqsave(&hpdev->hbus->config_lock, flags); in _hv_pcifront_read_config()
1106 writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr); in _hv_pcifront_read_config()
1126 spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); in _hv_pcifront_read_config()
1128 dev_err(&hpdev->hbus->hdev->device, in _hv_pcifront_read_config()
1137 void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + in hv_pcifront_get_vendor_id()
1140 spin_lock_irqsave(&hpdev->hbus->config_lock, flags); in hv_pcifront_get_vendor_id()
1143 writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr); in hv_pcifront_get_vendor_id()
1153 spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); in hv_pcifront_get_vendor_id()
1159 * _hv_pcifront_write_config() - Internal PCI config write
1169 void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + where; in _hv_pcifront_write_config()
1173 /* SSIDs and ROM BARs are read-only */ in _hv_pcifront_write_config()
1175 spin_lock_irqsave(&hpdev->hbus->config_lock, flags); in _hv_pcifront_write_config()
1177 writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr); in _hv_pcifront_write_config()
1197 spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); in _hv_pcifront_write_config()
1199 dev_err(&hpdev->hbus->hdev->device, in _hv_pcifront_write_config()
1205 * hv_pcifront_read_config() - Read configuration space
1219 container_of(bus->sysdata, struct hv_pcibus_device, sysdata); in hv_pcifront_read_config()
1233 * hv_pcifront_write_config() - Write configuration space
1247 container_of(bus->sysdata, struct hv_pcibus_device, sysdata); in hv_pcifront_write_config()
1269 * Hyper-V SR-IOV provides a backchannel mechanism in software for
1272 * but instead of doing reads and writes in 32-bit chunks through a very slow
1275 * Nearly every SR-IOV device contains just such a communications channel in
1299 * hv_pci_read_config_compl() - Invoked when a response packet
1315 comp->comp_pkt.completion_status = -1; in hv_pci_read_config_compl()
1319 data_len = resp_packet_size - hdr_len; in hv_pci_read_config_compl()
1320 if (data_len > 0 && read_resp->status == 0) { in hv_pci_read_config_compl()
1321 comp->bytes_returned = min(comp->len, data_len); in hv_pci_read_config_compl()
1322 memcpy(comp->buf, read_resp->bytes, comp->bytes_returned); in hv_pci_read_config_compl()
1324 comp->bytes_returned = 0; in hv_pci_read_config_compl()
1327 comp->comp_pkt.completion_status = read_resp->status; in hv_pci_read_config_compl()
1329 complete(&comp->comp_pkt.host_event); in hv_pci_read_config_compl()
1333 * hv_read_config_block() - Sends a read config block request to
1334 * the back-end driver running in the Hyper-V parent partition.
1339 * @bytes_returned: Size which came back from the back-end driver.
1341 * Return: 0 on success, -errno on failure
1348 container_of(pdev->bus->sysdata, struct hv_pcibus_device, in hv_read_config_block()
1359 return -EINVAL; in hv_read_config_block()
1369 read_blk->message_type.type = PCI_READ_BLOCK; in hv_read_config_block()
1370 read_blk->wslot.slot = devfn_to_wslot(pdev->devfn); in hv_read_config_block()
1371 read_blk->block_id = block_id; in hv_read_config_block()
1372 read_blk->bytes_requested = len; in hv_read_config_block()
1374 ret = vmbus_sendpacket(hbus->hdev->channel, read_blk, in hv_read_config_block()
1381 ret = wait_for_response(hbus->hdev, &comp_pkt.comp_pkt.host_event); in hv_read_config_block()
1387 dev_err(&hbus->hdev->device, in hv_read_config_block()
1391 return -EIO; in hv_read_config_block()
1399 * hv_pci_write_config_compl() - Invoked when a response packet for a write
1410 comp_pkt->completion_status = resp->status; in hv_pci_write_config_compl()
1411 complete(&comp_pkt->host_event); in hv_pci_write_config_compl()
1415 * hv_write_config_block() - Sends a write config block request to the
1416 * back-end driver running in the Hyper-V parent partition.
1422 * Return: 0 on success, -errno on failure
1428 container_of(pdev->bus->sysdata, struct hv_pcibus_device, in hv_write_config_block()
1441 return -EINVAL; in hv_write_config_block()
1449 write_blk->message_type.type = PCI_WRITE_BLOCK; in hv_write_config_block()
1450 write_blk->wslot.slot = devfn_to_wslot(pdev->devfn); in hv_write_config_block()
1451 write_blk->block_id = block_id; in hv_write_config_block()
1452 write_blk->byte_count = len; in hv_write_config_block()
1453 memcpy(write_blk->bytes, buf, len); in hv_write_config_block()
1460 * specified in write_blk->byte_count. in hv_write_config_block()
1464 ret = vmbus_sendpacket(hbus->hdev->channel, write_blk, pkt_size, in hv_write_config_block()
1470 ret = wait_for_response(hbus->hdev, &comp_pkt.host_event); in hv_write_config_block()
1475 dev_err(&hbus->hdev->device, in hv_write_config_block()
1478 return -EIO; in hv_write_config_block()
1485 * hv_register_block_invalidate() - Invoked when a config block invalidation
1486 * arrives from the back-end driver.
1491 * Return: 0 on success, -errno on failure
1498 container_of(pdev->bus->sysdata, struct hv_pcibus_device, in hv_register_block_invalidate()
1502 hpdev = get_pcichild_wslot(hbus, devfn_to_wslot(pdev->devfn)); in hv_register_block_invalidate()
1504 return -ENODEV; in hv_register_block_invalidate()
1506 hpdev->block_invalidate = block_invalidate; in hv_register_block_invalidate()
1507 hpdev->invalidate_context = context; in hv_register_block_invalidate()
1524 if (!int_desc->vector_count) { in hv_int_desc_free()
1530 int_pkt->message_type.type = in hv_int_desc_free()
1532 int_pkt->wslot.slot = hpdev->desc.win_slot.slot; in hv_int_desc_free()
1533 int_pkt->int_desc = *int_desc; in hv_int_desc_free()
1534 vmbus_sendpacket(hpdev->hbus->hdev->channel, int_pkt, sizeof(*int_pkt), in hv_int_desc_free()
1540 * hv_msi_free() - Free the MSI.
1542 * @info: Extra MSI-related context
1545 * The Hyper-V parent partition and hypervisor are tracking the
1558 struct msi_desc *msi = irq_data_get_msi_desc(irq_data); in hv_msi_free() local
1560 pdev = msi_desc_to_pci_dev(msi); in hv_msi_free()
1561 hbus = info->data; in hv_msi_free()
1566 irq_data->chip_data = NULL; in hv_msi_free()
1567 hpdev = get_pcichild_wslot(hbus, devfn_to_wslot(pdev->devfn)); in hv_msi_free()
1580 if (data->parent_data->chip->irq_mask) in hv_irq_mask()
1588 if (data->parent_data->chip->irq_unmask) in hv_irq_unmask()
1606 comp_pkt->comp_pkt.completion_status = -1; in hv_pci_compose_compl()
1609 comp_pkt->comp_pkt.completion_status = resp->status; in hv_pci_compose_compl()
1610 comp_pkt->int_desc = int_resp->int_desc; in hv_pci_compose_compl()
1612 complete(&comp_pkt->comp_pkt.host_event); in hv_pci_compose_compl()
1619 int_pkt->message_type.type = PCI_CREATE_INTERRUPT_MESSAGE; in hv_compose_msi_req_v1()
1620 int_pkt->wslot.slot = slot; in hv_compose_msi_req_v1()
1621 int_pkt->int_desc.vector = vector; in hv_compose_msi_req_v1()
1622 int_pkt->int_desc.vector_count = vector_count; in hv_compose_msi_req_v1()
1623 int_pkt->int_desc.delivery_mode = DELIVERY_MODE; in hv_compose_msi_req_v1()
1626 * Create MSI w/ dummy vCPU set, overwritten by subsequent retarget in in hv_compose_msi_req_v1()
1629 int_pkt->int_desc.cpu_mask = CPU_AFFINITY_ALL; in hv_compose_msi_req_v1()
1637 * interrupted is specified later in hv_irq_unmask() and communicated to Hyper-V
1639 * not irrelevant because Hyper-V chooses the physical CPU to handle the
1641 * hv_compose_msi_msg(). Hyper-V's choice of pCPU is not visible to the guest,
1643 * performance bottleneck. So we spread out the dummy vCPUs to influence Hyper-V
1646 * For the single-MSI and MSI-X cases, it's OK for hv_compose_msi_req_get_cpu()
1648 * hv_compose_msi_msg() contains the "real" vCPU, causing Hyper-V to choose a
1649 * new pCPU for the interrupt. But for the multi-MSI case, the second call to
1651 * original dummy vCPU is used. This dummy vCPU must be round-robin'ed so that
1652 * the pCPUs are spread out. All interrupts for a multi-MSI device end up using
1656 * With Hyper-V in Nov 2022, the HVCALL_RETARGET_INTERRUPT hypercall does *not*
1657 * cause Hyper-V to reselect the pCPU based on the specified vCPU. Such an
1659 * dummy vCPU selection won't matter, and interrupts for the same multi-MSI
1664 * Create MSI w/ dummy vCPU set targeting just one vCPU, overwritten
1673 * Make sure the dummy vCPU values for multi-MSI don't all point to vCPU0.
1679 /* -1 means starting with CPU 0 */ in hv_compose_multi_msi_req_get_cpu()
1680 static int cpu_next = -1; in hv_compose_multi_msi_req_get_cpu()
1700 int_pkt->message_type.type = PCI_CREATE_INTERRUPT_MESSAGE2; in hv_compose_msi_req_v2()
1701 int_pkt->wslot.slot = slot; in hv_compose_msi_req_v2()
1702 int_pkt->int_desc.vector = vector; in hv_compose_msi_req_v2()
1703 int_pkt->int_desc.vector_count = vector_count; in hv_compose_msi_req_v2()
1704 int_pkt->int_desc.delivery_mode = DELIVERY_MODE; in hv_compose_msi_req_v2()
1705 int_pkt->int_desc.processor_array[0] = in hv_compose_msi_req_v2()
1707 int_pkt->int_desc.processor_count = 1; in hv_compose_msi_req_v2()
1716 int_pkt->message_type.type = PCI_CREATE_INTERRUPT_MESSAGE3; in hv_compose_msi_req_v3()
1717 int_pkt->wslot.slot = slot; in hv_compose_msi_req_v3()
1718 int_pkt->int_desc.vector = vector; in hv_compose_msi_req_v3()
1719 int_pkt->int_desc.reserved = 0; in hv_compose_msi_req_v3()
1720 int_pkt->int_desc.vector_count = vector_count; in hv_compose_msi_req_v3()
1721 int_pkt->int_desc.delivery_mode = DELIVERY_MODE; in hv_compose_msi_req_v3()
1722 int_pkt->int_desc.processor_array[0] = in hv_compose_msi_req_v3()
1724 int_pkt->int_desc.processor_count = 1; in hv_compose_msi_req_v3()
1730 * hv_compose_msi_msg() - Supplies a valid MSI address/data
1731 * @data: Everything about this MSI
1772 multi_msi = !msi_desc->pci.msi_attrib.is_msix && in hv_compose_msi_msg()
1773 msi_desc->nvec_used > 1; in hv_compose_msi_msg()
1776 if (data->chip_data && multi_msi) { in hv_compose_msi_msg()
1777 int_desc = data->chip_data; in hv_compose_msi_msg()
1778 msg->address_hi = int_desc->address >> 32; in hv_compose_msi_msg()
1779 msg->address_lo = int_desc->address & 0xffffffff; in hv_compose_msi_msg()
1780 msg->data = int_desc->data; in hv_compose_msi_msg()
1786 pbus = pdev->bus; in hv_compose_msi_msg()
1787 hbus = container_of(pbus->sysdata, struct hv_pcibus_device, sysdata); in hv_compose_msi_msg()
1788 channel = hbus->hdev->channel; in hv_compose_msi_msg()
1789 hpdev = get_pcichild_wslot(hbus, devfn_to_wslot(pdev->devfn)); in hv_compose_msi_msg()
1794 if (data->chip_data && !multi_msi) { in hv_compose_msi_msg()
1795 int_desc = data->chip_data; in hv_compose_msi_msg()
1796 data->chip_data = NULL; in hv_compose_msi_msg()
1806 * If this is not the first MSI of Multi MSI, we already have in hv_compose_msi_msg()
1809 if (msi_desc->irq != data->irq) { in hv_compose_msi_msg()
1810 data->chip_data = int_desc; in hv_compose_msi_msg()
1811 int_desc->address = msi_desc->msg.address_lo | in hv_compose_msi_msg()
1812 (u64)msi_desc->msg.address_hi << 32; in hv_compose_msi_msg()
1813 int_desc->data = msi_desc->msg.data + in hv_compose_msi_msg()
1814 (data->irq - msi_desc->irq); in hv_compose_msi_msg()
1815 msg->address_hi = msi_desc->msg.address_hi; in hv_compose_msi_msg()
1816 msg->address_lo = msi_desc->msg.address_lo; in hv_compose_msi_msg()
1817 msg->data = int_desc->data; in hv_compose_msi_msg()
1824 * to be aligned with the count, and also not zero. Multi-msi in hv_compose_msi_msg()
1828 vector_count = msi_desc->nvec_used; in hv_compose_msi_msg()
1846 switch (hbus->protocol_version) { in hv_compose_msi_msg()
1849 hpdev->desc.win_slot.slot, in hv_compose_msi_msg()
1858 hpdev->desc.win_slot.slot, in hv_compose_msi_msg()
1866 hpdev->desc.win_slot.slot, in hv_compose_msi_msg()
1876 dev_err(&hbus->hdev->device, in hv_compose_msi_msg()
1881 ret = vmbus_sendpacket_getid(hpdev->hbus->hdev->channel, &ctxt.int_pkts, in hv_compose_msi_msg()
1886 dev_err(&hbus->hdev->device, in hv_compose_msi_msg()
1896 tasklet_disable_in_atomic(&channel->callback_event); in hv_compose_msi_msg()
1907 dev_err_once(&hbus->hdev->device, in hv_compose_msi_msg()
1919 spin_lock_irqsave(&channel->sched_lock, flags); in hv_compose_msi_msg()
1920 if (unlikely(channel->onchannel_callback == NULL)) { in hv_compose_msi_msg()
1921 spin_unlock_irqrestore(&channel->sched_lock, flags); in hv_compose_msi_msg()
1925 spin_unlock_irqrestore(&channel->sched_lock, flags); in hv_compose_msi_msg()
1927 if (hpdev->state == hv_pcichild_ejecting) { in hv_compose_msi_msg()
1928 dev_err_once(&hbus->hdev->device, in hv_compose_msi_msg()
1936 tasklet_enable(&channel->callback_event); in hv_compose_msi_msg()
1939 dev_err(&hbus->hdev->device, in hv_compose_msi_msg()
1951 data->chip_data = int_desc; in hv_compose_msi_msg()
1954 msg->address_hi = comp.int_desc.address >> 32; in hv_compose_msi_msg()
1955 msg->address_lo = comp.int_desc.address & 0xffffffff; in hv_compose_msi_msg()
1956 msg->data = comp.int_desc.data; in hv_compose_msi_msg()
1962 tasklet_enable(&channel->callback_event); in hv_compose_msi_msg()
1967 * been 're-used', i.e., already removed and (re-)mapped.) in hv_compose_msi_msg()
1977 msg->address_hi = 0; in hv_compose_msi_msg()
1978 msg->address_lo = 0; in hv_compose_msi_msg()
1979 msg->data = 0; in hv_compose_msi_msg()
1984 .name = "Hyper-V PCIe MSI",
2002 * hv_pcie_init_irq_domain() - Initialize IRQ domain
2007 * devices only support MSI and MSI-X, not line-based interrupts
2008 * or simulations of line-based interrupts through PCIe's
2009 * fabric-layer messages. Because interrupts are remapped, we
2010 * can support multi-message MSI here.
2016 hbus->msi_info.chip = &hv_msi_irq_chip; in hv_pcie_init_irq_domain()
2017 hbus->msi_info.ops = &hv_msi_ops; in hv_pcie_init_irq_domain()
2018 hbus->msi_info.flags = (MSI_FLAG_USE_DEF_DOM_OPS | in hv_pcie_init_irq_domain()
2021 hbus->msi_info.handler = FLOW_HANDLER; in hv_pcie_init_irq_domain()
2022 hbus->msi_info.handler_name = FLOW_NAME; in hv_pcie_init_irq_domain()
2023 hbus->msi_info.data = hbus; in hv_pcie_init_irq_domain()
2024 hbus->irq_domain = pci_msi_create_irq_domain(hbus->fwnode, in hv_pcie_init_irq_domain()
2025 &hbus->msi_info, in hv_pcie_init_irq_domain()
2027 if (!hbus->irq_domain) { in hv_pcie_init_irq_domain()
2028 dev_err(&hbus->hdev->device, in hv_pcie_init_irq_domain()
2029 "Failed to build an MSI IRQ domain\n"); in hv_pcie_init_irq_domain()
2030 return -ENODEV; in hv_pcie_init_irq_domain()
2033 dev_set_msi_domain(&hbus->bridge->dev, hbus->irq_domain); in hv_pcie_init_irq_domain()
2039 * get_bar_size() - Get the address space consumed by a BAR
2040 * @bar_val: Value that a BAR returned after -1 was written
2059 * survey_child_resources() - Total all MMIO requirements
2072 event = xchg(&hbus->survey_event, NULL); in survey_child_resources()
2077 if (hbus->low_mmio_space || hbus->high_mmio_space) { in survey_child_resources()
2082 spin_lock_irqsave(&hbus->device_list_lock, flags); in survey_child_resources()
2089 list_for_each_entry(hpdev, &hbus->children, list_entry) { in survey_child_resources()
2091 if (hpdev->probed_bar[i] & PCI_BASE_ADDRESS_SPACE_IO) in survey_child_resources()
2092 dev_err(&hbus->hdev->device, in survey_child_resources()
2095 if (hpdev->probed_bar[i] != 0) { in survey_child_resources()
2101 bar_val = hpdev->probed_bar[i]; in survey_child_resources()
2104 ((u64)hpdev->probed_bar[++i] << 32); in survey_child_resources()
2111 hbus->high_mmio_space += bar_size; in survey_child_resources()
2113 hbus->low_mmio_space += bar_size; in survey_child_resources()
2118 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in survey_child_resources()
2123 * prepopulate_bars() - Fill in BARs with defaults
2131 * the memory-mapped I/O space will be aligned on the largest
2148 if (hbus->low_mmio_space) { in prepopulate_bars()
2149 low_size = 1ULL << (63 - __builtin_clzll(hbus->low_mmio_space)); in prepopulate_bars()
2150 low_base = hbus->low_mmio_res->start; in prepopulate_bars()
2153 if (hbus->high_mmio_space) { in prepopulate_bars()
2155 (63 - __builtin_clzll(hbus->high_mmio_space)); in prepopulate_bars()
2156 high_base = hbus->high_mmio_res->start; in prepopulate_bars()
2159 spin_lock_irqsave(&hbus->device_list_lock, flags); in prepopulate_bars()
2167 * If the memory enable bit is already set, Hyper-V silently ignores in prepopulate_bars()
2172 list_for_each_entry(hpdev, &hbus->children, list_entry) { in prepopulate_bars()
2180 list_for_each_entry(hpdev, &hbus->children, list_entry) { in prepopulate_bars()
2182 bar_val = hpdev->probed_bar[i]; in prepopulate_bars()
2188 ((u64)hpdev->probed_bar[i + 1] in prepopulate_bars()
2222 * to be pre-set. Actually here we intentionally in prepopulate_bars()
2224 * in the core PCI driver doesn't cause Hyper-V in prepopulate_bars()
2238 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in prepopulate_bars()
2247 * same ordered workqueue. Therefore hbus->children list will not change
2256 list_for_each_entry(hpdev, &hbus->children, list_entry) { in hv_pci_assign_slots()
2257 if (hpdev->pci_slot) in hv_pci_assign_slots()
2260 slot_nr = PCI_SLOT(wslot_to_devfn(hpdev->desc.win_slot.slot)); in hv_pci_assign_slots()
2261 snprintf(name, SLOT_NAME_SIZE, "%u", hpdev->desc.ser); in hv_pci_assign_slots()
2262 hpdev->pci_slot = pci_create_slot(hbus->bridge->bus, slot_nr, in hv_pci_assign_slots()
2264 if (IS_ERR(hpdev->pci_slot)) { in hv_pci_assign_slots()
2266 hpdev->pci_slot = NULL; in hv_pci_assign_slots()
2278 list_for_each_entry(hpdev, &hbus->children, list_entry) { in hv_pci_remove_slots()
2279 if (!hpdev->pci_slot) in hv_pci_remove_slots()
2281 pci_destroy_slot(hpdev->pci_slot); in hv_pci_remove_slots()
2282 hpdev->pci_slot = NULL; in hv_pci_remove_slots()
2292 struct pci_bus *bus = hbus->bridge->bus; in hv_pci_assign_numa_node()
2295 list_for_each_entry(dev, &bus->devices, bus_list) { in hv_pci_assign_numa_node()
2296 hv_dev = get_pcichild_wslot(hbus, devfn_to_wslot(dev->devfn)); in hv_pci_assign_numa_node()
2300 if (hv_dev->desc.flags & HV_PCI_DEVICE_FLAG_NUMA_AFFINITY && in hv_pci_assign_numa_node()
2301 hv_dev->desc.virtual_numa_node < num_possible_nodes()) in hv_pci_assign_numa_node()
2308 set_dev_node(&dev->dev, in hv_pci_assign_numa_node()
2310 hv_dev->desc.virtual_numa_node)); in hv_pci_assign_numa_node()
2317 * create_root_hv_pci_bus() - Expose a new root PCI bus
2320 * Return: 0 on success, -errno on failure
2325 struct pci_host_bridge *bridge = hbus->bridge; in create_root_hv_pci_bus()
2327 bridge->dev.parent = &hbus->hdev->device; in create_root_hv_pci_bus()
2328 bridge->sysdata = &hbus->sysdata; in create_root_hv_pci_bus()
2329 bridge->ops = &hv_pcifront_ops; in create_root_hv_pci_bus()
2337 pci_bus_assign_resources(bridge->bus); in create_root_hv_pci_bus()
2339 pci_bus_add_devices(bridge->bus); in create_root_hv_pci_bus()
2341 hbus->state = hv_pcibus_installed; in create_root_hv_pci_bus()
2351 * q_resource_requirements() - Query Resource Requirements
2368 status = (resp_packet_size < sizeof(*q_res_req)) ? -1 : resp->status; in q_resource_requirements()
2370 dev_err(&completion->hpdev->hbus->hdev->device, in q_resource_requirements()
2375 completion->hpdev->probed_bar[i] = in q_resource_requirements()
2376 q_res_req->probed_bar[i]; in q_resource_requirements()
2380 complete(&completion->host_event); in q_resource_requirements()
2384 * new_pcichild_device() - Create a new child device
2411 hpdev->hbus = hbus; in new_pcichild_device()
2419 res_req->message_type.type = PCI_QUERY_RESOURCE_REQUIREMENTS; in new_pcichild_device()
2420 res_req->wslot.slot = desc->win_slot.slot; in new_pcichild_device()
2422 ret = vmbus_sendpacket(hbus->hdev->channel, res_req, in new_pcichild_device()
2430 if (wait_for_response(hbus->hdev, &comp_pkt.host_event)) in new_pcichild_device()
2433 hpdev->desc = *desc; in new_pcichild_device()
2434 refcount_set(&hpdev->refs, 1); in new_pcichild_device()
2436 spin_lock_irqsave(&hbus->device_list_lock, flags); in new_pcichild_device()
2438 list_add_tail(&hpdev->list_entry, &hbus->children); in new_pcichild_device()
2439 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in new_pcichild_device()
2448 * get_pcichild_wslot() - Find device from slot
2466 spin_lock_irqsave(&hbus->device_list_lock, flags); in get_pcichild_wslot()
2467 list_for_each_entry(iter, &hbus->children, list_entry) { in get_pcichild_wslot()
2468 if (iter->desc.win_slot.slot == wslot) { in get_pcichild_wslot()
2474 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in get_pcichild_wslot()
2480 * pci_devices_present_work() - Handle new list of child devices
2485 * debug the interaction between Hyper-V and Linux. This
2500 * because both are pushed to the ordered workqueue hbus->wq.
2515 hbus = dr_wrk->bus; in pci_devices_present_work()
2521 spin_lock_irqsave(&hbus->device_list_lock, flags); in pci_devices_present_work()
2522 while (!list_empty(&hbus->dr_list)) { in pci_devices_present_work()
2523 dr = list_first_entry(&hbus->dr_list, struct hv_dr_state, in pci_devices_present_work()
2525 list_del(&dr->list_entry); in pci_devices_present_work()
2528 if (!list_empty(&hbus->dr_list)) { in pci_devices_present_work()
2533 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in pci_devices_present_work()
2539 spin_lock_irqsave(&hbus->device_list_lock, flags); in pci_devices_present_work()
2540 list_for_each_entry(hpdev, &hbus->children, list_entry) { in pci_devices_present_work()
2541 hpdev->reported_missing = true; in pci_devices_present_work()
2543 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in pci_devices_present_work()
2546 for (child_no = 0; child_no < dr->device_count; child_no++) { in pci_devices_present_work()
2548 new_desc = &dr->func[child_no]; in pci_devices_present_work()
2550 spin_lock_irqsave(&hbus->device_list_lock, flags); in pci_devices_present_work()
2551 list_for_each_entry(hpdev, &hbus->children, list_entry) { in pci_devices_present_work()
2552 if ((hpdev->desc.win_slot.slot == new_desc->win_slot.slot) && in pci_devices_present_work()
2553 (hpdev->desc.v_id == new_desc->v_id) && in pci_devices_present_work()
2554 (hpdev->desc.d_id == new_desc->d_id) && in pci_devices_present_work()
2555 (hpdev->desc.ser == new_desc->ser)) { in pci_devices_present_work()
2556 hpdev->reported_missing = false; in pci_devices_present_work()
2560 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in pci_devices_present_work()
2565 dev_err(&hbus->hdev->device, in pci_devices_present_work()
2571 spin_lock_irqsave(&hbus->device_list_lock, flags); in pci_devices_present_work()
2574 list_for_each_entry(hpdev, &hbus->children, list_entry) { in pci_devices_present_work()
2575 if (hpdev->reported_missing) { in pci_devices_present_work()
2578 list_move_tail(&hpdev->list_entry, &removed); in pci_devices_present_work()
2583 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in pci_devices_present_work()
2589 list_del(&hpdev->list_entry); in pci_devices_present_work()
2591 if (hpdev->pci_slot) in pci_devices_present_work()
2592 pci_destroy_slot(hpdev->pci_slot); in pci_devices_present_work()
2597 switch (hbus->state) { in pci_devices_present_work()
2604 pci_scan_child_bus(hbus->bridge->bus); in pci_devices_present_work()
2623 * hv_pci_start_relations_work() - Queue work to start device discovery
2627 * Return: 0 on success, -errno on failure
2636 if (hbus->state == hv_pcibus_removing) { in hv_pci_start_relations_work()
2637 dev_info(&hbus->hdev->device, in hv_pci_start_relations_work()
2639 return -ENOENT; in hv_pci_start_relations_work()
2644 return -ENOMEM; in hv_pci_start_relations_work()
2646 INIT_WORK(&dr_wrk->wrk, pci_devices_present_work); in hv_pci_start_relations_work()
2647 dr_wrk->bus = hbus; in hv_pci_start_relations_work()
2649 spin_lock_irqsave(&hbus->device_list_lock, flags); in hv_pci_start_relations_work()
2655 pending_dr = !list_empty(&hbus->dr_list); in hv_pci_start_relations_work()
2656 list_add_tail(&dr->list_entry, &hbus->dr_list); in hv_pci_start_relations_work()
2657 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in hv_pci_start_relations_work()
2662 queue_work(hbus->wq, &dr_wrk->wrk); in hv_pci_start_relations_work()
2668 * hv_pci_devices_present() - Handle list of new children
2682 dr = kzalloc(struct_size(dr, func, relations->device_count), in hv_pci_devices_present()
2687 dr->device_count = relations->device_count; in hv_pci_devices_present()
2688 for (i = 0; i < dr->device_count; i++) { in hv_pci_devices_present()
2689 dr->func[i].v_id = relations->func[i].v_id; in hv_pci_devices_present()
2690 dr->func[i].d_id = relations->func[i].d_id; in hv_pci_devices_present()
2691 dr->func[i].rev = relations->func[i].rev; in hv_pci_devices_present()
2692 dr->func[i].prog_intf = relations->func[i].prog_intf; in hv_pci_devices_present()
2693 dr->func[i].subclass = relations->func[i].subclass; in hv_pci_devices_present()
2694 dr->func[i].base_class = relations->func[i].base_class; in hv_pci_devices_present()
2695 dr->func[i].subsystem_id = relations->func[i].subsystem_id; in hv_pci_devices_present()
2696 dr->func[i].win_slot = relations->func[i].win_slot; in hv_pci_devices_present()
2697 dr->func[i].ser = relations->func[i].ser; in hv_pci_devices_present()
2705 * hv_pci_devices_present2() - Handle list of new children
2717 dr = kzalloc(struct_size(dr, func, relations->device_count), in hv_pci_devices_present2()
2722 dr->device_count = relations->device_count; in hv_pci_devices_present2()
2723 for (i = 0; i < dr->device_count; i++) { in hv_pci_devices_present2()
2724 dr->func[i].v_id = relations->func[i].v_id; in hv_pci_devices_present2()
2725 dr->func[i].d_id = relations->func[i].d_id; in hv_pci_devices_present2()
2726 dr->func[i].rev = relations->func[i].rev; in hv_pci_devices_present2()
2727 dr->func[i].prog_intf = relations->func[i].prog_intf; in hv_pci_devices_present2()
2728 dr->func[i].subclass = relations->func[i].subclass; in hv_pci_devices_present2()
2729 dr->func[i].base_class = relations->func[i].base_class; in hv_pci_devices_present2()
2730 dr->func[i].subsystem_id = relations->func[i].subsystem_id; in hv_pci_devices_present2()
2731 dr->func[i].win_slot = relations->func[i].win_slot; in hv_pci_devices_present2()
2732 dr->func[i].ser = relations->func[i].ser; in hv_pci_devices_present2()
2733 dr->func[i].flags = relations->func[i].flags; in hv_pci_devices_present2()
2734 dr->func[i].virtual_numa_node = in hv_pci_devices_present2()
2735 relations->func[i].virtual_numa_node; in hv_pci_devices_present2()
2743 * hv_eject_device_work() - Asynchronously handles ejection
2765 hbus = hpdev->hbus; in hv_eject_device_work()
2767 WARN_ON(hpdev->state != hv_pcichild_ejecting); in hv_eject_device_work()
2772 * must be done without constructs like pci_domain_nr(hbus->bridge->bus) in hv_eject_device_work()
2773 * because hbus->bridge->bus may not exist yet. in hv_eject_device_work()
2775 wslot = wslot_to_devfn(hpdev->desc.win_slot.slot); in hv_eject_device_work()
2776 pdev = pci_get_domain_bus_and_slot(hbus->bridge->domain_nr, 0, wslot); in hv_eject_device_work()
2784 spin_lock_irqsave(&hbus->device_list_lock, flags); in hv_eject_device_work()
2785 list_del(&hpdev->list_entry); in hv_eject_device_work()
2786 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in hv_eject_device_work()
2788 if (hpdev->pci_slot) in hv_eject_device_work()
2789 pci_destroy_slot(hpdev->pci_slot); in hv_eject_device_work()
2793 ejct_pkt->message_type.type = PCI_EJECTION_COMPLETE; in hv_eject_device_work()
2794 ejct_pkt->wslot.slot = hpdev->desc.win_slot.slot; in hv_eject_device_work()
2795 vmbus_sendpacket(hbus->hdev->channel, ejct_pkt, in hv_eject_device_work()
2808 * hv_pci_eject_device() - Handles device ejection
2812 * just schedules work so that we don't re-enter the packet
2817 struct hv_pcibus_device *hbus = hpdev->hbus; in hv_pci_eject_device()
2818 struct hv_device *hdev = hbus->hdev; in hv_pci_eject_device()
2820 if (hbus->state == hv_pcibus_removing) { in hv_pci_eject_device()
2821 dev_info(&hdev->device, "PCI VMBus EJECT: ignored\n"); in hv_pci_eject_device()
2825 hpdev->state = hv_pcichild_ejecting; in hv_pci_eject_device()
2827 INIT_WORK(&hpdev->wrk, hv_eject_device_work); in hv_pci_eject_device()
2828 queue_work(hbus->wq, &hpdev->wrk); in hv_pci_eject_device()
2832 * hv_pci_onchannelcallback() - Handles incoming packets
2843 struct vmbus_channel *chan = hbus->hdev->channel; in hv_pci_onchannelcallback()
2867 if (ret == -ENOBUFS) { in hv_pci_onchannelcallback()
2889 switch (desc->type) { in hv_pci_onchannelcallback()
2897 dev_err(&hbus->hdev->device, in hv_pci_onchannelcallback()
2905 * Call ->completion_func() within the critical section to make in hv_pci_onchannelcallback()
2911 comp_packet->completion_func(comp_packet->compl_ctxt, in hv_pci_onchannelcallback()
2920 switch (new_message->message_type.type) { in hv_pci_onchannelcallback()
2927 bus_rel->device_count)) { in hv_pci_onchannelcallback()
2928 dev_err(&hbus->hdev->device, in hv_pci_onchannelcallback()
2942 bus_rel2->device_count)) { in hv_pci_onchannelcallback()
2943 dev_err(&hbus->hdev->device, in hv_pci_onchannelcallback()
2955 dev_err(&hbus->hdev->device, in hv_pci_onchannelcallback()
2960 dev_message->wslot.slot); in hv_pci_onchannelcallback()
2971 dev_err(&hbus->hdev->device, in hv_pci_onchannelcallback()
2976 inval->wslot.slot); in hv_pci_onchannelcallback()
2978 if (hpdev->block_invalidate) { in hv_pci_onchannelcallback()
2979 hpdev->block_invalidate( in hv_pci_onchannelcallback()
2980 hpdev->invalidate_context, in hv_pci_onchannelcallback()
2981 inval->block_mask); in hv_pci_onchannelcallback()
2988 dev_warn(&hbus->hdev->device, in hv_pci_onchannelcallback()
2990 new_message->message_type.type); in hv_pci_onchannelcallback()
2996 dev_err(&hbus->hdev->device, in hv_pci_onchannelcallback()
2998 desc->type, req_id, bytes_recvd); in hv_pci_onchannelcallback()
3007 * hv_pci_protocol_negotiation() - Set up protocol
3010 * the order of probing - highest go first.
3044 return -ENOMEM; in hv_pci_protocol_negotiation()
3047 pkt->completion_func = hv_pci_generic_compl; in hv_pci_protocol_negotiation()
3048 pkt->compl_ctxt = &comp_pkt; in hv_pci_protocol_negotiation()
3049 version_req = (struct pci_version_request *)&pkt->message; in hv_pci_protocol_negotiation()
3050 version_req->message_type.type = PCI_QUERY_PROTOCOL_VERSION; in hv_pci_protocol_negotiation()
3053 version_req->protocol_version = version[i]; in hv_pci_protocol_negotiation()
3054 ret = vmbus_sendpacket(hdev->channel, version_req, in hv_pci_protocol_negotiation()
3062 dev_err(&hdev->device, in hv_pci_protocol_negotiation()
3063 "PCI Pass-through VSP failed to request version: %d", in hv_pci_protocol_negotiation()
3069 hbus->protocol_version = version[i]; in hv_pci_protocol_negotiation()
3070 dev_info(&hdev->device, in hv_pci_protocol_negotiation()
3072 hbus->protocol_version); in hv_pci_protocol_negotiation()
3077 dev_err(&hdev->device, in hv_pci_protocol_negotiation()
3078 "PCI Pass-through VSP failed version request: %#x", in hv_pci_protocol_negotiation()
3080 ret = -EPROTO; in hv_pci_protocol_negotiation()
3087 dev_err(&hdev->device, in hv_pci_protocol_negotiation()
3088 "PCI pass-through VSP failed to find supported version"); in hv_pci_protocol_negotiation()
3089 ret = -EPROTO; in hv_pci_protocol_negotiation()
3097 * hv_pci_free_bridge_windows() - Release memory regions for the
3108 if (hbus->low_mmio_space && hbus->low_mmio_res) { in hv_pci_free_bridge_windows()
3109 hbus->low_mmio_res->flags |= IORESOURCE_BUSY; in hv_pci_free_bridge_windows()
3110 vmbus_free_mmio(hbus->low_mmio_res->start, in hv_pci_free_bridge_windows()
3111 resource_size(hbus->low_mmio_res)); in hv_pci_free_bridge_windows()
3114 if (hbus->high_mmio_space && hbus->high_mmio_res) { in hv_pci_free_bridge_windows()
3115 hbus->high_mmio_res->flags |= IORESOURCE_BUSY; in hv_pci_free_bridge_windows()
3116 vmbus_free_mmio(hbus->high_mmio_res->start, in hv_pci_free_bridge_windows()
3117 resource_size(hbus->high_mmio_res)); in hv_pci_free_bridge_windows()
3122 * hv_pci_allocate_bridge_windows() - Allocate memory regions
3144 * Return: 0 on success, -errno on failure
3151 if (hbus->low_mmio_space) { in hv_pci_allocate_bridge_windows()
3152 align = 1ULL << (63 - __builtin_clzll(hbus->low_mmio_space)); in hv_pci_allocate_bridge_windows()
3153 ret = vmbus_allocate_mmio(&hbus->low_mmio_res, hbus->hdev, 0, in hv_pci_allocate_bridge_windows()
3155 hbus->low_mmio_space, in hv_pci_allocate_bridge_windows()
3158 dev_err(&hbus->hdev->device, in hv_pci_allocate_bridge_windows()
3160 hbus->low_mmio_space); in hv_pci_allocate_bridge_windows()
3165 hbus->low_mmio_res->flags |= IORESOURCE_WINDOW; in hv_pci_allocate_bridge_windows()
3166 hbus->low_mmio_res->flags &= ~IORESOURCE_BUSY; in hv_pci_allocate_bridge_windows()
3167 pci_add_resource(&hbus->bridge->windows, hbus->low_mmio_res); in hv_pci_allocate_bridge_windows()
3170 if (hbus->high_mmio_space) { in hv_pci_allocate_bridge_windows()
3171 align = 1ULL << (63 - __builtin_clzll(hbus->high_mmio_space)); in hv_pci_allocate_bridge_windows()
3172 ret = vmbus_allocate_mmio(&hbus->high_mmio_res, hbus->hdev, in hv_pci_allocate_bridge_windows()
3173 0x100000000, -1, in hv_pci_allocate_bridge_windows()
3174 hbus->high_mmio_space, align, in hv_pci_allocate_bridge_windows()
3177 dev_err(&hbus->hdev->device, in hv_pci_allocate_bridge_windows()
3179 hbus->high_mmio_space); in hv_pci_allocate_bridge_windows()
3184 hbus->high_mmio_res->flags |= IORESOURCE_WINDOW; in hv_pci_allocate_bridge_windows()
3185 hbus->high_mmio_res->flags &= ~IORESOURCE_BUSY; in hv_pci_allocate_bridge_windows()
3186 pci_add_resource(&hbus->bridge->windows, hbus->high_mmio_res); in hv_pci_allocate_bridge_windows()
3192 if (hbus->low_mmio_res) { in hv_pci_allocate_bridge_windows()
3193 vmbus_free_mmio(hbus->low_mmio_res->start, in hv_pci_allocate_bridge_windows()
3194 resource_size(hbus->low_mmio_res)); in hv_pci_allocate_bridge_windows()
3201 * hv_allocate_config_window() - Find MMIO space for PCI Config
3204 * This function claims memory-mapped I/O space for accessing
3207 * Return: 0 on success, -errno on failure
3217 ret = vmbus_allocate_mmio(&hbus->mem_config, hbus->hdev, 0, -1, in hv_allocate_config_window()
3230 hbus->mem_config->flags |= IORESOURCE_BUSY; in hv_allocate_config_window()
3237 vmbus_free_mmio(hbus->mem_config->start, PCI_CONFIG_MMIO_LENGTH); in hv_free_config_window()
3243 * hv_pci_enter_d0() - Bring the "bus" into the D0 power state
3246 * Return: 0 on success, -errno on failure
3258 * powered-on state. This includes telling the host which region in hv_pci_enter_d0()
3259 * of memory-mapped I/O space has been chosen for configuration space in hv_pci_enter_d0()
3264 return -ENOMEM; in hv_pci_enter_d0()
3267 pkt->completion_func = hv_pci_generic_compl; in hv_pci_enter_d0()
3268 pkt->compl_ctxt = &comp_pkt; in hv_pci_enter_d0()
3269 d0_entry = (struct pci_bus_d0_entry *)&pkt->message; in hv_pci_enter_d0()
3270 d0_entry->message_type.type = PCI_BUS_D0ENTRY; in hv_pci_enter_d0()
3271 d0_entry->mmio_base = hbus->mem_config->start; in hv_pci_enter_d0()
3273 ret = vmbus_sendpacket(hdev->channel, d0_entry, sizeof(*d0_entry), in hv_pci_enter_d0()
3283 dev_err(&hdev->device, in hv_pci_enter_d0()
3284 "PCI Pass-through VSP failed D0 Entry with status %x\n", in hv_pci_enter_d0()
3286 ret = -EPROTO; in hv_pci_enter_d0()
3298 * hv_pci_query_relations() - Ask host to send list of child
3302 * Return: 0 on success, -errno on failure
3313 if (cmpxchg(&hbus->survey_event, NULL, &comp)) in hv_pci_query_relations()
3314 return -ENOTEMPTY; in hv_pci_query_relations()
3319 ret = vmbus_sendpacket(hdev->channel, &message, sizeof(message), in hv_pci_query_relations()
3328 * hv_send_resources_allocated() - Report local resource choices
3342 * Return: 0 on success, -errno on failure
3356 size_res = (hbus->protocol_version < PCI_PROTOCOL_VERSION_1_2) in hv_send_resources_allocated()
3361 return -ENOMEM; in hv_send_resources_allocated()
3372 pkt->completion_func = hv_pci_generic_compl; in hv_send_resources_allocated()
3373 pkt->compl_ctxt = &comp_pkt; in hv_send_resources_allocated()
3375 if (hbus->protocol_version < PCI_PROTOCOL_VERSION_1_2) { in hv_send_resources_allocated()
3377 (struct pci_resources_assigned *)&pkt->message; in hv_send_resources_allocated()
3378 res_assigned->message_type.type = in hv_send_resources_allocated()
3380 res_assigned->wslot.slot = hpdev->desc.win_slot.slot; in hv_send_resources_allocated()
3383 (struct pci_resources_assigned2 *)&pkt->message; in hv_send_resources_allocated()
3384 res_assigned2->message_type.type = in hv_send_resources_allocated()
3386 res_assigned2->wslot.slot = hpdev->desc.win_slot.slot; in hv_send_resources_allocated()
3390 ret = vmbus_sendpacket(hdev->channel, &pkt->message, in hv_send_resources_allocated()
3400 ret = -EPROTO; in hv_send_resources_allocated()
3401 dev_err(&hdev->device, in hv_send_resources_allocated()
3407 hbus->wslot_res_allocated = wslot; in hv_send_resources_allocated()
3415 * hv_send_resources_released() - Report local resources
3419 * Return: 0 on success, -errno on failure
3429 for (wslot = hbus->wslot_res_allocated; wslot >= 0; wslot--) { in hv_send_resources_released()
3436 pkt.wslot.slot = hpdev->desc.win_slot.slot; in hv_send_resources_released()
3440 ret = vmbus_sendpacket(hdev->channel, &pkt, sizeof(pkt), 0, in hv_send_resources_released()
3445 hbus->wslot_res_allocated = wslot - 1; in hv_send_resources_released()
3448 hbus->wslot_res_allocated = -1; in hv_send_resources_released()
3463 * hv_get_dom_num() - Get a valid PCI domain number
3487 * hv_put_dom_num() - Mark the PCI domain number as free
3496 * hv_pci_probe() - New VMBus channel probe, for a root PCI bus
3500 * Return: 0 on success, -errno on failure
3518 bridge = devm_pci_alloc_host_bridge(&hdev->device, 0); in hv_pci_probe()
3520 return -ENOMEM; in hv_pci_probe()
3524 * alignment for kmalloc(power-of-two)"), kzalloc() is able to allocate in hv_pci_probe()
3525 * a 4KB buffer that is guaranteed to be 4KB-aligned. Here the size and in hv_pci_probe()
3533 * is tracked by hbus->children) as memory leak (false positive). in hv_pci_probe()
3542 return -ENOMEM; in hv_pci_probe()
3544 hbus->bridge = bridge; in hv_pci_probe()
3545 hbus->state = hv_pcibus_init; in hv_pci_probe()
3546 hbus->wslot_res_allocated = -1; in hv_pci_probe()
3554 * Note that, since this code only runs in a Hyper-V VM, Hyper-V in hv_pci_probe()
3561 dom_req = hdev->dev_instance.b[5] << 8 | hdev->dev_instance.b[4]; in hv_pci_probe()
3565 dev_err(&hdev->device, in hv_pci_probe()
3567 ret = -EINVAL; in hv_pci_probe()
3572 dev_info(&hdev->device, in hv_pci_probe()
3576 hbus->bridge->domain_nr = dom; in hv_pci_probe()
3578 hbus->sysdata.domain = dom; in hv_pci_probe()
3587 hbus->sysdata.parent = hdev->device.parent; in hv_pci_probe()
3590 hbus->hdev = hdev; in hv_pci_probe()
3591 INIT_LIST_HEAD(&hbus->children); in hv_pci_probe()
3592 INIT_LIST_HEAD(&hbus->dr_list); in hv_pci_probe()
3593 spin_lock_init(&hbus->config_lock); in hv_pci_probe()
3594 spin_lock_init(&hbus->device_list_lock); in hv_pci_probe()
3595 spin_lock_init(&hbus->retarget_msi_interrupt_lock); in hv_pci_probe()
3596 hbus->wq = alloc_ordered_workqueue("hv_pci_%x", 0, in hv_pci_probe()
3597 hbus->bridge->domain_nr); in hv_pci_probe()
3598 if (!hbus->wq) { in hv_pci_probe()
3599 ret = -ENOMEM; in hv_pci_probe()
3603 hdev->channel->next_request_id_callback = vmbus_next_request_id; in hv_pci_probe()
3604 hdev->channel->request_addr_callback = vmbus_request_addr; in hv_pci_probe()
3605 hdev->channel->rqstor_size = HV_PCI_RQSTOR_SIZE; in hv_pci_probe()
3607 ret = vmbus_open(hdev->channel, pci_ring_size, pci_ring_size, NULL, 0, in hv_pci_probe()
3623 hbus->cfg_addr = ioremap(hbus->mem_config->start, in hv_pci_probe()
3625 if (!hbus->cfg_addr) { in hv_pci_probe()
3626 dev_err(&hdev->device, in hv_pci_probe()
3628 ret = -ENOMEM; in hv_pci_probe()
3632 name = kasprintf(GFP_KERNEL, "%pUL", &hdev->dev_instance); in hv_pci_probe()
3634 ret = -ENOMEM; in hv_pci_probe()
3638 hbus->fwnode = irq_domain_alloc_named_fwnode(name); in hv_pci_probe()
3640 if (!hbus->fwnode) { in hv_pci_probe()
3641 ret = -ENOMEM; in hv_pci_probe()
3668 if (ret == -EPROTO && enter_d0_retry) { in hv_pci_probe()
3671 dev_err(&hdev->device, "Retrying D0 Entry\n"); in hv_pci_probe()
3681 hbus->wslot_res_allocated = 255; in hv_pci_probe()
3687 dev_err(&hdev->device, in hv_pci_probe()
3703 hbus->state = hv_pcibus_probed; in hv_pci_probe()
3716 irq_domain_remove(hbus->irq_domain); in hv_pci_probe()
3718 irq_domain_free_fwnode(hbus->fwnode); in hv_pci_probe()
3720 iounmap(hbus->cfg_addr); in hv_pci_probe()
3724 vmbus_close(hdev->channel); in hv_pci_probe()
3726 destroy_workqueue(hbus->wq); in hv_pci_probe()
3728 hv_put_dom_num(hbus->bridge->domain_nr); in hv_pci_probe()
3737 struct vmbus_channel *chan = hdev->channel; in hv_pci_bus_exit()
3750 * access the per-channel ringbuffer any longer. in hv_pci_bus_exit()
3752 if (chan->rescind) in hv_pci_bus_exit()
3760 spin_lock_irqsave(&hbus->device_list_lock, flags); in hv_pci_bus_exit()
3761 list_for_each_entry_safe(hpdev, tmp, &hbus->children, list_entry) in hv_pci_bus_exit()
3762 list_move_tail(&hpdev->list_entry, &removed); in hv_pci_bus_exit()
3763 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in hv_pci_bus_exit()
3767 list_del(&hpdev->list_entry); in hv_pci_bus_exit()
3768 if (hpdev->pci_slot) in hv_pci_bus_exit()
3769 pci_destroy_slot(hpdev->pci_slot); in hv_pci_bus_exit()
3778 dev_err(&hdev->device, in hv_pci_bus_exit()
3807 return -ETIMEDOUT; in hv_pci_bus_exit()
3814 * hv_pci_remove() - Remove routine for this VMBus channel
3817 * Return: 0 on success, -errno on failure
3825 if (hbus->state == hv_pcibus_installed) { in hv_pci_remove()
3826 tasklet_disable(&hdev->channel->callback_event); in hv_pci_remove()
3827 hbus->state = hv_pcibus_removing; in hv_pci_remove()
3828 tasklet_enable(&hdev->channel->callback_event); in hv_pci_remove()
3829 destroy_workqueue(hbus->wq); in hv_pci_remove()
3830 hbus->wq = NULL; in hv_pci_remove()
3833 * on hbus-wq. We can't race with hv_pci_devices_present() in hv_pci_remove()
3839 pci_stop_root_bus(hbus->bridge->bus); in hv_pci_remove()
3841 pci_remove_root_bus(hbus->bridge->bus); in hv_pci_remove()
3847 vmbus_close(hdev->channel); in hv_pci_remove()
3849 iounmap(hbus->cfg_addr); in hv_pci_remove()
3852 irq_domain_remove(hbus->irq_domain); in hv_pci_remove()
3853 irq_domain_free_fwnode(hbus->fwnode); in hv_pci_remove()
3855 hv_put_dom_num(hbus->bridge->domain_nr); in hv_pci_remove()
3873 * items onto hbus->wq in hv_pci_devices_present() and in hv_pci_suspend()
3876 * the work item handler pci_devices_present_work() -> in hv_pci_suspend()
3880 * callback tasklet, sets hbus->state to hv_pcibus_removing, and in hv_pci_suspend()
3881 * re-enables the tasklet. This way, when hv_pci_suspend() proceeds, in hv_pci_suspend()
3883 * hbus->wq and safely closes the vmbus channel. in hv_pci_suspend()
3885 tasklet_disable(&hdev->channel->callback_event); in hv_pci_suspend()
3888 old_state = hbus->state; in hv_pci_suspend()
3889 if (hbus->state == hv_pcibus_installed) in hv_pci_suspend()
3890 hbus->state = hv_pcibus_removing; in hv_pci_suspend()
3892 tasklet_enable(&hdev->channel->callback_event); in hv_pci_suspend()
3895 return -EINVAL; in hv_pci_suspend()
3897 flush_workqueue(hbus->wq); in hv_pci_suspend()
3903 vmbus_close(hdev->channel); in hv_pci_suspend()
3914 msi_lock_descs(&pdev->dev); in hv_pci_restore_msi_msg()
3915 msi_for_each_desc(entry, &pdev->dev, MSI_DESC_ASSOCIATED) { in hv_pci_restore_msi_msg()
3916 irq_data = irq_get_irq_data(entry->irq); in hv_pci_restore_msi_msg()
3918 ret = -EINVAL; in hv_pci_restore_msi_msg()
3922 hv_compose_msi_msg(irq_data, &entry->msg); in hv_pci_restore_msi_msg()
3924 msi_unlock_descs(&pdev->dev); in hv_pci_restore_msi_msg()
3930 * Upon resume, pci_restore_msi_state() -> ... -> __pci_write_msi_msg()
3931 * directly writes the MSI/MSI-X registers via MMIO, but since Hyper-V
3933 * must be used to ask Hyper-V to re-create the IOMMU Interrupt Remapping
3938 pci_walk_bus(hbus->bridge->bus, hv_pci_restore_msi_msg, NULL); in hv_pci_restore_msi_state()
3947 hbus->state = hv_pcibus_init; in hv_pci_resume()
3949 hdev->channel->next_request_id_callback = vmbus_next_request_id; in hv_pci_resume()
3950 hdev->channel->request_addr_callback = vmbus_request_addr; in hv_pci_resume()
3951 hdev->channel->rqstor_size = HV_PCI_RQSTOR_SIZE; in hv_pci_resume()
3953 ret = vmbus_open(hdev->channel, pci_ring_size, pci_ring_size, NULL, 0, in hv_pci_resume()
3959 version[0] = hbus->protocol_version; in hv_pci_resume()
3980 hbus->state = hv_pcibus_installed; in hv_pci_resume()
3983 vmbus_close(hdev->channel); in hv_pci_resume()
3988 /* PCI Pass-through Class ID */
3989 /* 44C4F61D-4444-4400-9D52-802E27EDE19F */
4019 return -ENODEV; in init_hv_pci_drv()
4039 MODULE_DESCRIPTION("Hyper-V PCI");