Lines Matching +full:ecam +full:- +full:based

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>
71 #define CPU_AFFINITY_ALL -1ULL
74 * Supported protocol versions in the order of probing - highest go
86 #define CFG_PAGE_SIZE (PCI_CONFIG_MMIO_LENGTH - CFG_PAGE_OFFSET)
146 * Function numbers are 8-bits wide on Express, as interpreted through ARI,
149 * the Hyper-V parent partition.
202 * occupied by this Message-Signaled
205 * 32. For "MSI-X," as first defined in PCI
206 * 3.0, this must be 1, as each MSI-X table
220 * struct hv_msi_desc2 - 1.2 version of hv_msi_desc
226 * occupied by this Message-Signaled
229 * 32. For "MSI-X," as first defined in PCI
230 * 3.0, this must be 1, as each MSI-X table
244 * struct hv_msi_desc3 - 1.3 version of hv_msi_desc
264 * a message-signaled interrupt, either MSI
265 * or MSI-X.
587 * hv_pci_generic_compl() - Invoked for a completion packet
602 comp_pkt->completion_status = resp->status; in hv_pci_generic_compl()
604 comp_pkt->completion_status = -1; in hv_pci_generic_compl()
606 complete(&comp_pkt->host_event); in hv_pci_generic_compl()
614 refcount_inc(&hpdev->refs); in get_pcichild()
619 if (refcount_dec_and_test(&hpdev->refs)) in put_pcichild()
631 if (hdev->channel->rescind) { in wait_for_response()
632 dev_warn_once(&hdev->device, "The device is gone.\n"); in wait_for_response()
633 return -ENODEV; in wait_for_response()
644 * devfn_to_wslot() - Convert from Linux PCI slot to Windows
663 * wslot_to_devfn() - Convert from Windows PCI slot to Linux
680 * of pages in memory-mapped I/O space. Writing to the first page chooses
687 * _hv_pcifront_read_config() - Internal PCI config read
697 void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + where; in _hv_pcifront_read_config()
703 memcpy(val, ((u8 *)&hpdev->desc.v_id) + where, size); in _hv_pcifront_read_config()
706 memcpy(val, ((u8 *)&hpdev->desc.rev) + where - in _hv_pcifront_read_config()
710 memcpy(val, (u8 *)&hpdev->desc.subsystem_id + where - in _hv_pcifront_read_config()
719 * Interrupt Line and Interrupt PIN are hard-wired to zero in _hv_pcifront_read_config()
720 * because this front-end only supports message-signaled in _hv_pcifront_read_config()
725 spin_lock_irqsave(&hpdev->hbus->config_lock, flags); in _hv_pcifront_read_config()
727 writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr); in _hv_pcifront_read_config()
747 spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); in _hv_pcifront_read_config()
749 dev_err(&hpdev->hbus->hdev->device, in _hv_pcifront_read_config()
758 void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + in hv_pcifront_get_vendor_id()
761 spin_lock_irqsave(&hpdev->hbus->config_lock, flags); in hv_pcifront_get_vendor_id()
764 writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr); in hv_pcifront_get_vendor_id()
774 spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); in hv_pcifront_get_vendor_id()
780 * _hv_pcifront_write_config() - Internal PCI config write
790 void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + where; in _hv_pcifront_write_config()
794 /* SSIDs and ROM BARs are read-only */ in _hv_pcifront_write_config()
796 spin_lock_irqsave(&hpdev->hbus->config_lock, flags); in _hv_pcifront_write_config()
798 writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr); in _hv_pcifront_write_config()
818 spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); in _hv_pcifront_write_config()
820 dev_err(&hpdev->hbus->hdev->device, in _hv_pcifront_write_config()
826 * hv_pcifront_read_config() - Read configuration space
840 container_of(bus->sysdata, struct hv_pcibus_device, sysdata); in hv_pcifront_read_config()
854 * hv_pcifront_write_config() - Write configuration space
868 container_of(bus->sysdata, struct hv_pcibus_device, sysdata); in hv_pcifront_write_config()
890 * Hyper-V SR-IOV provides a backchannel mechanism in software for
893 * but instead of doing reads and writes in 32-bit chunks through a very slow
896 * Nearly every SR-IOV device contains just such a communications channel in
920 * hv_pci_read_config_compl() - Invoked when a response packet
936 comp->comp_pkt.completion_status = -1; in hv_pci_read_config_compl()
940 data_len = resp_packet_size - hdr_len; in hv_pci_read_config_compl()
941 if (data_len > 0 && read_resp->status == 0) { in hv_pci_read_config_compl()
942 comp->bytes_returned = min(comp->len, data_len); in hv_pci_read_config_compl()
943 memcpy(comp->buf, read_resp->bytes, comp->bytes_returned); in hv_pci_read_config_compl()
945 comp->bytes_returned = 0; in hv_pci_read_config_compl()
948 comp->comp_pkt.completion_status = read_resp->status; in hv_pci_read_config_compl()
950 complete(&comp->comp_pkt.host_event); in hv_pci_read_config_compl()
954 * hv_read_config_block() - Sends a read config block request to
955 * the back-end driver running in the Hyper-V parent partition.
960 * @bytes_returned: Size which came back from the back-end driver.
962 * Return: 0 on success, -errno on failure
969 container_of(pdev->bus->sysdata, struct hv_pcibus_device, in hv_read_config_block()
980 return -EINVAL; in hv_read_config_block()
990 read_blk->message_type.type = PCI_READ_BLOCK; in hv_read_config_block()
991 read_blk->wslot.slot = devfn_to_wslot(pdev->devfn); in hv_read_config_block()
992 read_blk->block_id = block_id; in hv_read_config_block()
993 read_blk->bytes_requested = len; in hv_read_config_block()
995 ret = vmbus_sendpacket(hbus->hdev->channel, read_blk, in hv_read_config_block()
1002 ret = wait_for_response(hbus->hdev, &comp_pkt.comp_pkt.host_event); in hv_read_config_block()
1008 dev_err(&hbus->hdev->device, in hv_read_config_block()
1012 return -EIO; in hv_read_config_block()
1020 * hv_pci_write_config_compl() - Invoked when a response packet for a write
1031 comp_pkt->completion_status = resp->status; in hv_pci_write_config_compl()
1032 complete(&comp_pkt->host_event); in hv_pci_write_config_compl()
1036 * hv_write_config_block() - Sends a write config block request to the
1037 * back-end driver running in the Hyper-V parent partition.
1043 * Return: 0 on success, -errno on failure
1049 container_of(pdev->bus->sysdata, struct hv_pcibus_device, in hv_write_config_block()
1062 return -EINVAL; in hv_write_config_block()
1070 write_blk->message_type.type = PCI_WRITE_BLOCK; in hv_write_config_block()
1071 write_blk->wslot.slot = devfn_to_wslot(pdev->devfn); in hv_write_config_block()
1072 write_blk->block_id = block_id; in hv_write_config_block()
1073 write_blk->byte_count = len; in hv_write_config_block()
1074 memcpy(write_blk->bytes, buf, len); in hv_write_config_block()
1081 * specified in write_blk->byte_count. in hv_write_config_block()
1085 ret = vmbus_sendpacket(hbus->hdev->channel, write_blk, pkt_size, in hv_write_config_block()
1091 ret = wait_for_response(hbus->hdev, &comp_pkt.host_event); in hv_write_config_block()
1096 dev_err(&hbus->hdev->device, in hv_write_config_block()
1099 return -EIO; in hv_write_config_block()
1106 * hv_register_block_invalidate() - Invoked when a config block invalidation
1107 * arrives from the back-end driver.
1112 * Return: 0 on success, -errno on failure
1119 container_of(pdev->bus->sysdata, struct hv_pcibus_device, in hv_register_block_invalidate()
1123 hpdev = get_pcichild_wslot(hbus, devfn_to_wslot(pdev->devfn)); in hv_register_block_invalidate()
1125 return -ENODEV; in hv_register_block_invalidate()
1127 hpdev->block_invalidate = block_invalidate; in hv_register_block_invalidate()
1128 hpdev->invalidate_context = context; in hv_register_block_invalidate()
1147 int_pkt->message_type.type = in hv_int_desc_free()
1149 int_pkt->wslot.slot = hpdev->desc.win_slot.slot; in hv_int_desc_free()
1150 int_pkt->int_desc = *int_desc; in hv_int_desc_free()
1151 vmbus_sendpacket(hpdev->hbus->hdev->channel, int_pkt, sizeof(*int_pkt), in hv_int_desc_free()
1157 * hv_msi_free() - Free the MSI.
1159 * @info: Extra MSI-related context
1162 * The Hyper-V parent partition and hypervisor are tracking the
1178 hbus = info->data; in hv_msi_free()
1183 irq_data->chip_data = NULL; in hv_msi_free()
1184 hpdev = get_pcichild_wslot(hbus, devfn_to_wslot(pdev->devfn)); in hv_msi_free()
1197 struct irq_data *parent = data->parent_data; in hv_set_affinity()
1199 return parent->chip->irq_set_affinity(parent, dest, force); in hv_set_affinity()
1208 * hv_irq_unmask() - "Unmask" the IRQ by setting its current
1234 pbus = pdev->bus; in hv_irq_unmask()
1235 hbus = container_of(pbus->sysdata, struct hv_pcibus_device, sysdata); in hv_irq_unmask()
1237 spin_lock_irqsave(&hbus->retarget_msi_interrupt_lock, flags); in hv_irq_unmask()
1239 params = &hbus->retarget_msi_interrupt_params; in hv_irq_unmask()
1241 params->partition_id = HV_PARTITION_ID_SELF; in hv_irq_unmask()
1242 params->int_entry.source = HV_INTERRUPT_SOURCE_MSI; in hv_irq_unmask()
1243 hv_set_msi_entry_from_desc(&params->int_entry.msi_entry, msi_desc); in hv_irq_unmask()
1244 params->device_id = (hbus->hdev->dev_instance.b[5] << 24) | in hv_irq_unmask()
1245 (hbus->hdev->dev_instance.b[4] << 16) | in hv_irq_unmask()
1246 (hbus->hdev->dev_instance.b[7] << 8) | in hv_irq_unmask()
1247 (hbus->hdev->dev_instance.b[6] & 0xf8) | in hv_irq_unmask()
1248 PCI_FUNC(pdev->devfn); in hv_irq_unmask()
1249 params->int_target.vector = cfg->vector; in hv_irq_unmask()
1252 * Honoring apic->delivery_mode set to APIC_DELIVERY_MODE_FIXED by in hv_irq_unmask()
1258 if (hbus->protocol_version >= PCI_PROTOCOL_VERSION_1_2) { in hv_irq_unmask()
1266 params->int_target.flags |= in hv_irq_unmask()
1275 nr_bank = cpumask_to_vpset(&params->int_target.vp_set, tmp); in hv_irq_unmask()
1284 * var-sized hypercall, var-size starts after vp_mask (thus in hv_irq_unmask()
1291 params->int_target.vp_mask |= in hv_irq_unmask()
1300 spin_unlock_irqrestore(&hbus->retarget_msi_interrupt_lock, flags); in hv_irq_unmask()
1307 * refer to cpu_disable_common() -> fixup_irqs() -> in hv_irq_unmask()
1308 * irq_migrate_all_off_this_cpu() -> migrate_one_irq(). in hv_irq_unmask()
1313 * into the irqdata data structure in migrate_one_irq() -> in hv_irq_unmask()
1314 * irq_do_set_affinity() -> hv_set_affinity(), so later when the VM in hv_irq_unmask()
1318 if (!hv_result_success(res) && hbus->state != hv_pcibus_removing) in hv_irq_unmask()
1319 dev_err(&hbus->hdev->device, in hv_irq_unmask()
1337 comp_pkt->comp_pkt.completion_status = resp->status; in hv_pci_compose_compl()
1338 comp_pkt->int_desc = int_resp->int_desc; in hv_pci_compose_compl()
1339 complete(&comp_pkt->comp_pkt.host_event); in hv_pci_compose_compl()
1346 int_pkt->message_type.type = PCI_CREATE_INTERRUPT_MESSAGE; in hv_compose_msi_req_v1()
1347 int_pkt->wslot.slot = slot; in hv_compose_msi_req_v1()
1348 int_pkt->int_desc.vector = vector; in hv_compose_msi_req_v1()
1349 int_pkt->int_desc.vector_count = 1; in hv_compose_msi_req_v1()
1350 int_pkt->int_desc.delivery_mode = APIC_DELIVERY_MODE_FIXED; in hv_compose_msi_req_v1()
1356 int_pkt->int_desc.cpu_mask = CPU_AFFINITY_ALL; in hv_compose_msi_req_v1()
1376 int_pkt->message_type.type = PCI_CREATE_INTERRUPT_MESSAGE2; in hv_compose_msi_req_v2()
1377 int_pkt->wslot.slot = slot; in hv_compose_msi_req_v2()
1378 int_pkt->int_desc.vector = vector; in hv_compose_msi_req_v2()
1379 int_pkt->int_desc.vector_count = 1; in hv_compose_msi_req_v2()
1380 int_pkt->int_desc.delivery_mode = APIC_DELIVERY_MODE_FIXED; in hv_compose_msi_req_v2()
1382 int_pkt->int_desc.processor_array[0] = in hv_compose_msi_req_v2()
1384 int_pkt->int_desc.processor_count = 1; in hv_compose_msi_req_v2()
1395 int_pkt->message_type.type = PCI_CREATE_INTERRUPT_MESSAGE3; in hv_compose_msi_req_v3()
1396 int_pkt->wslot.slot = slot; in hv_compose_msi_req_v3()
1397 int_pkt->int_desc.vector = vector; in hv_compose_msi_req_v3()
1398 int_pkt->int_desc.reserved = 0; in hv_compose_msi_req_v3()
1399 int_pkt->int_desc.vector_count = 1; in hv_compose_msi_req_v3()
1400 int_pkt->int_desc.delivery_mode = APIC_DELIVERY_MODE_FIXED; in hv_compose_msi_req_v3()
1402 int_pkt->int_desc.processor_array[0] = in hv_compose_msi_req_v3()
1404 int_pkt->int_desc.processor_count = 1; in hv_compose_msi_req_v3()
1410 * hv_compose_msi_msg() - Supplies a valid MSI address/data
1445 pbus = pdev->bus; in hv_compose_msi_msg()
1446 hbus = container_of(pbus->sysdata, struct hv_pcibus_device, sysdata); in hv_compose_msi_msg()
1447 channel = hbus->hdev->channel; in hv_compose_msi_msg()
1448 hpdev = get_pcichild_wslot(hbus, devfn_to_wslot(pdev->devfn)); in hv_compose_msi_msg()
1453 if (data->chip_data) { in hv_compose_msi_msg()
1454 int_desc = data->chip_data; in hv_compose_msi_msg()
1455 data->chip_data = NULL; in hv_compose_msi_msg()
1468 switch (hbus->protocol_version) { in hv_compose_msi_msg()
1472 hpdev->desc.win_slot.slot, in hv_compose_msi_msg()
1473 cfg->vector); in hv_compose_msi_msg()
1480 hpdev->desc.win_slot.slot, in hv_compose_msi_msg()
1481 cfg->vector); in hv_compose_msi_msg()
1487 hpdev->desc.win_slot.slot, in hv_compose_msi_msg()
1488 cfg->vector); in hv_compose_msi_msg()
1496 dev_err(&hbus->hdev->device, in hv_compose_msi_msg()
1501 ret = vmbus_sendpacket(hpdev->hbus->hdev->channel, &ctxt.int_pkts, in hv_compose_msi_msg()
1506 dev_err(&hbus->hdev->device, in hv_compose_msi_msg()
1516 tasklet_disable_in_atomic(&channel->callback_event); in hv_compose_msi_msg()
1527 dev_err_once(&hbus->hdev->device, in hv_compose_msi_msg()
1539 spin_lock_irqsave(&channel->sched_lock, flags); in hv_compose_msi_msg()
1540 if (unlikely(channel->onchannel_callback == NULL)) { in hv_compose_msi_msg()
1541 spin_unlock_irqrestore(&channel->sched_lock, flags); in hv_compose_msi_msg()
1545 spin_unlock_irqrestore(&channel->sched_lock, flags); in hv_compose_msi_msg()
1547 if (hpdev->state == hv_pcichild_ejecting) { in hv_compose_msi_msg()
1548 dev_err_once(&hbus->hdev->device, in hv_compose_msi_msg()
1556 tasklet_enable(&channel->callback_event); in hv_compose_msi_msg()
1559 dev_err(&hbus->hdev->device, in hv_compose_msi_msg()
1571 data->chip_data = int_desc; in hv_compose_msi_msg()
1574 msg->address_hi = comp.int_desc.address >> 32; in hv_compose_msi_msg()
1575 msg->address_lo = comp.int_desc.address & 0xffffffff; in hv_compose_msi_msg()
1576 msg->data = comp.int_desc.data; in hv_compose_msi_msg()
1582 tasklet_enable(&channel->callback_event); in hv_compose_msi_msg()
1588 msg->address_hi = 0; in hv_compose_msi_msg()
1589 msg->address_lo = 0; in hv_compose_msi_msg()
1590 msg->data = 0; in hv_compose_msi_msg()
1595 .name = "Hyper-V PCIe MSI",
1609 * hv_pcie_init_irq_domain() - Initialize IRQ domain
1614 * devices only support MSI and MSI-X, not line-based interrupts
1615 * or simulations of line-based interrupts through PCIe's
1616 * fabric-layer messages. Because interrupts are remapped, we
1617 * can support multi-message MSI here.
1623 hbus->msi_info.chip = &hv_msi_irq_chip; in hv_pcie_init_irq_domain()
1624 hbus->msi_info.ops = &hv_msi_ops; in hv_pcie_init_irq_domain()
1625 hbus->msi_info.flags = (MSI_FLAG_USE_DEF_DOM_OPS | in hv_pcie_init_irq_domain()
1628 hbus->msi_info.handler = handle_edge_irq; in hv_pcie_init_irq_domain()
1629 hbus->msi_info.handler_name = "edge"; in hv_pcie_init_irq_domain()
1630 hbus->msi_info.data = hbus; in hv_pcie_init_irq_domain()
1631 hbus->irq_domain = pci_msi_create_irq_domain(hbus->fwnode, in hv_pcie_init_irq_domain()
1632 &hbus->msi_info, in hv_pcie_init_irq_domain()
1634 if (!hbus->irq_domain) { in hv_pcie_init_irq_domain()
1635 dev_err(&hbus->hdev->device, in hv_pcie_init_irq_domain()
1637 return -ENODEV; in hv_pcie_init_irq_domain()
1640 dev_set_msi_domain(&hbus->bridge->dev, hbus->irq_domain); in hv_pcie_init_irq_domain()
1646 * get_bar_size() - Get the address space consumed by a BAR
1647 * @bar_val: Value that a BAR returned after -1 was written
1666 * survey_child_resources() - Total all MMIO requirements
1679 event = xchg(&hbus->survey_event, NULL); in survey_child_resources()
1684 if (hbus->low_mmio_space || hbus->high_mmio_space) { in survey_child_resources()
1689 spin_lock_irqsave(&hbus->device_list_lock, flags); in survey_child_resources()
1696 list_for_each_entry(hpdev, &hbus->children, list_entry) { in survey_child_resources()
1698 if (hpdev->probed_bar[i] & PCI_BASE_ADDRESS_SPACE_IO) in survey_child_resources()
1699 dev_err(&hbus->hdev->device, in survey_child_resources()
1702 if (hpdev->probed_bar[i] != 0) { in survey_child_resources()
1708 bar_val = hpdev->probed_bar[i]; in survey_child_resources()
1711 ((u64)hpdev->probed_bar[++i] << 32); in survey_child_resources()
1718 hbus->high_mmio_space += bar_size; in survey_child_resources()
1720 hbus->low_mmio_space += bar_size; in survey_child_resources()
1725 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in survey_child_resources()
1730 * prepopulate_bars() - Fill in BARs with defaults
1738 * the memory-mapped I/O space will be aligned on the largest
1755 if (hbus->low_mmio_space) { in prepopulate_bars()
1756 low_size = 1ULL << (63 - __builtin_clzll(hbus->low_mmio_space)); in prepopulate_bars()
1757 low_base = hbus->low_mmio_res->start; in prepopulate_bars()
1760 if (hbus->high_mmio_space) { in prepopulate_bars()
1762 (63 - __builtin_clzll(hbus->high_mmio_space)); in prepopulate_bars()
1763 high_base = hbus->high_mmio_res->start; in prepopulate_bars()
1766 spin_lock_irqsave(&hbus->device_list_lock, flags); in prepopulate_bars()
1774 * If the memory enable bit is already set, Hyper-V silently ignores in prepopulate_bars()
1779 list_for_each_entry(hpdev, &hbus->children, list_entry) { in prepopulate_bars()
1787 list_for_each_entry(hpdev, &hbus->children, list_entry) { in prepopulate_bars()
1789 bar_val = hpdev->probed_bar[i]; in prepopulate_bars()
1795 ((u64)hpdev->probed_bar[i + 1] in prepopulate_bars()
1840 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in prepopulate_bars()
1849 * same ordered workqueue. Therefore hbus->children list will not change
1858 list_for_each_entry(hpdev, &hbus->children, list_entry) { in hv_pci_assign_slots()
1859 if (hpdev->pci_slot) in hv_pci_assign_slots()
1862 slot_nr = PCI_SLOT(wslot_to_devfn(hpdev->desc.win_slot.slot)); in hv_pci_assign_slots()
1863 snprintf(name, SLOT_NAME_SIZE, "%u", hpdev->desc.ser); in hv_pci_assign_slots()
1864 hpdev->pci_slot = pci_create_slot(hbus->bridge->bus, slot_nr, in hv_pci_assign_slots()
1866 if (IS_ERR(hpdev->pci_slot)) { in hv_pci_assign_slots()
1868 hpdev->pci_slot = NULL; in hv_pci_assign_slots()
1880 list_for_each_entry(hpdev, &hbus->children, list_entry) { in hv_pci_remove_slots()
1881 if (!hpdev->pci_slot) in hv_pci_remove_slots()
1883 pci_destroy_slot(hpdev->pci_slot); in hv_pci_remove_slots()
1884 hpdev->pci_slot = NULL; in hv_pci_remove_slots()
1894 struct pci_bus *bus = hbus->bridge->bus; in hv_pci_assign_numa_node()
1897 list_for_each_entry(dev, &bus->devices, bus_list) { in hv_pci_assign_numa_node()
1898 hv_dev = get_pcichild_wslot(hbus, devfn_to_wslot(dev->devfn)); in hv_pci_assign_numa_node()
1902 if (hv_dev->desc.flags & HV_PCI_DEVICE_FLAG_NUMA_AFFINITY) in hv_pci_assign_numa_node()
1903 set_dev_node(&dev->dev, hv_dev->desc.virtual_numa_node); in hv_pci_assign_numa_node()
1910 * create_root_hv_pci_bus() - Expose a new root PCI bus
1913 * Return: 0 on success, -errno on failure
1918 struct pci_host_bridge *bridge = hbus->bridge; in create_root_hv_pci_bus()
1920 bridge->dev.parent = &hbus->hdev->device; in create_root_hv_pci_bus()
1921 bridge->sysdata = &hbus->sysdata; in create_root_hv_pci_bus()
1922 bridge->ops = &hv_pcifront_ops; in create_root_hv_pci_bus()
1930 pci_bus_assign_resources(bridge->bus); in create_root_hv_pci_bus()
1932 pci_bus_add_devices(bridge->bus); in create_root_hv_pci_bus()
1934 hbus->state = hv_pcibus_installed; in create_root_hv_pci_bus()
1944 * q_resource_requirements() - Query Resource Requirements
1960 if (resp->status < 0) { in q_resource_requirements()
1961 dev_err(&completion->hpdev->hbus->hdev->device, in q_resource_requirements()
1963 resp->status); in q_resource_requirements()
1966 completion->hpdev->probed_bar[i] = in q_resource_requirements()
1967 q_res_req->probed_bar[i]; in q_resource_requirements()
1971 complete(&completion->host_event); in q_resource_requirements()
1975 * new_pcichild_device() - Create a new child device
2002 hpdev->hbus = hbus; in new_pcichild_device()
2010 res_req->message_type.type = PCI_QUERY_RESOURCE_REQUIREMENTS; in new_pcichild_device()
2011 res_req->wslot.slot = desc->win_slot.slot; in new_pcichild_device()
2013 ret = vmbus_sendpacket(hbus->hdev->channel, res_req, in new_pcichild_device()
2021 if (wait_for_response(hbus->hdev, &comp_pkt.host_event)) in new_pcichild_device()
2024 hpdev->desc = *desc; in new_pcichild_device()
2025 refcount_set(&hpdev->refs, 1); in new_pcichild_device()
2027 spin_lock_irqsave(&hbus->device_list_lock, flags); in new_pcichild_device()
2029 list_add_tail(&hpdev->list_entry, &hbus->children); in new_pcichild_device()
2030 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in new_pcichild_device()
2039 * get_pcichild_wslot() - Find device from slot
2057 spin_lock_irqsave(&hbus->device_list_lock, flags); in get_pcichild_wslot()
2058 list_for_each_entry(iter, &hbus->children, list_entry) { in get_pcichild_wslot()
2059 if (iter->desc.win_slot.slot == wslot) { in get_pcichild_wslot()
2065 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in get_pcichild_wslot()
2071 * pci_devices_present_work() - Handle new list of child devices
2076 * debug the interaction between Hyper-V and Linux. This
2091 * because both are pushed to the ordered workqueue hbus->wq.
2106 hbus = dr_wrk->bus; in pci_devices_present_work()
2112 spin_lock_irqsave(&hbus->device_list_lock, flags); in pci_devices_present_work()
2113 while (!list_empty(&hbus->dr_list)) { in pci_devices_present_work()
2114 dr = list_first_entry(&hbus->dr_list, struct hv_dr_state, in pci_devices_present_work()
2116 list_del(&dr->list_entry); in pci_devices_present_work()
2119 if (!list_empty(&hbus->dr_list)) { in pci_devices_present_work()
2124 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in pci_devices_present_work()
2130 spin_lock_irqsave(&hbus->device_list_lock, flags); in pci_devices_present_work()
2131 list_for_each_entry(hpdev, &hbus->children, list_entry) { in pci_devices_present_work()
2132 hpdev->reported_missing = true; in pci_devices_present_work()
2134 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in pci_devices_present_work()
2137 for (child_no = 0; child_no < dr->device_count; child_no++) { in pci_devices_present_work()
2139 new_desc = &dr->func[child_no]; in pci_devices_present_work()
2141 spin_lock_irqsave(&hbus->device_list_lock, flags); in pci_devices_present_work()
2142 list_for_each_entry(hpdev, &hbus->children, list_entry) { in pci_devices_present_work()
2143 if ((hpdev->desc.win_slot.slot == new_desc->win_slot.slot) && in pci_devices_present_work()
2144 (hpdev->desc.v_id == new_desc->v_id) && in pci_devices_present_work()
2145 (hpdev->desc.d_id == new_desc->d_id) && in pci_devices_present_work()
2146 (hpdev->desc.ser == new_desc->ser)) { in pci_devices_present_work()
2147 hpdev->reported_missing = false; in pci_devices_present_work()
2151 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in pci_devices_present_work()
2156 dev_err(&hbus->hdev->device, in pci_devices_present_work()
2162 spin_lock_irqsave(&hbus->device_list_lock, flags); in pci_devices_present_work()
2165 list_for_each_entry(hpdev, &hbus->children, list_entry) { in pci_devices_present_work()
2166 if (hpdev->reported_missing) { in pci_devices_present_work()
2169 list_move_tail(&hpdev->list_entry, &removed); in pci_devices_present_work()
2174 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in pci_devices_present_work()
2180 list_del(&hpdev->list_entry); in pci_devices_present_work()
2182 if (hpdev->pci_slot) in pci_devices_present_work()
2183 pci_destroy_slot(hpdev->pci_slot); in pci_devices_present_work()
2188 switch (hbus->state) { in pci_devices_present_work()
2195 pci_scan_child_bus(hbus->bridge->bus); in pci_devices_present_work()
2214 * hv_pci_start_relations_work() - Queue work to start device discovery
2218 * Return: 0 on success, -errno on failure
2227 if (hbus->state == hv_pcibus_removing) { in hv_pci_start_relations_work()
2228 dev_info(&hbus->hdev->device, in hv_pci_start_relations_work()
2230 return -ENOENT; in hv_pci_start_relations_work()
2235 return -ENOMEM; in hv_pci_start_relations_work()
2237 INIT_WORK(&dr_wrk->wrk, pci_devices_present_work); in hv_pci_start_relations_work()
2238 dr_wrk->bus = hbus; in hv_pci_start_relations_work()
2240 spin_lock_irqsave(&hbus->device_list_lock, flags); in hv_pci_start_relations_work()
2246 pending_dr = !list_empty(&hbus->dr_list); in hv_pci_start_relations_work()
2247 list_add_tail(&dr->list_entry, &hbus->dr_list); in hv_pci_start_relations_work()
2248 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in hv_pci_start_relations_work()
2253 queue_work(hbus->wq, &dr_wrk->wrk); in hv_pci_start_relations_work()
2259 * hv_pci_devices_present() - Handle list of new children
2273 dr = kzalloc(struct_size(dr, func, relations->device_count), in hv_pci_devices_present()
2278 dr->device_count = relations->device_count; in hv_pci_devices_present()
2279 for (i = 0; i < dr->device_count; i++) { in hv_pci_devices_present()
2280 dr->func[i].v_id = relations->func[i].v_id; in hv_pci_devices_present()
2281 dr->func[i].d_id = relations->func[i].d_id; in hv_pci_devices_present()
2282 dr->func[i].rev = relations->func[i].rev; in hv_pci_devices_present()
2283 dr->func[i].prog_intf = relations->func[i].prog_intf; in hv_pci_devices_present()
2284 dr->func[i].subclass = relations->func[i].subclass; in hv_pci_devices_present()
2285 dr->func[i].base_class = relations->func[i].base_class; in hv_pci_devices_present()
2286 dr->func[i].subsystem_id = relations->func[i].subsystem_id; in hv_pci_devices_present()
2287 dr->func[i].win_slot = relations->func[i].win_slot; in hv_pci_devices_present()
2288 dr->func[i].ser = relations->func[i].ser; in hv_pci_devices_present()
2296 * hv_pci_devices_present2() - Handle list of new children
2308 dr = kzalloc(struct_size(dr, func, relations->device_count), in hv_pci_devices_present2()
2313 dr->device_count = relations->device_count; in hv_pci_devices_present2()
2314 for (i = 0; i < dr->device_count; i++) { in hv_pci_devices_present2()
2315 dr->func[i].v_id = relations->func[i].v_id; in hv_pci_devices_present2()
2316 dr->func[i].d_id = relations->func[i].d_id; in hv_pci_devices_present2()
2317 dr->func[i].rev = relations->func[i].rev; in hv_pci_devices_present2()
2318 dr->func[i].prog_intf = relations->func[i].prog_intf; in hv_pci_devices_present2()
2319 dr->func[i].subclass = relations->func[i].subclass; in hv_pci_devices_present2()
2320 dr->func[i].base_class = relations->func[i].base_class; in hv_pci_devices_present2()
2321 dr->func[i].subsystem_id = relations->func[i].subsystem_id; in hv_pci_devices_present2()
2322 dr->func[i].win_slot = relations->func[i].win_slot; in hv_pci_devices_present2()
2323 dr->func[i].ser = relations->func[i].ser; in hv_pci_devices_present2()
2324 dr->func[i].flags = relations->func[i].flags; in hv_pci_devices_present2()
2325 dr->func[i].virtual_numa_node = in hv_pci_devices_present2()
2326 relations->func[i].virtual_numa_node; in hv_pci_devices_present2()
2334 * hv_eject_device_work() - Asynchronously handles ejection
2356 hbus = hpdev->hbus; in hv_eject_device_work()
2358 WARN_ON(hpdev->state != hv_pcichild_ejecting); in hv_eject_device_work()
2363 * must be done without constructs like pci_domain_nr(hbus->bridge->bus) in hv_eject_device_work()
2364 * because hbus->bridge->bus may not exist yet. in hv_eject_device_work()
2366 wslot = wslot_to_devfn(hpdev->desc.win_slot.slot); in hv_eject_device_work()
2367 pdev = pci_get_domain_bus_and_slot(hbus->bridge->domain_nr, 0, wslot); in hv_eject_device_work()
2375 spin_lock_irqsave(&hbus->device_list_lock, flags); in hv_eject_device_work()
2376 list_del(&hpdev->list_entry); in hv_eject_device_work()
2377 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in hv_eject_device_work()
2379 if (hpdev->pci_slot) in hv_eject_device_work()
2380 pci_destroy_slot(hpdev->pci_slot); in hv_eject_device_work()
2384 ejct_pkt->message_type.type = PCI_EJECTION_COMPLETE; in hv_eject_device_work()
2385 ejct_pkt->wslot.slot = hpdev->desc.win_slot.slot; in hv_eject_device_work()
2386 vmbus_sendpacket(hbus->hdev->channel, ejct_pkt, in hv_eject_device_work()
2399 * hv_pci_eject_device() - Handles device ejection
2403 * just schedules work so that we don't re-enter the packet
2408 struct hv_pcibus_device *hbus = hpdev->hbus; in hv_pci_eject_device()
2409 struct hv_device *hdev = hbus->hdev; in hv_pci_eject_device()
2411 if (hbus->state == hv_pcibus_removing) { in hv_pci_eject_device()
2412 dev_info(&hdev->device, "PCI VMBus EJECT: ignored\n"); in hv_pci_eject_device()
2416 hpdev->state = hv_pcichild_ejecting; in hv_pci_eject_device()
2418 INIT_WORK(&hpdev->wrk, hv_eject_device_work); in hv_pci_eject_device()
2419 queue_work(hbus->wq, &hpdev->wrk); in hv_pci_eject_device()
2423 * hv_pci_onchannelcallback() - Handles incoming packets
2453 ret = vmbus_recvpacket_raw(hbus->hdev->channel, buffer, in hv_pci_onchannelcallback()
2456 if (ret == -ENOBUFS) { in hv_pci_onchannelcallback()
2478 switch (desc->type) { in hv_pci_onchannelcallback()
2487 comp_packet->completion_func(comp_packet->compl_ctxt, in hv_pci_onchannelcallback()
2495 switch (new_message->message_type.type) { in hv_pci_onchannelcallback()
2501 bus_rel->device_count)) { in hv_pci_onchannelcallback()
2502 dev_err(&hbus->hdev->device, in hv_pci_onchannelcallback()
2515 bus_rel2->device_count)) { in hv_pci_onchannelcallback()
2516 dev_err(&hbus->hdev->device, in hv_pci_onchannelcallback()
2528 dev_message->wslot.slot); in hv_pci_onchannelcallback()
2539 inval->wslot.slot); in hv_pci_onchannelcallback()
2541 if (hpdev->block_invalidate) { in hv_pci_onchannelcallback()
2542 hpdev->block_invalidate( in hv_pci_onchannelcallback()
2543 hpdev->invalidate_context, in hv_pci_onchannelcallback()
2544 inval->block_mask); in hv_pci_onchannelcallback()
2551 dev_warn(&hbus->hdev->device, in hv_pci_onchannelcallback()
2553 new_message->message_type.type); in hv_pci_onchannelcallback()
2559 dev_err(&hbus->hdev->device, in hv_pci_onchannelcallback()
2561 desc->type, req_id, bytes_recvd); in hv_pci_onchannelcallback()
2570 * hv_pci_protocol_negotiation() - Set up protocol
2573 * the order of probing - highest go first.
2607 return -ENOMEM; in hv_pci_protocol_negotiation()
2610 pkt->completion_func = hv_pci_generic_compl; in hv_pci_protocol_negotiation()
2611 pkt->compl_ctxt = &comp_pkt; in hv_pci_protocol_negotiation()
2612 version_req = (struct pci_version_request *)&pkt->message; in hv_pci_protocol_negotiation()
2613 version_req->message_type.type = PCI_QUERY_PROTOCOL_VERSION; in hv_pci_protocol_negotiation()
2616 version_req->protocol_version = version[i]; in hv_pci_protocol_negotiation()
2617 ret = vmbus_sendpacket(hdev->channel, version_req, in hv_pci_protocol_negotiation()
2625 dev_err(&hdev->device, in hv_pci_protocol_negotiation()
2626 "PCI Pass-through VSP failed to request version: %d", in hv_pci_protocol_negotiation()
2632 hbus->protocol_version = version[i]; in hv_pci_protocol_negotiation()
2633 dev_info(&hdev->device, in hv_pci_protocol_negotiation()
2635 hbus->protocol_version); in hv_pci_protocol_negotiation()
2640 dev_err(&hdev->device, in hv_pci_protocol_negotiation()
2641 "PCI Pass-through VSP failed version request: %#x", in hv_pci_protocol_negotiation()
2643 ret = -EPROTO; in hv_pci_protocol_negotiation()
2650 dev_err(&hdev->device, in hv_pci_protocol_negotiation()
2651 "PCI pass-through VSP failed to find supported version"); in hv_pci_protocol_negotiation()
2652 ret = -EPROTO; in hv_pci_protocol_negotiation()
2660 * hv_pci_free_bridge_windows() - Release memory regions for the
2671 if (hbus->low_mmio_space && hbus->low_mmio_res) { in hv_pci_free_bridge_windows()
2672 hbus->low_mmio_res->flags |= IORESOURCE_BUSY; in hv_pci_free_bridge_windows()
2673 vmbus_free_mmio(hbus->low_mmio_res->start, in hv_pci_free_bridge_windows()
2674 resource_size(hbus->low_mmio_res)); in hv_pci_free_bridge_windows()
2677 if (hbus->high_mmio_space && hbus->high_mmio_res) { in hv_pci_free_bridge_windows()
2678 hbus->high_mmio_res->flags |= IORESOURCE_BUSY; in hv_pci_free_bridge_windows()
2679 vmbus_free_mmio(hbus->high_mmio_res->start, in hv_pci_free_bridge_windows()
2680 resource_size(hbus->high_mmio_res)); in hv_pci_free_bridge_windows()
2685 * hv_pci_allocate_bridge_windows() - Allocate memory regions
2707 * Return: 0 on success, -errno on failure
2714 if (hbus->low_mmio_space) { in hv_pci_allocate_bridge_windows()
2715 align = 1ULL << (63 - __builtin_clzll(hbus->low_mmio_space)); in hv_pci_allocate_bridge_windows()
2716 ret = vmbus_allocate_mmio(&hbus->low_mmio_res, hbus->hdev, 0, in hv_pci_allocate_bridge_windows()
2718 hbus->low_mmio_space, in hv_pci_allocate_bridge_windows()
2721 dev_err(&hbus->hdev->device, in hv_pci_allocate_bridge_windows()
2723 hbus->low_mmio_space); in hv_pci_allocate_bridge_windows()
2728 hbus->low_mmio_res->flags |= IORESOURCE_WINDOW; in hv_pci_allocate_bridge_windows()
2729 hbus->low_mmio_res->flags &= ~IORESOURCE_BUSY; in hv_pci_allocate_bridge_windows()
2730 pci_add_resource(&hbus->bridge->windows, hbus->low_mmio_res); in hv_pci_allocate_bridge_windows()
2733 if (hbus->high_mmio_space) { in hv_pci_allocate_bridge_windows()
2734 align = 1ULL << (63 - __builtin_clzll(hbus->high_mmio_space)); in hv_pci_allocate_bridge_windows()
2735 ret = vmbus_allocate_mmio(&hbus->high_mmio_res, hbus->hdev, in hv_pci_allocate_bridge_windows()
2736 0x100000000, -1, in hv_pci_allocate_bridge_windows()
2737 hbus->high_mmio_space, align, in hv_pci_allocate_bridge_windows()
2740 dev_err(&hbus->hdev->device, in hv_pci_allocate_bridge_windows()
2742 hbus->high_mmio_space); in hv_pci_allocate_bridge_windows()
2747 hbus->high_mmio_res->flags |= IORESOURCE_WINDOW; in hv_pci_allocate_bridge_windows()
2748 hbus->high_mmio_res->flags &= ~IORESOURCE_BUSY; in hv_pci_allocate_bridge_windows()
2749 pci_add_resource(&hbus->bridge->windows, hbus->high_mmio_res); in hv_pci_allocate_bridge_windows()
2755 if (hbus->low_mmio_res) { in hv_pci_allocate_bridge_windows()
2756 vmbus_free_mmio(hbus->low_mmio_res->start, in hv_pci_allocate_bridge_windows()
2757 resource_size(hbus->low_mmio_res)); in hv_pci_allocate_bridge_windows()
2764 * hv_allocate_config_window() - Find MMIO space for PCI Config
2767 * This function claims memory-mapped I/O space for accessing
2770 * Return: 0 on success, -errno on failure
2780 ret = vmbus_allocate_mmio(&hbus->mem_config, hbus->hdev, 0, -1, in hv_allocate_config_window()
2793 hbus->mem_config->flags |= IORESOURCE_BUSY; in hv_allocate_config_window()
2800 vmbus_free_mmio(hbus->mem_config->start, PCI_CONFIG_MMIO_LENGTH); in hv_free_config_window()
2806 * hv_pci_enter_d0() - Bring the "bus" into the D0 power state
2809 * Return: 0 on success, -errno on failure
2821 * powered-on state. This includes telling the host which region in hv_pci_enter_d0()
2822 * of memory-mapped I/O space has been chosen for configuration space in hv_pci_enter_d0()
2827 return -ENOMEM; in hv_pci_enter_d0()
2830 pkt->completion_func = hv_pci_generic_compl; in hv_pci_enter_d0()
2831 pkt->compl_ctxt = &comp_pkt; in hv_pci_enter_d0()
2832 d0_entry = (struct pci_bus_d0_entry *)&pkt->message; in hv_pci_enter_d0()
2833 d0_entry->message_type.type = PCI_BUS_D0ENTRY; in hv_pci_enter_d0()
2834 d0_entry->mmio_base = hbus->mem_config->start; in hv_pci_enter_d0()
2836 ret = vmbus_sendpacket(hdev->channel, d0_entry, sizeof(*d0_entry), in hv_pci_enter_d0()
2846 dev_err(&hdev->device, in hv_pci_enter_d0()
2847 "PCI Pass-through VSP failed D0 Entry with status %x\n", in hv_pci_enter_d0()
2849 ret = -EPROTO; in hv_pci_enter_d0()
2861 * hv_pci_query_relations() - Ask host to send list of child
2865 * Return: 0 on success, -errno on failure
2876 if (cmpxchg(&hbus->survey_event, NULL, &comp)) in hv_pci_query_relations()
2877 return -ENOTEMPTY; in hv_pci_query_relations()
2882 ret = vmbus_sendpacket(hdev->channel, &message, sizeof(message), in hv_pci_query_relations()
2891 * hv_send_resources_allocated() - Report local resource choices
2905 * Return: 0 on success, -errno on failure
2919 size_res = (hbus->protocol_version < PCI_PROTOCOL_VERSION_1_2) in hv_send_resources_allocated()
2924 return -ENOMEM; in hv_send_resources_allocated()
2935 pkt->completion_func = hv_pci_generic_compl; in hv_send_resources_allocated()
2936 pkt->compl_ctxt = &comp_pkt; in hv_send_resources_allocated()
2938 if (hbus->protocol_version < PCI_PROTOCOL_VERSION_1_2) { in hv_send_resources_allocated()
2940 (struct pci_resources_assigned *)&pkt->message; in hv_send_resources_allocated()
2941 res_assigned->message_type.type = in hv_send_resources_allocated()
2943 res_assigned->wslot.slot = hpdev->desc.win_slot.slot; in hv_send_resources_allocated()
2946 (struct pci_resources_assigned2 *)&pkt->message; in hv_send_resources_allocated()
2947 res_assigned2->message_type.type = in hv_send_resources_allocated()
2949 res_assigned2->wslot.slot = hpdev->desc.win_slot.slot; in hv_send_resources_allocated()
2953 ret = vmbus_sendpacket(hdev->channel, &pkt->message, in hv_send_resources_allocated()
2963 ret = -EPROTO; in hv_send_resources_allocated()
2964 dev_err(&hdev->device, in hv_send_resources_allocated()
2970 hbus->wslot_res_allocated = wslot; in hv_send_resources_allocated()
2978 * hv_send_resources_released() - Report local resources
2982 * Return: 0 on success, -errno on failure
2992 for (wslot = hbus->wslot_res_allocated; wslot >= 0; wslot--) { in hv_send_resources_released()
2999 pkt.wslot.slot = hpdev->desc.win_slot.slot; in hv_send_resources_released()
3003 ret = vmbus_sendpacket(hdev->channel, &pkt, sizeof(pkt), 0, in hv_send_resources_released()
3008 hbus->wslot_res_allocated = wslot - 1; in hv_send_resources_released()
3011 hbus->wslot_res_allocated = -1; in hv_send_resources_released()
3026 * hv_get_dom_num() - Get a valid PCI domain number
3050 * hv_put_dom_num() - Mark the PCI domain number as free
3059 * hv_pci_probe() - New VMBus channel probe, for a root PCI bus
3063 * Return: 0 on success, -errno on failure
3081 bridge = devm_pci_alloc_host_bridge(&hdev->device, 0); in hv_pci_probe()
3083 return -ENOMEM; in hv_pci_probe()
3087 * alignment for kmalloc(power-of-two)"), kzalloc() is able to allocate in hv_pci_probe()
3088 * a 4KB buffer that is guaranteed to be 4KB-aligned. Here the size and in hv_pci_probe()
3096 * is tracked by hbus->children) as memory leak (false positive). in hv_pci_probe()
3105 return -ENOMEM; in hv_pci_probe()
3107 hbus->bridge = bridge; in hv_pci_probe()
3108 hbus->state = hv_pcibus_init; in hv_pci_probe()
3109 hbus->wslot_res_allocated = -1; in hv_pci_probe()
3117 * Note that, since this code only runs in a Hyper-V VM, Hyper-V in hv_pci_probe()
3124 dom_req = hdev->dev_instance.b[5] << 8 | hdev->dev_instance.b[4]; in hv_pci_probe()
3128 dev_err(&hdev->device, in hv_pci_probe()
3130 ret = -EINVAL; in hv_pci_probe()
3135 dev_info(&hdev->device, in hv_pci_probe()
3139 hbus->bridge->domain_nr = dom; in hv_pci_probe()
3141 hbus->sysdata.domain = dom; in hv_pci_probe()
3144 hbus->hdev = hdev; in hv_pci_probe()
3145 INIT_LIST_HEAD(&hbus->children); in hv_pci_probe()
3146 INIT_LIST_HEAD(&hbus->dr_list); in hv_pci_probe()
3147 spin_lock_init(&hbus->config_lock); in hv_pci_probe()
3148 spin_lock_init(&hbus->device_list_lock); in hv_pci_probe()
3149 spin_lock_init(&hbus->retarget_msi_interrupt_lock); in hv_pci_probe()
3150 hbus->wq = alloc_ordered_workqueue("hv_pci_%x", 0, in hv_pci_probe()
3151 hbus->bridge->domain_nr); in hv_pci_probe()
3152 if (!hbus->wq) { in hv_pci_probe()
3153 ret = -ENOMEM; in hv_pci_probe()
3157 ret = vmbus_open(hdev->channel, pci_ring_size, pci_ring_size, NULL, 0, in hv_pci_probe()
3173 hbus->cfg_addr = ioremap(hbus->mem_config->start, in hv_pci_probe()
3175 if (!hbus->cfg_addr) { in hv_pci_probe()
3176 dev_err(&hdev->device, in hv_pci_probe()
3178 ret = -ENOMEM; in hv_pci_probe()
3182 name = kasprintf(GFP_KERNEL, "%pUL", &hdev->dev_instance); in hv_pci_probe()
3184 ret = -ENOMEM; in hv_pci_probe()
3188 hbus->fwnode = irq_domain_alloc_named_fwnode(name); in hv_pci_probe()
3190 if (!hbus->fwnode) { in hv_pci_probe()
3191 ret = -ENOMEM; in hv_pci_probe()
3218 if (ret == -EPROTO && enter_d0_retry) { in hv_pci_probe()
3221 dev_err(&hdev->device, "Retrying D0 Entry\n"); in hv_pci_probe()
3231 hbus->wslot_res_allocated = 255; in hv_pci_probe()
3237 dev_err(&hdev->device, in hv_pci_probe()
3253 hbus->state = hv_pcibus_probed; in hv_pci_probe()
3266 irq_domain_remove(hbus->irq_domain); in hv_pci_probe()
3268 irq_domain_free_fwnode(hbus->fwnode); in hv_pci_probe()
3270 iounmap(hbus->cfg_addr); in hv_pci_probe()
3274 vmbus_close(hdev->channel); in hv_pci_probe()
3276 destroy_workqueue(hbus->wq); in hv_pci_probe()
3278 hv_put_dom_num(hbus->bridge->domain_nr); in hv_pci_probe()
3298 * access the per-channel ringbuffer any longer. in hv_pci_bus_exit()
3300 if (hdev->channel->rescind) in hv_pci_bus_exit()
3308 spin_lock_irqsave(&hbus->device_list_lock, flags); in hv_pci_bus_exit()
3309 list_for_each_entry_safe(hpdev, tmp, &hbus->children, list_entry) in hv_pci_bus_exit()
3310 list_move_tail(&hpdev->list_entry, &removed); in hv_pci_bus_exit()
3311 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in hv_pci_bus_exit()
3315 list_del(&hpdev->list_entry); in hv_pci_bus_exit()
3316 if (hpdev->pci_slot) in hv_pci_bus_exit()
3317 pci_destroy_slot(hpdev->pci_slot); in hv_pci_bus_exit()
3326 dev_err(&hdev->device, in hv_pci_bus_exit()
3337 ret = vmbus_sendpacket(hdev->channel, &pkt.teardown_packet.message, in hv_pci_bus_exit()
3346 return -ETIMEDOUT; in hv_pci_bus_exit()
3352 * hv_pci_remove() - Remove routine for this VMBus channel
3355 * Return: 0 on success, -errno on failure
3363 if (hbus->state == hv_pcibus_installed) { in hv_pci_remove()
3364 tasklet_disable(&hdev->channel->callback_event); in hv_pci_remove()
3365 hbus->state = hv_pcibus_removing; in hv_pci_remove()
3366 tasklet_enable(&hdev->channel->callback_event); in hv_pci_remove()
3367 destroy_workqueue(hbus->wq); in hv_pci_remove()
3368 hbus->wq = NULL; in hv_pci_remove()
3371 * on hbus-wq. We can't race with hv_pci_devices_present() in hv_pci_remove()
3377 pci_stop_root_bus(hbus->bridge->bus); in hv_pci_remove()
3379 pci_remove_root_bus(hbus->bridge->bus); in hv_pci_remove()
3385 vmbus_close(hdev->channel); in hv_pci_remove()
3387 iounmap(hbus->cfg_addr); in hv_pci_remove()
3390 irq_domain_remove(hbus->irq_domain); in hv_pci_remove()
3391 irq_domain_free_fwnode(hbus->fwnode); in hv_pci_remove()
3393 hv_put_dom_num(hbus->bridge->domain_nr); in hv_pci_remove()
3411 * items onto hbus->wq in hv_pci_devices_present() and in hv_pci_suspend()
3414 * the work item handler pci_devices_present_work() -> in hv_pci_suspend()
3418 * callback tasklet, sets hbus->state to hv_pcibus_removing, and in hv_pci_suspend()
3419 * re-enables the tasklet. This way, when hv_pci_suspend() proceeds, in hv_pci_suspend()
3421 * hbus->wq and safely closes the vmbus channel. in hv_pci_suspend()
3423 tasklet_disable(&hdev->channel->callback_event); in hv_pci_suspend()
3426 old_state = hbus->state; in hv_pci_suspend()
3427 if (hbus->state == hv_pcibus_installed) in hv_pci_suspend()
3428 hbus->state = hv_pcibus_removing; in hv_pci_suspend()
3430 tasklet_enable(&hdev->channel->callback_event); in hv_pci_suspend()
3433 return -EINVAL; in hv_pci_suspend()
3435 flush_workqueue(hbus->wq); in hv_pci_suspend()
3441 vmbus_close(hdev->channel); in hv_pci_suspend()
3452 irq_data = irq_get_irq_data(entry->irq); in hv_pci_restore_msi_msg()
3454 return -EINVAL; in hv_pci_restore_msi_msg()
3456 hv_compose_msi_msg(irq_data, &entry->msg); in hv_pci_restore_msi_msg()
3463 * Upon resume, pci_restore_msi_state() -> ... -> __pci_write_msi_msg()
3464 * directly writes the MSI/MSI-X registers via MMIO, but since Hyper-V
3466 * must be used to ask Hyper-V to re-create the IOMMU Interrupt Remapping
3471 pci_walk_bus(hbus->bridge->bus, hv_pci_restore_msi_msg, NULL); in hv_pci_restore_msi_state()
3480 hbus->state = hv_pcibus_init; in hv_pci_resume()
3482 ret = vmbus_open(hdev->channel, pci_ring_size, pci_ring_size, NULL, 0, in hv_pci_resume()
3488 version[0] = hbus->protocol_version; in hv_pci_resume()
3509 hbus->state = hv_pcibus_installed; in hv_pci_resume()
3512 vmbus_close(hdev->channel); in hv_pci_resume()
3517 /* PCI Pass-through Class ID */
3518 /* 44C4F61D-4444-4400-9D52-802E27EDE19F */
3546 return -ENODEV; in init_hv_pci_drv()
3562 MODULE_DESCRIPTION("Hyper-V PCI");