Lines Matching refs:vmd
152 static inline unsigned int index_from_irqs(struct vmd_dev *vmd, in index_from_irqs() argument
155 return irqs - vmd->irqs; in index_from_irqs()
170 struct vmd_dev *vmd = irq_data_get_irq_handler_data(data); in vmd_compose_msi_msg() local
175 msg->arch_addr_lo.destid_0_7 = index_from_irqs(vmd, irq); in vmd_compose_msi_msg()
233 static struct vmd_irq_list *vmd_next_irq(struct vmd_dev *vmd, struct msi_desc *desc) in vmd_next_irq() argument
237 if (vmd->msix_count == 1 + vmd->first_vec) in vmd_next_irq()
238 return &vmd->irqs[vmd->first_vec]; in vmd_next_irq()
248 return &vmd->irqs[vmd->first_vec]; in vmd_next_irq()
252 best = vmd->first_vec + 1; in vmd_next_irq()
253 for (i = best; i < vmd->msix_count; i++) in vmd_next_irq()
254 if (vmd->irqs[i].count < vmd->irqs[best].count) in vmd_next_irq()
256 vmd->irqs[best].count++; in vmd_next_irq()
259 return &vmd->irqs[best]; in vmd_next_irq()
269 struct vmd_dev *vmd = domain->host_data; in vmd_msi_alloc() local
280 vmdirq->irq = vmd_next_irq(vmd, desc); in vmd_msi_alloc()
285 handle_untracked_irq, vmd, NULL); in vmd_msi_alloc()
342 static int vmd_create_irq_domain(struct vmd_dev *vmd) in vmd_create_irq_domain() argument
345 .size = vmd->msix_count, in vmd_create_irq_domain()
347 .host_data = vmd, in vmd_create_irq_domain()
351 vmd->sysdata.domain); in vmd_create_irq_domain()
355 vmd->irq_domain = msi_create_parent_irq_domain(&info, in vmd_create_irq_domain()
357 if (!vmd->irq_domain) { in vmd_create_irq_domain()
365 static void vmd_set_msi_remapping(struct vmd_dev *vmd, bool enable) in vmd_set_msi_remapping() argument
369 pci_read_config_word(vmd->dev, PCI_REG_VMCONFIG, ®); in vmd_set_msi_remapping()
372 pci_write_config_word(vmd->dev, PCI_REG_VMCONFIG, reg); in vmd_set_msi_remapping()
375 static void vmd_remove_irq_domain(struct vmd_dev *vmd) in vmd_remove_irq_domain() argument
381 if (!vmd->msix_count) in vmd_remove_irq_domain()
382 vmd_set_msi_remapping(vmd, true); in vmd_remove_irq_domain()
384 if (vmd->irq_domain) { in vmd_remove_irq_domain()
385 struct fwnode_handle *fn = vmd->irq_domain->fwnode; in vmd_remove_irq_domain()
387 irq_domain_remove(vmd->irq_domain); in vmd_remove_irq_domain()
392 static void __iomem *vmd_cfg_addr(struct vmd_dev *vmd, struct pci_bus *bus, in vmd_cfg_addr() argument
395 unsigned int busnr_ecam = bus->number - vmd->busn_start; in vmd_cfg_addr()
398 if (offset + len >= resource_size(&vmd->dev->resource[VMD_CFGBAR])) in vmd_cfg_addr()
401 return vmd->cfgbar + offset; in vmd_cfg_addr()
411 struct vmd_dev *vmd = vmd_from_bus(bus); in vmd_pci_read() local
412 void __iomem *addr = vmd_cfg_addr(vmd, bus, devfn, reg, len); in vmd_pci_read()
417 guard(raw_spinlock_irqsave)(&vmd->cfg_lock); in vmd_pci_read()
441 struct vmd_dev *vmd = vmd_from_bus(bus); in vmd_pci_write() local
442 void __iomem *addr = vmd_cfg_addr(vmd, bus, devfn, reg, len); in vmd_pci_write()
447 guard(raw_spinlock_irqsave)(&vmd->cfg_lock); in vmd_pci_write()
521 static void vmd_domain_reset(struct vmd_dev *vmd) in vmd_domain_reset() argument
523 u16 bus, max_buses = resource_size(&vmd->resources[0]); in vmd_domain_reset()
529 base = vmd->cfgbar + PCIE_ECAM_OFFSET(bus, in vmd_domain_reset()
536 base = vmd->cfgbar + PCIE_ECAM_OFFSET(bus, in vmd_domain_reset()
569 static void vmd_attach_resources(struct vmd_dev *vmd) in vmd_attach_resources() argument
571 vmd->dev->resource[VMD_MEMBAR1].child = &vmd->resources[1]; in vmd_attach_resources()
572 vmd->dev->resource[VMD_MEMBAR2].child = &vmd->resources[2]; in vmd_attach_resources()
575 static void vmd_detach_resources(struct vmd_dev *vmd) in vmd_detach_resources() argument
577 vmd->dev->resource[VMD_MEMBAR1].child = NULL; in vmd_detach_resources()
578 vmd->dev->resource[VMD_MEMBAR2].child = NULL; in vmd_detach_resources()
581 static int vmd_get_phys_offsets(struct vmd_dev *vmd, bool native_hint, in vmd_get_phys_offsets() argument
585 struct pci_dev *dev = vmd->dev; in vmd_get_phys_offsets()
635 static int vmd_get_bus_number_start(struct vmd_dev *vmd) in vmd_get_bus_number_start() argument
637 struct pci_dev *dev = vmd->dev; in vmd_get_bus_number_start()
646 vmd->busn_start = 0; in vmd_get_bus_number_start()
649 vmd->busn_start = 128; in vmd_get_bus_number_start()
652 vmd->busn_start = 224; in vmd_get_bus_number_start()
678 static int vmd_alloc_irqs(struct vmd_dev *vmd) in vmd_alloc_irqs() argument
680 struct pci_dev *dev = vmd->dev; in vmd_alloc_irqs()
683 vmd->msix_count = pci_msix_vec_count(dev); in vmd_alloc_irqs()
684 if (vmd->msix_count < 0) in vmd_alloc_irqs()
687 vmd->msix_count = pci_alloc_irq_vectors(dev, vmd->first_vec + 1, in vmd_alloc_irqs()
688 vmd->msix_count, PCI_IRQ_MSIX); in vmd_alloc_irqs()
689 if (vmd->msix_count < 0) in vmd_alloc_irqs()
690 return vmd->msix_count; in vmd_alloc_irqs()
692 vmd->irqs = devm_kcalloc(&dev->dev, vmd->msix_count, sizeof(*vmd->irqs), in vmd_alloc_irqs()
694 if (!vmd->irqs) in vmd_alloc_irqs()
697 for (i = 0; i < vmd->msix_count; i++) { in vmd_alloc_irqs()
698 err = init_srcu_struct(&vmd->irqs[i].srcu); in vmd_alloc_irqs()
702 INIT_LIST_HEAD(&vmd->irqs[i].irq_list); in vmd_alloc_irqs()
703 vmd->irqs[i].virq = pci_irq_vector(dev, i); in vmd_alloc_irqs()
704 err = devm_request_irq(&dev->dev, vmd->irqs[i].virq, in vmd_alloc_irqs()
706 vmd->name, &vmd->irqs[i]); in vmd_alloc_irqs()
774 static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) in vmd_enable_domain() argument
776 struct pci_sysdata *sd = &vmd->sysdata; in vmd_enable_domain()
795 ret = vmd_get_phys_offsets(vmd, true, &offset[0], &offset[1]); in vmd_enable_domain()
799 ret = vmd_get_phys_offsets(vmd, false, &offset[0], &offset[1]); in vmd_enable_domain()
809 ret = vmd_get_bus_number_start(vmd); in vmd_enable_domain()
814 res = &vmd->dev->resource[VMD_CFGBAR]; in vmd_enable_domain()
815 vmd->resources[0] = (struct resource) { in vmd_enable_domain()
817 .start = vmd->busn_start, in vmd_enable_domain()
818 .end = vmd->busn_start + (resource_size(res) >> 20) - 1, in vmd_enable_domain()
839 res = &vmd->dev->resource[VMD_MEMBAR1]; in vmd_enable_domain()
844 vmd->resources[1] = (struct resource) { in vmd_enable_domain()
852 res = &vmd->dev->resource[VMD_MEMBAR2]; in vmd_enable_domain()
857 vmd->resources[2] = (struct resource) { in vmd_enable_domain()
873 ret = vmd_alloc_irqs(vmd); in vmd_enable_domain()
877 vmd_set_msi_remapping(vmd, true); in vmd_enable_domain()
879 ret = vmd_create_irq_domain(vmd); in vmd_enable_domain()
883 vmd_set_msi_remapping(vmd, false); in vmd_enable_domain()
886 pci_add_resource(&resources, &vmd->resources[0]); in vmd_enable_domain()
887 pci_add_resource_offset(&resources, &vmd->resources[1], offset[0]); in vmd_enable_domain()
888 pci_add_resource_offset(&resources, &vmd->resources[2], offset[1]); in vmd_enable_domain()
890 sd->vmd_dev = vmd->dev; in vmd_enable_domain()
902 sd->node = pcibus_to_node(vmd->dev->bus); in vmd_enable_domain()
904 vmd->bus = pci_create_root_bus(&vmd->dev->dev, vmd->busn_start, in vmd_enable_domain()
906 if (!vmd->bus) { in vmd_enable_domain()
909 vmd_remove_irq_domain(vmd); in vmd_enable_domain()
913 vmd_copy_host_bridge_flags(pci_find_host_bridge(vmd->dev->bus), in vmd_enable_domain()
914 to_pci_host_bridge(vmd->bus->bridge)); in vmd_enable_domain()
916 vmd_attach_resources(vmd); in vmd_enable_domain()
917 if (vmd->irq_domain) in vmd_enable_domain()
918 dev_set_msi_domain(&vmd->bus->dev, vmd->irq_domain); in vmd_enable_domain()
920 dev_set_msi_domain(&vmd->bus->dev, in vmd_enable_domain()
921 dev_get_msi_domain(&vmd->dev->dev)); in vmd_enable_domain()
923 WARN(sysfs_create_link(&vmd->dev->dev.kobj, &vmd->bus->dev.kobj, in vmd_enable_domain()
928 pci_scan_child_bus(vmd->bus); in vmd_enable_domain()
929 vmd_domain_reset(vmd); in vmd_enable_domain()
938 list_for_each_entry(child, &vmd->bus->children, node) { in vmd_enable_domain()
950 pci_assign_unassigned_bus_resources(vmd->bus); in vmd_enable_domain()
952 pci_walk_bus(vmd->bus, vmd_pm_enable_quirk, &features); in vmd_enable_domain()
959 list_for_each_entry(child, &vmd->bus->children, node) in vmd_enable_domain()
962 pci_bus_add_devices(vmd->bus); in vmd_enable_domain()
971 struct vmd_dev *vmd; in vmd_probe() local
995 vmd = devm_kzalloc(&dev->dev, sizeof(*vmd), GFP_KERNEL); in vmd_probe()
996 if (!vmd) in vmd_probe()
999 vmd->dev = dev; in vmd_probe()
1000 vmd->sysdata.domain = PCI_DOMAIN_NR_NOT_SET; in vmd_probe()
1001 vmd->instance = ida_alloc(&vmd_instance_ida, GFP_KERNEL); in vmd_probe()
1002 if (vmd->instance < 0) in vmd_probe()
1003 return vmd->instance; in vmd_probe()
1005 vmd->name = devm_kasprintf(&dev->dev, GFP_KERNEL, "vmd%d", in vmd_probe()
1006 vmd->instance); in vmd_probe()
1007 if (!vmd->name) { in vmd_probe()
1016 vmd->cfgbar = pcim_iomap(dev, VMD_CFGBAR, 0); in vmd_probe()
1017 if (!vmd->cfgbar) { in vmd_probe()
1030 vmd->first_vec = 1; in vmd_probe()
1032 raw_spin_lock_init(&vmd->cfg_lock); in vmd_probe()
1033 pci_set_drvdata(dev, vmd); in vmd_probe()
1034 err = vmd_enable_domain(vmd, features); in vmd_probe()
1038 dev_info(&vmd->dev->dev, "Bound to PCI domain %04x\n", in vmd_probe()
1039 vmd->sysdata.domain); in vmd_probe()
1043 ida_free(&vmd_instance_ida, vmd->instance); in vmd_probe()
1047 static void vmd_cleanup_srcu(struct vmd_dev *vmd) in vmd_cleanup_srcu() argument
1051 for (i = 0; i < vmd->msix_count; i++) in vmd_cleanup_srcu()
1052 cleanup_srcu_struct(&vmd->irqs[i].srcu); in vmd_cleanup_srcu()
1057 struct vmd_dev *vmd = pci_get_drvdata(dev); in vmd_remove() local
1059 pci_stop_root_bus(vmd->bus); in vmd_remove()
1060 sysfs_remove_link(&vmd->dev->dev.kobj, "domain"); in vmd_remove()
1061 pci_remove_root_bus(vmd->bus); in vmd_remove()
1062 vmd_cleanup_srcu(vmd); in vmd_remove()
1063 vmd_detach_resources(vmd); in vmd_remove()
1064 vmd_remove_irq_domain(vmd); in vmd_remove()
1065 ida_free(&vmd_instance_ida, vmd->instance); in vmd_remove()
1066 pci_bus_release_emul_domain_nr(vmd->sysdata.domain); in vmd_remove()
1071 struct vmd_dev *vmd = pci_get_drvdata(dev); in vmd_shutdown() local
1073 vmd_remove_irq_domain(vmd); in vmd_shutdown()
1080 struct vmd_dev *vmd = pci_get_drvdata(pdev); in vmd_suspend() local
1083 for (i = 0; i < vmd->msix_count; i++) in vmd_suspend()
1084 devm_free_irq(dev, vmd->irqs[i].virq, &vmd->irqs[i]); in vmd_suspend()
1092 struct vmd_dev *vmd = pci_get_drvdata(pdev); in vmd_resume() local
1095 vmd_set_msi_remapping(vmd, !!vmd->irq_domain); in vmd_resume()
1097 for (i = 0; i < vmd->msix_count; i++) { in vmd_resume()
1098 err = devm_request_irq(dev, vmd->irqs[i].virq, in vmd_resume()
1100 vmd->name, &vmd->irqs[i]); in vmd_resume()