Lines Matching refs:hbus

530 	struct hv_pcibus_device *hbus;
573 static struct hv_pci_dev *get_pcichild_wslot(struct hv_pcibus_device *hbus,
664 void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + where;
692 spin_lock_irqsave(&hpdev->hbus->config_lock, flags);
694 writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr);
714 spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags);
716 dev_err(&hpdev->hbus->hdev->device,
725 void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET +
728 spin_lock_irqsave(&hpdev->hbus->config_lock, flags);
731 writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr);
741 spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags);
757 void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + where;
763 spin_lock_irqsave(&hpdev->hbus->config_lock, flags);
765 writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr);
785 spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags);
787 dev_err(&hpdev->hbus->hdev->device,
806 struct hv_pcibus_device *hbus =
810 hpdev = get_pcichild_wslot(hbus, devfn_to_wslot(devfn));
834 struct hv_pcibus_device *hbus =
838 hpdev = get_pcichild_wslot(hbus, devfn_to_wslot(devfn));
935 struct hv_pcibus_device *hbus =
962 ret = vmbus_sendpacket(hbus->hdev->channel, read_blk,
969 ret = wait_for_response(hbus->hdev, &comp_pkt.comp_pkt.host_event);
975 dev_err(&hbus->hdev->device,
1015 struct hv_pcibus_device *hbus =
1052 ret = vmbus_sendpacket(hbus->hdev->channel, write_blk, pkt_size,
1058 ret = wait_for_response(hbus->hdev, &comp_pkt.host_event);
1063 dev_err(&hbus->hdev->device,
1085 struct hv_pcibus_device *hbus =
1090 hpdev = get_pcichild_wslot(hbus, devfn_to_wslot(pdev->devfn));
1122 vmbus_sendpacket(hpdev->hbus->hdev->channel, int_pkt, sizeof(*int_pkt),
1141 struct hv_pcibus_device *hbus;
1149 hbus = info->data;
1155 hpdev = get_pcichild_wslot(hbus, devfn_to_wslot(pdev->devfn));
1216 struct hv_pcibus_device *hbus;
1229 hbus = container_of(pbus->sysdata, struct hv_pcibus_device, sysdata);
1232 dev_warn(&hbus->hdev->device, "%s() can not unmask irq %u\n",
1237 spin_lock_irqsave(&hbus->retarget_msi_interrupt_lock, flags);
1239 params = &hbus->retarget_msi_interrupt_params;
1245 params->device_id = (hbus->hdev->dev_instance.b[5] << 24) |
1246 (hbus->hdev->dev_instance.b[4] << 16) |
1247 (hbus->hdev->dev_instance.b[7] << 8) |
1248 (hbus->hdev->dev_instance.b[6] & 0xf8) |
1259 if (hbus->protocol_version >= PCI_PROTOCOL_VERSION_1_2) {
1301 spin_unlock_irqrestore(&hbus->retarget_msi_interrupt_lock, flags);
1319 if (res && hbus->state != hv_pcibus_removing)
1320 dev_err(&hbus->hdev->device,
1399 struct hv_pcibus_device *hbus;
1433 hbus = container_of(pbus->sysdata, struct hv_pcibus_device, sysdata);
1434 channel = hbus->hdev->channel;
1435 hpdev = get_pcichild_wslot(hbus, devfn_to_wslot(pdev->devfn));
1478 switch (hbus->protocol_version) {
1501 dev_err(&hbus->hdev->device,
1506 ret = vmbus_sendpacket(hpdev->hbus->hdev->channel, &ctxt.int_pkts,
1511 dev_err(&hbus->hdev->device,
1532 dev_err_once(&hbus->hdev->device,
1549 hv_pci_onchannelcallback(hbus);
1558 dev_err(&hbus->hdev->device,
1609 * @hbus: The root PCI bus
1620 static int hv_pcie_init_irq_domain(struct hv_pcibus_device *hbus)
1622 hbus->msi_info.chip = &hv_msi_irq_chip;
1623 hbus->msi_info.ops = &hv_msi_ops;
1624 hbus->msi_info.flags = (MSI_FLAG_USE_DEF_DOM_OPS |
1627 hbus->msi_info.handler = handle_edge_irq;
1628 hbus->msi_info.handler_name = "edge";
1629 hbus->msi_info.data = hbus;
1630 hbus->irq_domain = pci_msi_create_irq_domain(hbus->sysdata.fwnode,
1631 &hbus->msi_info,
1633 if (!hbus->irq_domain) {
1634 dev_err(&hbus->hdev->device,
1664 * @hbus: Root PCI bus, as understood by this driver
1666 static void survey_child_resources(struct hv_pcibus_device *hbus)
1676 event = xchg(&hbus->survey_event, NULL);
1681 if (hbus->low_mmio_space || hbus->high_mmio_space) {
1686 spin_lock_irqsave(&hbus->device_list_lock, flags);
1693 list_for_each_entry(hpdev, &hbus->children, list_entry) {
1696 dev_err(&hbus->hdev->device,
1715 hbus->high_mmio_space += bar_size;
1717 hbus->low_mmio_space += bar_size;
1722 spin_unlock_irqrestore(&hbus->device_list_lock, flags);
1728 * @hbus: Root PCI bus, as understood by this driver
1738 static void prepopulate_bars(struct hv_pcibus_device *hbus)
1752 if (hbus->low_mmio_space) {
1753 low_size = 1ULL << (63 - __builtin_clzll(hbus->low_mmio_space));
1754 low_base = hbus->low_mmio_res->start;
1757 if (hbus->high_mmio_space) {
1759 (63 - __builtin_clzll(hbus->high_mmio_space));
1760 high_base = hbus->high_mmio_res->start;
1763 spin_lock_irqsave(&hbus->device_list_lock, flags);
1776 list_for_each_entry(hpdev, &hbus->children, list_entry) {
1784 list_for_each_entry(hpdev, &hbus->children, list_entry) {
1837 spin_unlock_irqrestore(&hbus->device_list_lock, flags);
1846 * same ordered workqueue. Therefore hbus->children list will not change
1849 static void hv_pci_assign_slots(struct hv_pcibus_device *hbus)
1855 list_for_each_entry(hpdev, &hbus->children, list_entry) {
1861 hpdev->pci_slot = pci_create_slot(hbus->pci_bus, slot_nr,
1873 static void hv_pci_remove_slots(struct hv_pcibus_device *hbus)
1877 list_for_each_entry(hpdev, &hbus->children, list_entry) {
1888 static void hv_pci_assign_numa_node(struct hv_pcibus_device *hbus)
1891 struct pci_bus *bus = hbus->pci_bus;
1895 hv_dev = get_pcichild_wslot(hbus, devfn_to_wslot(dev->devfn));
1917 * @hbus: Root PCI bus, as understood by this driver
1921 static int create_root_hv_pci_bus(struct hv_pcibus_device *hbus)
1924 hbus->pci_bus = pci_create_root_bus(&hbus->hdev->device,
1927 &hbus->sysdata,
1928 &hbus->resources_for_children);
1929 if (!hbus->pci_bus)
1932 hbus->pci_bus->msi = &hbus->msi_chip;
1933 hbus->pci_bus->msi->dev = &hbus->hdev->device;
1936 pci_scan_child_bus(hbus->pci_bus);
1937 hv_pci_assign_numa_node(hbus);
1938 pci_bus_assign_resources(hbus->pci_bus);
1939 hv_pci_assign_slots(hbus);
1940 pci_bus_add_devices(hbus->pci_bus);
1942 hbus->state = hv_pcibus_installed;
1969 dev_err(&completion->hpdev->hbus->hdev->device,
1984 * @hbus: The internal struct tracking this root PCI bus.
1993 static struct hv_pci_dev *new_pcichild_device(struct hv_pcibus_device *hbus,
2010 hpdev->hbus = hbus;
2021 ret = vmbus_sendpacket(hbus->hdev->channel, res_req,
2029 if (wait_for_response(hbus->hdev, &comp_pkt.host_event))
2035 spin_lock_irqsave(&hbus->device_list_lock, flags);
2037 list_add_tail(&hpdev->list_entry, &hbus->children);
2038 spin_unlock_irqrestore(&hbus->device_list_lock, flags);
2048 * @hbus: Root PCI bus, as understood by this driver
2059 static struct hv_pci_dev *get_pcichild_wslot(struct hv_pcibus_device *hbus,
2065 spin_lock_irqsave(&hbus->device_list_lock, flags);
2066 list_for_each_entry(iter, &hbus->children, list_entry) {
2073 spin_unlock_irqrestore(&hbus->device_list_lock, flags);
2099 * because both are pushed to the ordered workqueue hbus->wq.
2107 struct hv_pcibus_device *hbus;
2114 hbus = dr_wrk->bus;
2120 spin_lock_irqsave(&hbus->device_list_lock, flags);
2121 while (!list_empty(&hbus->dr_list)) {
2122 dr = list_first_entry(&hbus->dr_list, struct hv_dr_state,
2127 if (!list_empty(&hbus->dr_list)) {
2132 spin_unlock_irqrestore(&hbus->device_list_lock, flags);
2135 put_hvpcibus(hbus);
2140 spin_lock_irqsave(&hbus->device_list_lock, flags);
2141 list_for_each_entry(hpdev, &hbus->children, list_entry) {
2144 spin_unlock_irqrestore(&hbus->device_list_lock, flags);
2151 spin_lock_irqsave(&hbus->device_list_lock, flags);
2152 list_for_each_entry(hpdev, &hbus->children, list_entry) {
2161 spin_unlock_irqrestore(&hbus->device_list_lock, flags);
2164 hpdev = new_pcichild_device(hbus, new_desc);
2166 dev_err(&hbus->hdev->device,
2172 spin_lock_irqsave(&hbus->device_list_lock, flags);
2175 list_for_each_entry(hpdev, &hbus->children, list_entry) {
2184 spin_unlock_irqrestore(&hbus->device_list_lock, flags);
2198 switch (hbus->state) {
2205 pci_scan_child_bus(hbus->pci_bus);
2206 hv_pci_assign_numa_node(hbus);
2207 hv_pci_assign_slots(hbus);
2213 survey_child_resources(hbus);
2220 put_hvpcibus(hbus);
2226 * @hbus: Root PCI bus, as understood by this driver
2231 static int hv_pci_start_relations_work(struct hv_pcibus_device *hbus,
2238 if (hbus->state == hv_pcibus_removing) {
2239 dev_info(&hbus->hdev->device,
2249 dr_wrk->bus = hbus;
2251 spin_lock_irqsave(&hbus->device_list_lock, flags);
2257 pending_dr = !list_empty(&hbus->dr_list);
2258 list_add_tail(&dr->list_entry, &hbus->dr_list);
2259 spin_unlock_irqrestore(&hbus->device_list_lock, flags);
2264 get_hvpcibus(hbus);
2265 queue_work(hbus->wq, &dr_wrk->wrk);
2273 * @hbus: Root PCI bus, as understood by this driver
2280 static void hv_pci_devices_present(struct hv_pcibus_device *hbus,
2304 if (hv_pci_start_relations_work(hbus, dr))
2310 * @hbus: Root PCI bus, as understood by this driver
2315 static void hv_pci_devices_present2(struct hv_pcibus_device *hbus,
2342 if (hv_pci_start_relations_work(hbus, dr))
2358 struct hv_pcibus_device *hbus;
2369 hbus = hpdev->hbus;
2374 * must be done without constructs like pci_domain_nr(hbus->pci_bus)
2375 * because hbus->pci_bus may not exist yet.
2378 pdev = pci_get_domain_bus_and_slot(hbus->sysdata.domain, 0, wslot);
2386 spin_lock_irqsave(&hbus->device_list_lock, flags);
2388 spin_unlock_irqrestore(&hbus->device_list_lock, flags);
2397 vmbus_sendpacket(hbus->hdev->channel, ejct_pkt,
2408 put_hvpcibus(hbus);
2421 struct hv_pcibus_device *hbus = hpdev->hbus;
2422 struct hv_device *hdev = hbus->hdev;
2424 if (hbus->state == hv_pcibus_removing) {
2431 get_hvpcibus(hbus);
2432 queue_work(hbus->wq, &hpdev->wrk);
2446 struct hv_pcibus_device *hbus = context;
2466 ret = vmbus_recvpacket_raw(hbus->hdev->channel, buffer,
2515 dev_err(&hbus->hdev->device,
2520 hv_pci_devices_present(hbus, bus_rel);
2529 dev_err(&hbus->hdev->device,
2534 hv_pci_devices_present2(hbus, bus_rel2);
2540 hpdev = get_pcichild_wslot(hbus,
2551 hpdev = get_pcichild_wslot(hbus,
2564 dev_warn(&hbus->hdev->device,
2572 dev_err(&hbus->hdev->device,
2605 struct hv_pcibus_device *hbus = hv_get_drvdata(hdev);
2645 hbus->protocol_version = version[i];
2648 hbus->protocol_version);
2675 * @hbus: Root PCI bus, as understood by this driver
2677 static void hv_pci_free_bridge_windows(struct hv_pcibus_device *hbus)
2684 if (hbus->low_mmio_space && hbus->low_mmio_res) {
2685 hbus->low_mmio_res->flags |= IORESOURCE_BUSY;
2686 vmbus_free_mmio(hbus->low_mmio_res->start,
2687 resource_size(hbus->low_mmio_res));
2690 if (hbus->high_mmio_space && hbus->high_mmio_res) {
2691 hbus->high_mmio_res->flags |= IORESOURCE_BUSY;
2692 vmbus_free_mmio(hbus->high_mmio_res->start,
2693 resource_size(hbus->high_mmio_res));
2700 * @hbus: Root PCI bus, as understood by this driver
2722 static int hv_pci_allocate_bridge_windows(struct hv_pcibus_device *hbus)
2727 if (hbus->low_mmio_space) {
2728 align = 1ULL << (63 - __builtin_clzll(hbus->low_mmio_space));
2729 ret = vmbus_allocate_mmio(&hbus->low_mmio_res, hbus->hdev, 0,
2731 hbus->low_mmio_space,
2734 dev_err(&hbus->hdev->device,
2736 hbus->low_mmio_space);
2741 hbus->low_mmio_res->flags |= IORESOURCE_WINDOW;
2742 hbus->low_mmio_res->flags &= ~IORESOURCE_BUSY;
2743 pci_add_resource(&hbus->resources_for_children,
2744 hbus->low_mmio_res);
2747 if (hbus->high_mmio_space) {
2748 align = 1ULL << (63 - __builtin_clzll(hbus->high_mmio_space));
2749 ret = vmbus_allocate_mmio(&hbus->high_mmio_res, hbus->hdev,
2751 hbus->high_mmio_space, align,
2754 dev_err(&hbus->hdev->device,
2756 hbus->high_mmio_space);
2761 hbus->high_mmio_res->flags |= IORESOURCE_WINDOW;
2762 hbus->high_mmio_res->flags &= ~IORESOURCE_BUSY;
2763 pci_add_resource(&hbus->resources_for_children,
2764 hbus->high_mmio_res);
2770 if (hbus->low_mmio_res) {
2771 vmbus_free_mmio(hbus->low_mmio_res->start,
2772 resource_size(hbus->low_mmio_res));
2780 * @hbus: Root PCI bus, as understood by this driver
2787 static int hv_allocate_config_window(struct hv_pcibus_device *hbus)
2795 ret = vmbus_allocate_mmio(&hbus->mem_config, hbus->hdev, 0, -1,
2808 hbus->mem_config->flags |= IORESOURCE_BUSY;
2813 static void hv_free_config_window(struct hv_pcibus_device *hbus)
2815 vmbus_free_mmio(hbus->mem_config->start, PCI_CONFIG_MMIO_LENGTH);
2828 struct hv_pcibus_device *hbus = hv_get_drvdata(hdev);
2851 d0_entry->mmio_base = hbus->mem_config->start;
2882 hbus->wslot_res_allocated = 255;
2918 struct hv_pcibus_device *hbus = hv_get_drvdata(hdev);
2925 if (cmpxchg(&hbus->survey_event, NULL, &comp))
2940 * channel callback already scheduled a work to hbus->wq, which can be
2942 * complete(&hbus->survey_event), even after hv_pci_query_relations()
2945 * raw_spin_lock_irqsave(). Flush hbus->wq before we exit from
2947 * -ENODEV, there can't be any more work item scheduled to hbus->wq
2952 flush_workqueue(hbus->wq);
2976 struct hv_pcibus_device *hbus = hv_get_drvdata(hdev);
2986 size_res = (hbus->protocol_version < PCI_PROTOCOL_VERSION_1_2)
2996 hpdev = get_pcichild_wslot(hbus, wslot);
3005 if (hbus->protocol_version < PCI_PROTOCOL_VERSION_1_2) {
3037 hbus->wslot_res_allocated = wslot;
3053 struct hv_pcibus_device *hbus = hv_get_drvdata(hdev);
3059 for (wslot = hbus->wslot_res_allocated; wslot >= 0; wslot--) {
3060 hpdev = get_pcichild_wslot(hbus, wslot);
3075 hbus->wslot_res_allocated = wslot - 1;
3078 hbus->wslot_res_allocated = -1;
3083 static void get_hvpcibus(struct hv_pcibus_device *hbus)
3085 refcount_inc(&hbus->remove_lock);
3088 static void put_hvpcibus(struct hv_pcibus_device *hbus)
3090 if (refcount_dec_and_test(&hbus->remove_lock))
3091 complete(&hbus->remove_event);
3146 struct hv_pcibus_device *hbus;
3155 BUILD_BUG_ON(sizeof(*hbus) > HV_HYP_PAGE_SIZE);
3161 * alignment of hbus is important because hbus's field
3166 * hence kmemleak reports the pointer contained in the hbus buffer
3168 * is tracked by hbus->children) as memory leak (false positive).
3171 * used to allocate the hbus buffer and we can avoid the kmemleak false
3173 * kmemleak to track and scan the hbus buffer.
3175 hbus = kzalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL);
3176 if (!hbus)
3178 hbus->state = hv_pcibus_init;
3179 hbus->wslot_res_allocated = -1;
3209 hbus->sysdata.domain = dom;
3211 hbus->hdev = hdev;
3212 refcount_set(&hbus->remove_lock, 1);
3213 INIT_LIST_HEAD(&hbus->children);
3214 INIT_LIST_HEAD(&hbus->dr_list);
3215 INIT_LIST_HEAD(&hbus->resources_for_children);
3216 spin_lock_init(&hbus->config_lock);
3217 spin_lock_init(&hbus->device_list_lock);
3218 spin_lock_init(&hbus->retarget_msi_interrupt_lock);
3219 init_completion(&hbus->remove_event);
3220 hbus->wq = alloc_ordered_workqueue("hv_pci_%x", 0,
3221 hbus->sysdata.domain);
3222 if (!hbus->wq) {
3228 hv_pci_onchannelcallback, hbus);
3232 hv_set_drvdata(hdev, hbus);
3239 ret = hv_allocate_config_window(hbus);
3243 hbus->cfg_addr = ioremap(hbus->mem_config->start,
3245 if (!hbus->cfg_addr) {
3258 hbus->sysdata.fwnode = irq_domain_alloc_named_fwnode(name);
3260 if (!hbus->sysdata.fwnode) {
3265 ret = hv_pcie_init_irq_domain(hbus);
3277 ret = hv_pci_allocate_bridge_windows(hbus);
3285 prepopulate_bars(hbus);
3287 hbus->state = hv_pcibus_probed;
3289 ret = create_root_hv_pci_bus(hbus);
3296 hv_pci_free_bridge_windows(hbus);
3300 irq_domain_remove(hbus->irq_domain);
3302 irq_domain_free_fwnode(hbus->sysdata.fwnode);
3304 iounmap(hbus->cfg_addr);
3306 hv_free_config_window(hbus);
3310 destroy_workqueue(hbus->wq);
3312 hv_put_dom_num(hbus->sysdata.domain);
3314 kfree(hbus);
3320 struct hv_pcibus_device *hbus = hv_get_drvdata(hdev);
3342 spin_lock_irqsave(&hbus->device_list_lock, flags);
3343 list_for_each_entry_safe(hpdev, tmp, &hbus->children, list_entry)
3345 spin_unlock_irqrestore(&hbus->device_list_lock, flags);
3393 struct hv_pcibus_device *hbus;
3396 hbus = hv_get_drvdata(hdev);
3397 if (hbus->state == hv_pcibus_installed) {
3399 hbus->state = hv_pcibus_removing;
3401 destroy_workqueue(hbus->wq);
3402 hbus->wq = NULL;
3405 * on hbus-wq. We can't race with hv_pci_devices_present()
3411 pci_stop_root_bus(hbus->pci_bus);
3412 hv_pci_remove_slots(hbus);
3413 pci_remove_root_bus(hbus->pci_bus);
3421 iounmap(hbus->cfg_addr);
3422 hv_free_config_window(hbus);
3423 pci_free_resource_list(&hbus->resources_for_children);
3424 hv_pci_free_bridge_windows(hbus);
3425 irq_domain_remove(hbus->irq_domain);
3426 irq_domain_free_fwnode(hbus->sysdata.fwnode);
3427 put_hvpcibus(hbus);
3428 wait_for_completion(&hbus->remove_event);
3430 hv_put_dom_num(hbus->sysdata.domain);
3432 kfree(hbus);
3438 struct hv_pcibus_device *hbus = hv_get_drvdata(hdev);
3448 * items onto hbus->wq in hv_pci_devices_present() and
3455 * callback tasklet, sets hbus->state to hv_pcibus_removing, and
3458 * hbus->wq and safely closes the vmbus channel.
3462 /* Change the hbus state to prevent new work items. */
3463 old_state = hbus->state;
3464 if (hbus->state == hv_pcibus_installed)
3465 hbus->state = hv_pcibus_removing;
3472 flush_workqueue(hbus->wq);
3506 static void hv_pci_restore_msi_state(struct hv_pcibus_device *hbus)
3508 pci_walk_bus(hbus->pci_bus, hv_pci_restore_msi_msg, NULL);
3513 struct hv_pcibus_device *hbus = hv_get_drvdata(hdev);
3517 hbus->state = hv_pcibus_init;
3520 hv_pci_onchannelcallback, hbus);
3525 version[0] = hbus->protocol_version;
3542 prepopulate_bars(hbus);
3544 hv_pci_restore_msi_state(hbus);
3546 hbus->state = hv_pcibus_installed;