Lines Matching refs:vmd
149 static inline unsigned int index_from_irqs(struct vmd_dev *vmd, in index_from_irqs() argument
152 return irqs - vmd->irqs; in index_from_irqs()
167 struct vmd_dev *vmd = irq_data_get_irq_handler_data(data); in vmd_compose_msi_msg() local
172 msg->arch_addr_lo.destid_0_7 = index_from_irqs(vmd, irq); in vmd_compose_msi_msg()
235 static struct vmd_irq_list *vmd_next_irq(struct vmd_dev *vmd, struct msi_desc *desc) in vmd_next_irq() argument
240 if (vmd->msix_count == 1 + vmd->first_vec) in vmd_next_irq()
241 return &vmd->irqs[vmd->first_vec]; in vmd_next_irq()
251 return &vmd->irqs[vmd->first_vec]; in vmd_next_irq()
255 best = vmd->first_vec + 1; in vmd_next_irq()
256 for (i = best; i < vmd->msix_count; i++) in vmd_next_irq()
257 if (vmd->irqs[i].count < vmd->irqs[best].count) in vmd_next_irq()
259 vmd->irqs[best].count++; in vmd_next_irq()
262 return &vmd->irqs[best]; in vmd_next_irq()
270 struct vmd_dev *vmd = vmd_from_bus(msi_desc_to_pci_dev(desc)->bus); in vmd_msi_init() local
277 vmdirq->irq = vmd_next_irq(vmd, desc); in vmd_msi_init()
281 handle_untracked_irq, vmd, NULL); in vmd_msi_init()
305 struct vmd_dev *vmd = vmd_from_bus(pdev->bus); in vmd_msi_prepare() local
307 if (nvec > vmd->msix_count) in vmd_msi_prepare()
308 return vmd->msix_count; in vmd_msi_prepare()
334 static void vmd_set_msi_remapping(struct vmd_dev *vmd, bool enable) in vmd_set_msi_remapping() argument
338 pci_read_config_word(vmd->dev, PCI_REG_VMCONFIG, ®); in vmd_set_msi_remapping()
341 pci_write_config_word(vmd->dev, PCI_REG_VMCONFIG, reg); in vmd_set_msi_remapping()
344 static int vmd_create_irq_domain(struct vmd_dev *vmd) in vmd_create_irq_domain() argument
348 fn = irq_domain_alloc_named_id_fwnode("VMD-MSI", vmd->sysdata.domain); in vmd_create_irq_domain()
352 vmd->irq_domain = pci_msi_create_irq_domain(fn, &vmd_msi_domain_info, NULL); in vmd_create_irq_domain()
353 if (!vmd->irq_domain) { in vmd_create_irq_domain()
361 static void vmd_remove_irq_domain(struct vmd_dev *vmd) in vmd_remove_irq_domain() argument
367 if (!vmd->msix_count) in vmd_remove_irq_domain()
368 vmd_set_msi_remapping(vmd, true); in vmd_remove_irq_domain()
370 if (vmd->irq_domain) { in vmd_remove_irq_domain()
371 struct fwnode_handle *fn = vmd->irq_domain->fwnode; in vmd_remove_irq_domain()
373 irq_domain_remove(vmd->irq_domain); in vmd_remove_irq_domain()
378 static void __iomem *vmd_cfg_addr(struct vmd_dev *vmd, struct pci_bus *bus, in vmd_cfg_addr() argument
381 unsigned int busnr_ecam = bus->number - vmd->busn_start; in vmd_cfg_addr()
384 if (offset + len >= resource_size(&vmd->dev->resource[VMD_CFGBAR])) in vmd_cfg_addr()
387 return vmd->cfgbar + offset; in vmd_cfg_addr()
397 struct vmd_dev *vmd = vmd_from_bus(bus); in vmd_pci_read() local
398 void __iomem *addr = vmd_cfg_addr(vmd, bus, devfn, reg, len); in vmd_pci_read()
405 spin_lock_irqsave(&vmd->cfg_lock, flags); in vmd_pci_read()
420 spin_unlock_irqrestore(&vmd->cfg_lock, flags); in vmd_pci_read()
432 struct vmd_dev *vmd = vmd_from_bus(bus); in vmd_pci_write() local
433 void __iomem *addr = vmd_cfg_addr(vmd, bus, devfn, reg, len); in vmd_pci_write()
440 spin_lock_irqsave(&vmd->cfg_lock, flags); in vmd_pci_write()
458 spin_unlock_irqrestore(&vmd->cfg_lock, flags); in vmd_pci_write()
517 static void vmd_domain_reset(struct vmd_dev *vmd) in vmd_domain_reset() argument
519 u16 bus, max_buses = resource_size(&vmd->resources[0]); in vmd_domain_reset()
525 base = vmd->cfgbar + PCIE_ECAM_OFFSET(bus, in vmd_domain_reset()
532 base = vmd->cfgbar + PCIE_ECAM_OFFSET(bus, in vmd_domain_reset()
565 static void vmd_attach_resources(struct vmd_dev *vmd) in vmd_attach_resources() argument
567 vmd->dev->resource[VMD_MEMBAR1].child = &vmd->resources[1]; in vmd_attach_resources()
568 vmd->dev->resource[VMD_MEMBAR2].child = &vmd->resources[2]; in vmd_attach_resources()
571 static void vmd_detach_resources(struct vmd_dev *vmd) in vmd_detach_resources() argument
573 vmd->dev->resource[VMD_MEMBAR1].child = NULL; in vmd_detach_resources()
574 vmd->dev->resource[VMD_MEMBAR2].child = NULL; in vmd_detach_resources()
593 static int vmd_get_phys_offsets(struct vmd_dev *vmd, bool native_hint, in vmd_get_phys_offsets() argument
597 struct pci_dev *dev = vmd->dev; in vmd_get_phys_offsets()
647 static int vmd_get_bus_number_start(struct vmd_dev *vmd) in vmd_get_bus_number_start() argument
649 struct pci_dev *dev = vmd->dev; in vmd_get_bus_number_start()
658 vmd->busn_start = 0; in vmd_get_bus_number_start()
661 vmd->busn_start = 128; in vmd_get_bus_number_start()
664 vmd->busn_start = 224; in vmd_get_bus_number_start()
690 static int vmd_alloc_irqs(struct vmd_dev *vmd) in vmd_alloc_irqs() argument
692 struct pci_dev *dev = vmd->dev; in vmd_alloc_irqs()
695 vmd->msix_count = pci_msix_vec_count(dev); in vmd_alloc_irqs()
696 if (vmd->msix_count < 0) in vmd_alloc_irqs()
699 vmd->msix_count = pci_alloc_irq_vectors(dev, vmd->first_vec + 1, in vmd_alloc_irqs()
700 vmd->msix_count, PCI_IRQ_MSIX); in vmd_alloc_irqs()
701 if (vmd->msix_count < 0) in vmd_alloc_irqs()
702 return vmd->msix_count; in vmd_alloc_irqs()
704 vmd->irqs = devm_kcalloc(&dev->dev, vmd->msix_count, sizeof(*vmd->irqs), in vmd_alloc_irqs()
706 if (!vmd->irqs) in vmd_alloc_irqs()
709 for (i = 0; i < vmd->msix_count; i++) { in vmd_alloc_irqs()
710 err = init_srcu_struct(&vmd->irqs[i].srcu); in vmd_alloc_irqs()
714 INIT_LIST_HEAD(&vmd->irqs[i].irq_list); in vmd_alloc_irqs()
715 vmd->irqs[i].virq = pci_irq_vector(dev, i); in vmd_alloc_irqs()
716 err = devm_request_irq(&dev->dev, vmd->irqs[i].virq, in vmd_alloc_irqs()
718 vmd->name, &vmd->irqs[i]); in vmd_alloc_irqs()
781 static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) in vmd_enable_domain() argument
783 struct pci_sysdata *sd = &vmd->sysdata; in vmd_enable_domain()
802 ret = vmd_get_phys_offsets(vmd, true, &offset[0], &offset[1]); in vmd_enable_domain()
806 ret = vmd_get_phys_offsets(vmd, false, &offset[0], &offset[1]); in vmd_enable_domain()
816 ret = vmd_get_bus_number_start(vmd); in vmd_enable_domain()
821 res = &vmd->dev->resource[VMD_CFGBAR]; in vmd_enable_domain()
822 vmd->resources[0] = (struct resource) { in vmd_enable_domain()
824 .start = vmd->busn_start, in vmd_enable_domain()
825 .end = vmd->busn_start + (resource_size(res) >> 20) - 1, in vmd_enable_domain()
846 res = &vmd->dev->resource[VMD_MEMBAR1]; in vmd_enable_domain()
851 vmd->resources[1] = (struct resource) { in vmd_enable_domain()
859 res = &vmd->dev->resource[VMD_MEMBAR2]; in vmd_enable_domain()
864 vmd->resources[2] = (struct resource) { in vmd_enable_domain()
872 sd->vmd_dev = vmd->dev; in vmd_enable_domain()
877 sd->node = pcibus_to_node(vmd->dev->bus); in vmd_enable_domain()
887 ret = vmd_alloc_irqs(vmd); in vmd_enable_domain()
891 vmd_set_msi_remapping(vmd, true); in vmd_enable_domain()
893 ret = vmd_create_irq_domain(vmd); in vmd_enable_domain()
901 irq_domain_update_bus_token(vmd->irq_domain, DOMAIN_BUS_VMD_MSI); in vmd_enable_domain()
903 vmd_set_msi_remapping(vmd, false); in vmd_enable_domain()
906 pci_add_resource(&resources, &vmd->resources[0]); in vmd_enable_domain()
907 pci_add_resource_offset(&resources, &vmd->resources[1], offset[0]); in vmd_enable_domain()
908 pci_add_resource_offset(&resources, &vmd->resources[2], offset[1]); in vmd_enable_domain()
910 vmd->bus = pci_create_root_bus(&vmd->dev->dev, vmd->busn_start, in vmd_enable_domain()
912 if (!vmd->bus) { in vmd_enable_domain()
914 vmd_remove_irq_domain(vmd); in vmd_enable_domain()
918 vmd_copy_host_bridge_flags(pci_find_host_bridge(vmd->dev->bus), in vmd_enable_domain()
919 to_pci_host_bridge(vmd->bus->bridge)); in vmd_enable_domain()
921 vmd_attach_resources(vmd); in vmd_enable_domain()
922 if (vmd->irq_domain) in vmd_enable_domain()
923 dev_set_msi_domain(&vmd->bus->dev, vmd->irq_domain); in vmd_enable_domain()
925 dev_set_msi_domain(&vmd->bus->dev, in vmd_enable_domain()
926 dev_get_msi_domain(&vmd->dev->dev)); in vmd_enable_domain()
930 pci_scan_child_bus(vmd->bus); in vmd_enable_domain()
931 vmd_domain_reset(vmd); in vmd_enable_domain()
940 list_for_each_entry(child, &vmd->bus->children, node) { in vmd_enable_domain()
952 pci_assign_unassigned_bus_resources(vmd->bus); in vmd_enable_domain()
954 pci_walk_bus(vmd->bus, vmd_pm_enable_quirk, &features); in vmd_enable_domain()
961 list_for_each_entry(child, &vmd->bus->children, node) in vmd_enable_domain()
964 pci_bus_add_devices(vmd->bus); in vmd_enable_domain()
968 WARN(sysfs_create_link(&vmd->dev->dev.kobj, &vmd->bus->dev.kobj, in vmd_enable_domain()
976 struct vmd_dev *vmd; in vmd_probe() local
982 vmd = devm_kzalloc(&dev->dev, sizeof(*vmd), GFP_KERNEL); in vmd_probe()
983 if (!vmd) in vmd_probe()
986 vmd->dev = dev; in vmd_probe()
987 vmd->instance = ida_simple_get(&vmd_instance_ida, 0, 0, GFP_KERNEL); in vmd_probe()
988 if (vmd->instance < 0) in vmd_probe()
989 return vmd->instance; in vmd_probe()
991 vmd->name = devm_kasprintf(&dev->dev, GFP_KERNEL, "vmd%d", in vmd_probe()
992 vmd->instance); in vmd_probe()
993 if (!vmd->name) { in vmd_probe()
1002 vmd->cfgbar = pcim_iomap(dev, VMD_CFGBAR, 0); in vmd_probe()
1003 if (!vmd->cfgbar) { in vmd_probe()
1016 vmd->first_vec = 1; in vmd_probe()
1018 spin_lock_init(&vmd->cfg_lock); in vmd_probe()
1019 pci_set_drvdata(dev, vmd); in vmd_probe()
1020 err = vmd_enable_domain(vmd, features); in vmd_probe()
1024 dev_info(&vmd->dev->dev, "Bound to PCI domain %04x\n", in vmd_probe()
1025 vmd->sysdata.domain); in vmd_probe()
1029 ida_simple_remove(&vmd_instance_ida, vmd->instance); in vmd_probe()
1033 static void vmd_cleanup_srcu(struct vmd_dev *vmd) in vmd_cleanup_srcu() argument
1037 for (i = 0; i < vmd->msix_count; i++) in vmd_cleanup_srcu()
1038 cleanup_srcu_struct(&vmd->irqs[i].srcu); in vmd_cleanup_srcu()
1043 struct vmd_dev *vmd = pci_get_drvdata(dev); in vmd_remove() local
1045 sysfs_remove_link(&vmd->dev->dev.kobj, "domain"); in vmd_remove()
1046 pci_stop_root_bus(vmd->bus); in vmd_remove()
1047 pci_remove_root_bus(vmd->bus); in vmd_remove()
1048 vmd_cleanup_srcu(vmd); in vmd_remove()
1049 vmd_detach_resources(vmd); in vmd_remove()
1050 vmd_remove_irq_domain(vmd); in vmd_remove()
1051 ida_simple_remove(&vmd_instance_ida, vmd->instance); in vmd_remove()
1056 struct vmd_dev *vmd = pci_get_drvdata(dev); in vmd_shutdown() local
1058 vmd_remove_irq_domain(vmd); in vmd_shutdown()
1065 struct vmd_dev *vmd = pci_get_drvdata(pdev); in vmd_suspend() local
1068 for (i = 0; i < vmd->msix_count; i++) in vmd_suspend()
1069 devm_free_irq(dev, vmd->irqs[i].virq, &vmd->irqs[i]); in vmd_suspend()
1077 struct vmd_dev *vmd = pci_get_drvdata(pdev); in vmd_resume() local
1080 if (vmd->irq_domain) in vmd_resume()
1081 vmd_set_msi_remapping(vmd, true); in vmd_resume()
1083 vmd_set_msi_remapping(vmd, false); in vmd_resume()
1085 for (i = 0; i < vmd->msix_count; i++) { in vmd_resume()
1086 err = devm_request_irq(dev, vmd->irqs[i].virq, in vmd_resume()
1088 vmd->name, &vmd->irqs[i]); in vmd_resume()