Lines Matching refs:hbus

503 	struct hv_pcibus_device *hbus;  member
543 static struct hv_pci_dev *get_pcichild_wslot(struct hv_pcibus_device *hbus,
634 void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + where; in _hv_pcifront_read_config()
662 spin_lock_irqsave(&hpdev->hbus->config_lock, flags); in _hv_pcifront_read_config()
664 writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr); in _hv_pcifront_read_config()
684 spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); in _hv_pcifront_read_config()
686 dev_err(&hpdev->hbus->hdev->device, in _hv_pcifront_read_config()
695 void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + in hv_pcifront_get_vendor_id()
698 spin_lock_irqsave(&hpdev->hbus->config_lock, flags); in hv_pcifront_get_vendor_id()
701 writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr); in hv_pcifront_get_vendor_id()
711 spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); in hv_pcifront_get_vendor_id()
727 void __iomem *addr = hpdev->hbus->cfg_addr + CFG_PAGE_OFFSET + where; in _hv_pcifront_write_config()
733 spin_lock_irqsave(&hpdev->hbus->config_lock, flags); in _hv_pcifront_write_config()
735 writel(hpdev->desc.win_slot.slot, hpdev->hbus->cfg_addr); in _hv_pcifront_write_config()
755 spin_unlock_irqrestore(&hpdev->hbus->config_lock, flags); in _hv_pcifront_write_config()
757 dev_err(&hpdev->hbus->hdev->device, in _hv_pcifront_write_config()
776 struct hv_pcibus_device *hbus = in hv_pcifront_read_config() local
780 hpdev = get_pcichild_wslot(hbus, devfn_to_wslot(devfn)); in hv_pcifront_read_config()
804 struct hv_pcibus_device *hbus = in hv_pcifront_write_config() local
808 hpdev = get_pcichild_wslot(hbus, devfn_to_wslot(devfn)); in hv_pcifront_write_config()
840 vmbus_sendpacket(hpdev->hbus->hdev->channel, int_pkt, sizeof(*int_pkt), in hv_int_desc_free()
859 struct hv_pcibus_device *hbus; in hv_msi_free() local
867 hbus = info->data; in hv_msi_free()
873 hpdev = get_pcichild_wslot(hbus, devfn_to_wslot(pdev->devfn)); in hv_msi_free()
911 struct hv_pcibus_device *hbus; in hv_irq_unmask() local
924 hbus = container_of(pbus->sysdata, struct hv_pcibus_device, sysdata); in hv_irq_unmask()
926 spin_lock_irqsave(&hbus->retarget_msi_interrupt_lock, flags); in hv_irq_unmask()
928 params = &hbus->retarget_msi_interrupt_params; in hv_irq_unmask()
934 params->device_id = (hbus->hdev->dev_instance.b[5] << 24) | in hv_irq_unmask()
935 (hbus->hdev->dev_instance.b[4] << 16) | in hv_irq_unmask()
936 (hbus->hdev->dev_instance.b[7] << 8) | in hv_irq_unmask()
937 (hbus->hdev->dev_instance.b[6] & 0xf8) | in hv_irq_unmask()
971 dev_err(&hbus->hdev->device, in hv_irq_unmask()
991 spin_unlock_irqrestore(&hbus->retarget_msi_interrupt_lock, flags); in hv_irq_unmask()
994 dev_err(&hbus->hdev->device, in hv_irq_unmask()
1076 struct hv_pcibus_device *hbus; in hv_compose_msi_msg() local
1098 hbus = container_of(pbus->sysdata, struct hv_pcibus_device, sysdata); in hv_compose_msi_msg()
1099 hpdev = get_pcichild_wslot(hbus, devfn_to_wslot(pdev->devfn)); in hv_compose_msi_msg()
1139 dev_err(&hbus->hdev->device, in hv_compose_msi_msg()
1144 ret = vmbus_sendpacket(hpdev->hbus->hdev->channel, &ctxt.int_pkts, in hv_compose_msi_msg()
1149 dev_err(&hbus->hdev->device, in hv_compose_msi_msg()
1162 dev_err_once(&hbus->hdev->device, in hv_compose_msi_msg()
1178 if (hbus->hdev->channel->target_cpu == smp_processor_id()) in hv_compose_msi_msg()
1179 hv_pci_onchannelcallback(hbus); in hv_compose_msi_msg()
1184 dev_err_once(&hbus->hdev->device, in hv_compose_msi_msg()
1193 dev_err(&hbus->hdev->device, in hv_compose_msi_msg()
1261 static int hv_pcie_init_irq_domain(struct hv_pcibus_device *hbus) in hv_pcie_init_irq_domain() argument
1263 hbus->msi_info.chip = &hv_msi_irq_chip; in hv_pcie_init_irq_domain()
1264 hbus->msi_info.ops = &hv_msi_ops; in hv_pcie_init_irq_domain()
1265 hbus->msi_info.flags = (MSI_FLAG_USE_DEF_DOM_OPS | in hv_pcie_init_irq_domain()
1268 hbus->msi_info.handler = handle_edge_irq; in hv_pcie_init_irq_domain()
1269 hbus->msi_info.handler_name = "edge"; in hv_pcie_init_irq_domain()
1270 hbus->msi_info.data = hbus; in hv_pcie_init_irq_domain()
1271 hbus->irq_domain = pci_msi_create_irq_domain(hbus->sysdata.fwnode, in hv_pcie_init_irq_domain()
1272 &hbus->msi_info, in hv_pcie_init_irq_domain()
1274 if (!hbus->irq_domain) { in hv_pcie_init_irq_domain()
1275 dev_err(&hbus->hdev->device, in hv_pcie_init_irq_domain()
1307 static void survey_child_resources(struct hv_pcibus_device *hbus) in survey_child_resources() argument
1317 event = xchg(&hbus->survey_event, NULL); in survey_child_resources()
1322 if (hbus->low_mmio_space || hbus->high_mmio_space) { in survey_child_resources()
1327 spin_lock_irqsave(&hbus->device_list_lock, flags); in survey_child_resources()
1334 list_for_each_entry(hpdev, &hbus->children, list_entry) { in survey_child_resources()
1337 dev_err(&hbus->hdev->device, in survey_child_resources()
1356 hbus->high_mmio_space += bar_size; in survey_child_resources()
1358 hbus->low_mmio_space += bar_size; in survey_child_resources()
1363 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in survey_child_resources()
1379 static void prepopulate_bars(struct hv_pcibus_device *hbus) in prepopulate_bars() argument
1393 if (hbus->low_mmio_space) { in prepopulate_bars()
1394 low_size = 1ULL << (63 - __builtin_clzll(hbus->low_mmio_space)); in prepopulate_bars()
1395 low_base = hbus->low_mmio_res->start; in prepopulate_bars()
1398 if (hbus->high_mmio_space) { in prepopulate_bars()
1400 (63 - __builtin_clzll(hbus->high_mmio_space)); in prepopulate_bars()
1401 high_base = hbus->high_mmio_res->start; in prepopulate_bars()
1404 spin_lock_irqsave(&hbus->device_list_lock, flags); in prepopulate_bars()
1408 list_for_each_entry(hpdev, &hbus->children, list_entry) { in prepopulate_bars()
1461 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in prepopulate_bars()
1473 static void hv_pci_assign_slots(struct hv_pcibus_device *hbus) in hv_pci_assign_slots() argument
1479 list_for_each_entry(hpdev, &hbus->children, list_entry) { in hv_pci_assign_slots()
1485 hpdev->pci_slot = pci_create_slot(hbus->pci_bus, slot_nr, in hv_pci_assign_slots()
1500 static int create_root_hv_pci_bus(struct hv_pcibus_device *hbus) in create_root_hv_pci_bus() argument
1503 hbus->pci_bus = pci_create_root_bus(&hbus->hdev->device, in create_root_hv_pci_bus()
1506 &hbus->sysdata, in create_root_hv_pci_bus()
1507 &hbus->resources_for_children); in create_root_hv_pci_bus()
1508 if (!hbus->pci_bus) in create_root_hv_pci_bus()
1511 hbus->pci_bus->msi = &hbus->msi_chip; in create_root_hv_pci_bus()
1512 hbus->pci_bus->msi->dev = &hbus->hdev->device; in create_root_hv_pci_bus()
1515 pci_scan_child_bus(hbus->pci_bus); in create_root_hv_pci_bus()
1516 pci_bus_assign_resources(hbus->pci_bus); in create_root_hv_pci_bus()
1517 hv_pci_assign_slots(hbus); in create_root_hv_pci_bus()
1518 pci_bus_add_devices(hbus->pci_bus); in create_root_hv_pci_bus()
1520 hbus->state = hv_pcibus_installed; in create_root_hv_pci_bus()
1547 dev_err(&completion->hpdev->hbus->hdev->device, in q_resource_requirements()
1571 static struct hv_pci_dev *new_pcichild_device(struct hv_pcibus_device *hbus, in new_pcichild_device() argument
1588 hpdev->hbus = hbus; in new_pcichild_device()
1599 ret = vmbus_sendpacket(hbus->hdev->channel, res_req, in new_pcichild_device()
1607 if (wait_for_response(hbus->hdev, &comp_pkt.host_event)) in new_pcichild_device()
1613 spin_lock_irqsave(&hbus->device_list_lock, flags); in new_pcichild_device()
1615 list_add_tail(&hpdev->list_entry, &hbus->children); in new_pcichild_device()
1616 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in new_pcichild_device()
1637 static struct hv_pci_dev *get_pcichild_wslot(struct hv_pcibus_device *hbus, in get_pcichild_wslot() argument
1643 spin_lock_irqsave(&hbus->device_list_lock, flags); in get_pcichild_wslot()
1644 list_for_each_entry(iter, &hbus->children, list_entry) { in get_pcichild_wslot()
1651 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in get_pcichild_wslot()
1685 struct hv_pcibus_device *hbus; in pci_devices_present_work() local
1692 hbus = dr_wrk->bus; in pci_devices_present_work()
1698 spin_lock_irqsave(&hbus->device_list_lock, flags); in pci_devices_present_work()
1699 while (!list_empty(&hbus->dr_list)) { in pci_devices_present_work()
1700 dr = list_first_entry(&hbus->dr_list, struct hv_dr_state, in pci_devices_present_work()
1705 if (!list_empty(&hbus->dr_list)) { in pci_devices_present_work()
1710 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in pci_devices_present_work()
1713 put_hvpcibus(hbus); in pci_devices_present_work()
1718 spin_lock_irqsave(&hbus->device_list_lock, flags); in pci_devices_present_work()
1719 list_for_each_entry(hpdev, &hbus->children, list_entry) { in pci_devices_present_work()
1722 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in pci_devices_present_work()
1729 spin_lock_irqsave(&hbus->device_list_lock, flags); in pci_devices_present_work()
1730 list_for_each_entry(hpdev, &hbus->children, list_entry) { in pci_devices_present_work()
1739 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in pci_devices_present_work()
1742 hpdev = new_pcichild_device(hbus, new_desc); in pci_devices_present_work()
1744 dev_err(&hbus->hdev->device, in pci_devices_present_work()
1750 spin_lock_irqsave(&hbus->device_list_lock, flags); in pci_devices_present_work()
1753 list_for_each_entry(hpdev, &hbus->children, list_entry) { in pci_devices_present_work()
1762 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in pci_devices_present_work()
1772 switch (hbus->state) { in pci_devices_present_work()
1779 pci_scan_child_bus(hbus->pci_bus); in pci_devices_present_work()
1780 hv_pci_assign_slots(hbus); in pci_devices_present_work()
1786 survey_child_resources(hbus); in pci_devices_present_work()
1793 put_hvpcibus(hbus); in pci_devices_present_work()
1805 static void hv_pci_devices_present(struct hv_pcibus_device *hbus, in hv_pci_devices_present() argument
1826 dr_wrk->bus = hbus; in hv_pci_devices_present()
1834 spin_lock_irqsave(&hbus->device_list_lock, flags); in hv_pci_devices_present()
1840 pending_dr = !list_empty(&hbus->dr_list); in hv_pci_devices_present()
1841 list_add_tail(&dr->list_entry, &hbus->dr_list); in hv_pci_devices_present()
1842 spin_unlock_irqrestore(&hbus->device_list_lock, flags); in hv_pci_devices_present()
1847 get_hvpcibus(hbus); in hv_pci_devices_present()
1848 queue_work(hbus->wq, &dr_wrk->wrk); in hv_pci_devices_present()
1884 pdev = pci_get_domain_bus_and_slot(hpdev->hbus->sysdata.domain, 0, in hv_eject_device_work()
1893 spin_lock_irqsave(&hpdev->hbus->device_list_lock, flags); in hv_eject_device_work()
1895 spin_unlock_irqrestore(&hpdev->hbus->device_list_lock, flags); in hv_eject_device_work()
1904 vmbus_sendpacket(hpdev->hbus->hdev->channel, ejct_pkt, in hv_eject_device_work()
1910 put_hvpcibus(hpdev->hbus); in hv_eject_device_work()
1926 get_hvpcibus(hpdev->hbus); in hv_pci_eject_device()
1927 queue_work(hpdev->hbus->wq, &hpdev->wrk); in hv_pci_eject_device()
1941 struct hv_pcibus_device *hbus = context; in hv_pci_onchannelcallback() local
1959 ret = vmbus_recvpacket_raw(hbus->hdev->channel, buffer, in hv_pci_onchannelcallback()
2009 dev_err(&hbus->hdev->device, in hv_pci_onchannelcallback()
2014 hv_pci_devices_present(hbus, bus_rel); in hv_pci_onchannelcallback()
2020 hpdev = get_pcichild_wslot(hbus, in hv_pci_onchannelcallback()
2029 dev_warn(&hbus->hdev->device, in hv_pci_onchannelcallback()
2037 dev_err(&hbus->hdev->device, in hv_pci_onchannelcallback()
2136 static void hv_pci_free_bridge_windows(struct hv_pcibus_device *hbus) in hv_pci_free_bridge_windows() argument
2143 if (hbus->low_mmio_space && hbus->low_mmio_res) { in hv_pci_free_bridge_windows()
2144 hbus->low_mmio_res->flags |= IORESOURCE_BUSY; in hv_pci_free_bridge_windows()
2145 vmbus_free_mmio(hbus->low_mmio_res->start, in hv_pci_free_bridge_windows()
2146 resource_size(hbus->low_mmio_res)); in hv_pci_free_bridge_windows()
2149 if (hbus->high_mmio_space && hbus->high_mmio_res) { in hv_pci_free_bridge_windows()
2150 hbus->high_mmio_res->flags |= IORESOURCE_BUSY; in hv_pci_free_bridge_windows()
2151 vmbus_free_mmio(hbus->high_mmio_res->start, in hv_pci_free_bridge_windows()
2152 resource_size(hbus->high_mmio_res)); in hv_pci_free_bridge_windows()
2181 static int hv_pci_allocate_bridge_windows(struct hv_pcibus_device *hbus) in hv_pci_allocate_bridge_windows() argument
2186 if (hbus->low_mmio_space) { in hv_pci_allocate_bridge_windows()
2187 align = 1ULL << (63 - __builtin_clzll(hbus->low_mmio_space)); in hv_pci_allocate_bridge_windows()
2188 ret = vmbus_allocate_mmio(&hbus->low_mmio_res, hbus->hdev, 0, in hv_pci_allocate_bridge_windows()
2190 hbus->low_mmio_space, in hv_pci_allocate_bridge_windows()
2193 dev_err(&hbus->hdev->device, in hv_pci_allocate_bridge_windows()
2195 hbus->low_mmio_space); in hv_pci_allocate_bridge_windows()
2200 hbus->low_mmio_res->flags |= IORESOURCE_WINDOW; in hv_pci_allocate_bridge_windows()
2201 hbus->low_mmio_res->flags &= ~IORESOURCE_BUSY; in hv_pci_allocate_bridge_windows()
2202 pci_add_resource(&hbus->resources_for_children, in hv_pci_allocate_bridge_windows()
2203 hbus->low_mmio_res); in hv_pci_allocate_bridge_windows()
2206 if (hbus->high_mmio_space) { in hv_pci_allocate_bridge_windows()
2207 align = 1ULL << (63 - __builtin_clzll(hbus->high_mmio_space)); in hv_pci_allocate_bridge_windows()
2208 ret = vmbus_allocate_mmio(&hbus->high_mmio_res, hbus->hdev, in hv_pci_allocate_bridge_windows()
2210 hbus->high_mmio_space, align, in hv_pci_allocate_bridge_windows()
2213 dev_err(&hbus->hdev->device, in hv_pci_allocate_bridge_windows()
2215 hbus->high_mmio_space); in hv_pci_allocate_bridge_windows()
2220 hbus->high_mmio_res->flags |= IORESOURCE_WINDOW; in hv_pci_allocate_bridge_windows()
2221 hbus->high_mmio_res->flags &= ~IORESOURCE_BUSY; in hv_pci_allocate_bridge_windows()
2222 pci_add_resource(&hbus->resources_for_children, in hv_pci_allocate_bridge_windows()
2223 hbus->high_mmio_res); in hv_pci_allocate_bridge_windows()
2229 if (hbus->low_mmio_res) { in hv_pci_allocate_bridge_windows()
2230 vmbus_free_mmio(hbus->low_mmio_res->start, in hv_pci_allocate_bridge_windows()
2231 resource_size(hbus->low_mmio_res)); in hv_pci_allocate_bridge_windows()
2246 static int hv_allocate_config_window(struct hv_pcibus_device *hbus) in hv_allocate_config_window() argument
2254 ret = vmbus_allocate_mmio(&hbus->mem_config, hbus->hdev, 0, -1, in hv_allocate_config_window()
2267 hbus->mem_config->flags |= IORESOURCE_BUSY; in hv_allocate_config_window()
2272 static void hv_free_config_window(struct hv_pcibus_device *hbus) in hv_free_config_window() argument
2274 vmbus_free_mmio(hbus->mem_config->start, PCI_CONFIG_MMIO_LENGTH); in hv_free_config_window()
2285 struct hv_pcibus_device *hbus = hv_get_drvdata(hdev); in hv_pci_enter_d0() local
2306 d0_entry->mmio_base = hbus->mem_config->start; in hv_pci_enter_d0()
2341 struct hv_pcibus_device *hbus = hv_get_drvdata(hdev); in hv_pci_query_relations() local
2348 if (cmpxchg(&hbus->survey_event, NULL, &comp)) in hv_pci_query_relations()
2381 struct hv_pcibus_device *hbus = hv_get_drvdata(hdev); in hv_send_resources_allocated() local
2401 hpdev = get_pcichild_wslot(hbus, wslot); in hv_send_resources_allocated()
2456 struct hv_pcibus_device *hbus = hv_get_drvdata(hdev); in hv_send_resources_released() local
2463 hpdev = get_pcichild_wslot(hbus, wslot); in hv_send_resources_released()
2482 static void get_hvpcibus(struct hv_pcibus_device *hbus) in get_hvpcibus() argument
2484 refcount_inc(&hbus->remove_lock); in get_hvpcibus()
2487 static void put_hvpcibus(struct hv_pcibus_device *hbus) in put_hvpcibus() argument
2489 if (refcount_dec_and_test(&hbus->remove_lock)) in put_hvpcibus()
2490 complete(&hbus->remove_event); in put_hvpcibus()
2503 struct hv_pcibus_device *hbus; in hv_pci_probe() local
2510 BUILD_BUG_ON(sizeof(*hbus) > PAGE_SIZE); in hv_pci_probe()
2512 hbus = (struct hv_pcibus_device *)get_zeroed_page(GFP_KERNEL); in hv_pci_probe()
2513 if (!hbus) in hv_pci_probe()
2515 hbus->state = hv_pcibus_init; in hv_pci_probe()
2529 hbus->sysdata.domain = hdev->dev_instance.b[9] | in hv_pci_probe()
2532 hbus->hdev = hdev; in hv_pci_probe()
2533 refcount_set(&hbus->remove_lock, 1); in hv_pci_probe()
2534 INIT_LIST_HEAD(&hbus->children); in hv_pci_probe()
2535 INIT_LIST_HEAD(&hbus->dr_list); in hv_pci_probe()
2536 INIT_LIST_HEAD(&hbus->resources_for_children); in hv_pci_probe()
2537 spin_lock_init(&hbus->config_lock); in hv_pci_probe()
2538 spin_lock_init(&hbus->device_list_lock); in hv_pci_probe()
2539 spin_lock_init(&hbus->retarget_msi_interrupt_lock); in hv_pci_probe()
2540 init_completion(&hbus->remove_event); in hv_pci_probe()
2541 hbus->wq = alloc_ordered_workqueue("hv_pci_%x", 0, in hv_pci_probe()
2542 hbus->sysdata.domain); in hv_pci_probe()
2543 if (!hbus->wq) { in hv_pci_probe()
2549 hv_pci_onchannelcallback, hbus); in hv_pci_probe()
2553 hv_set_drvdata(hdev, hbus); in hv_pci_probe()
2559 ret = hv_allocate_config_window(hbus); in hv_pci_probe()
2563 hbus->cfg_addr = ioremap(hbus->mem_config->start, in hv_pci_probe()
2565 if (!hbus->cfg_addr) { in hv_pci_probe()
2572 hbus->sysdata.fwnode = irq_domain_alloc_fwnode(hbus); in hv_pci_probe()
2573 if (!hbus->sysdata.fwnode) { in hv_pci_probe()
2578 ret = hv_pcie_init_irq_domain(hbus); in hv_pci_probe()
2590 ret = hv_pci_allocate_bridge_windows(hbus); in hv_pci_probe()
2598 prepopulate_bars(hbus); in hv_pci_probe()
2600 hbus->state = hv_pcibus_probed; in hv_pci_probe()
2602 ret = create_root_hv_pci_bus(hbus); in hv_pci_probe()
2609 hv_pci_free_bridge_windows(hbus); in hv_pci_probe()
2611 irq_domain_remove(hbus->irq_domain); in hv_pci_probe()
2613 irq_domain_free_fwnode(hbus->sysdata.fwnode); in hv_pci_probe()
2615 iounmap(hbus->cfg_addr); in hv_pci_probe()
2617 hv_free_config_window(hbus); in hv_pci_probe()
2621 destroy_workqueue(hbus->wq); in hv_pci_probe()
2623 free_page((unsigned long)hbus); in hv_pci_probe()
2629 struct hv_pcibus_device *hbus = hv_get_drvdata(hdev); in hv_pci_bus_exit() local
2647 hv_pci_devices_present(hbus, &relations); in hv_pci_bus_exit()
2677 struct hv_pcibus_device *hbus; in hv_pci_remove() local
2679 hbus = hv_get_drvdata(hdev); in hv_pci_remove()
2680 if (hbus->state == hv_pcibus_installed) { in hv_pci_remove()
2683 pci_stop_root_bus(hbus->pci_bus); in hv_pci_remove()
2684 pci_remove_root_bus(hbus->pci_bus); in hv_pci_remove()
2686 hbus->state = hv_pcibus_removed; in hv_pci_remove()
2693 iounmap(hbus->cfg_addr); in hv_pci_remove()
2694 hv_free_config_window(hbus); in hv_pci_remove()
2695 pci_free_resource_list(&hbus->resources_for_children); in hv_pci_remove()
2696 hv_pci_free_bridge_windows(hbus); in hv_pci_remove()
2697 irq_domain_remove(hbus->irq_domain); in hv_pci_remove()
2698 irq_domain_free_fwnode(hbus->sysdata.fwnode); in hv_pci_remove()
2699 put_hvpcibus(hbus); in hv_pci_remove()
2700 wait_for_completion(&hbus->remove_event); in hv_pci_remove()
2701 destroy_workqueue(hbus->wq); in hv_pci_remove()
2702 free_page((unsigned long)hbus); in hv_pci_remove()