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()
224 static struct vmd_irq_list *vmd_next_irq(struct vmd_dev *vmd, struct msi_desc *desc) in vmd_next_irq() argument
229 if (vmd->msix_count == 1 + vmd->first_vec) in vmd_next_irq()
230 return &vmd->irqs[vmd->first_vec]; in vmd_next_irq()
240 return &vmd->irqs[vmd->first_vec]; in vmd_next_irq()
244 best = vmd->first_vec + 1; in vmd_next_irq()
245 for (i = best; i < vmd->msix_count; i++) in vmd_next_irq()
246 if (vmd->irqs[i].count < vmd->irqs[best].count) in vmd_next_irq()
248 vmd->irqs[best].count++; in vmd_next_irq()
251 return &vmd->irqs[best]; in vmd_next_irq()
259 struct vmd_dev *vmd = vmd_from_bus(msi_desc_to_pci_dev(desc)->bus); in vmd_msi_init() local
266 vmdirq->irq = vmd_next_irq(vmd, desc); in vmd_msi_init()
270 handle_untracked_irq, vmd, NULL); in vmd_msi_init()
294 struct vmd_dev *vmd = vmd_from_bus(pdev->bus); in vmd_msi_prepare() local
296 if (nvec > vmd->msix_count) in vmd_msi_prepare()
297 return vmd->msix_count; in vmd_msi_prepare()
323 static void vmd_set_msi_remapping(struct vmd_dev *vmd, bool enable) in vmd_set_msi_remapping() argument
327 pci_read_config_word(vmd->dev, PCI_REG_VMCONFIG, &reg); in vmd_set_msi_remapping()
330 pci_write_config_word(vmd->dev, PCI_REG_VMCONFIG, reg); in vmd_set_msi_remapping()
333 static int vmd_create_irq_domain(struct vmd_dev *vmd) in vmd_create_irq_domain() argument
337 fn = irq_domain_alloc_named_id_fwnode("VMD-MSI", vmd->sysdata.domain); in vmd_create_irq_domain()
341 vmd->irq_domain = pci_msi_create_irq_domain(fn, &vmd_msi_domain_info, NULL); in vmd_create_irq_domain()
342 if (!vmd->irq_domain) { in vmd_create_irq_domain()
350 static void vmd_remove_irq_domain(struct vmd_dev *vmd) in vmd_remove_irq_domain() argument
356 if (!vmd->msix_count) in vmd_remove_irq_domain()
357 vmd_set_msi_remapping(vmd, true); in vmd_remove_irq_domain()
359 if (vmd->irq_domain) { in vmd_remove_irq_domain()
360 struct fwnode_handle *fn = vmd->irq_domain->fwnode; in vmd_remove_irq_domain()
362 irq_domain_remove(vmd->irq_domain); in vmd_remove_irq_domain()
367 static void __iomem *vmd_cfg_addr(struct vmd_dev *vmd, struct pci_bus *bus, in vmd_cfg_addr() argument
370 unsigned int busnr_ecam = bus->number - vmd->busn_start; in vmd_cfg_addr()
373 if (offset + len >= resource_size(&vmd->dev->resource[VMD_CFGBAR])) in vmd_cfg_addr()
376 return vmd->cfgbar + offset; in vmd_cfg_addr()
386 struct vmd_dev *vmd = vmd_from_bus(bus); in vmd_pci_read() local
387 void __iomem *addr = vmd_cfg_addr(vmd, bus, devfn, reg, len); in vmd_pci_read()
394 spin_lock_irqsave(&vmd->cfg_lock, flags); in vmd_pci_read()
409 spin_unlock_irqrestore(&vmd->cfg_lock, flags); in vmd_pci_read()
421 struct vmd_dev *vmd = vmd_from_bus(bus); in vmd_pci_write() local
422 void __iomem *addr = vmd_cfg_addr(vmd, bus, devfn, reg, len); in vmd_pci_write()
429 spin_lock_irqsave(&vmd->cfg_lock, flags); in vmd_pci_write()
447 spin_unlock_irqrestore(&vmd->cfg_lock, flags); in vmd_pci_write()
506 static void vmd_domain_reset(struct vmd_dev *vmd) in vmd_domain_reset() argument
508 u16 bus, max_buses = resource_size(&vmd->resources[0]); in vmd_domain_reset()
514 base = vmd->cfgbar + PCIE_ECAM_OFFSET(bus, in vmd_domain_reset()
521 base = vmd->cfgbar + PCIE_ECAM_OFFSET(bus, in vmd_domain_reset()
554 static void vmd_attach_resources(struct vmd_dev *vmd) in vmd_attach_resources() argument
556 vmd->dev->resource[VMD_MEMBAR1].child = &vmd->resources[1]; in vmd_attach_resources()
557 vmd->dev->resource[VMD_MEMBAR2].child = &vmd->resources[2]; in vmd_attach_resources()
560 static void vmd_detach_resources(struct vmd_dev *vmd) in vmd_detach_resources() argument
562 vmd->dev->resource[VMD_MEMBAR1].child = NULL; in vmd_detach_resources()
563 vmd->dev->resource[VMD_MEMBAR2].child = NULL; in vmd_detach_resources()
582 static int vmd_get_phys_offsets(struct vmd_dev *vmd, bool native_hint, in vmd_get_phys_offsets() argument
586 struct pci_dev *dev = vmd->dev; in vmd_get_phys_offsets()
636 static int vmd_get_bus_number_start(struct vmd_dev *vmd) in vmd_get_bus_number_start() argument
638 struct pci_dev *dev = vmd->dev; in vmd_get_bus_number_start()
647 vmd->busn_start = 0; in vmd_get_bus_number_start()
650 vmd->busn_start = 128; in vmd_get_bus_number_start()
653 vmd->busn_start = 224; in vmd_get_bus_number_start()
679 static int vmd_alloc_irqs(struct vmd_dev *vmd) in vmd_alloc_irqs() argument
681 struct pci_dev *dev = vmd->dev; in vmd_alloc_irqs()
684 vmd->msix_count = pci_msix_vec_count(dev); in vmd_alloc_irqs()
685 if (vmd->msix_count < 0) in vmd_alloc_irqs()
688 vmd->msix_count = pci_alloc_irq_vectors(dev, vmd->first_vec + 1, in vmd_alloc_irqs()
689 vmd->msix_count, PCI_IRQ_MSIX); in vmd_alloc_irqs()
690 if (vmd->msix_count < 0) in vmd_alloc_irqs()
691 return vmd->msix_count; in vmd_alloc_irqs()
693 vmd->irqs = devm_kcalloc(&dev->dev, vmd->msix_count, sizeof(*vmd->irqs), in vmd_alloc_irqs()
695 if (!vmd->irqs) in vmd_alloc_irqs()
698 for (i = 0; i < vmd->msix_count; i++) { in vmd_alloc_irqs()
699 err = init_srcu_struct(&vmd->irqs[i].srcu); in vmd_alloc_irqs()
703 INIT_LIST_HEAD(&vmd->irqs[i].irq_list); in vmd_alloc_irqs()
704 vmd->irqs[i].virq = pci_irq_vector(dev, i); in vmd_alloc_irqs()
705 err = devm_request_irq(&dev->dev, vmd->irqs[i].virq, in vmd_alloc_irqs()
707 vmd->name, &vmd->irqs[i]); in vmd_alloc_irqs()
770 static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) in vmd_enable_domain() argument
772 struct pci_sysdata *sd = &vmd->sysdata; in vmd_enable_domain()
791 ret = vmd_get_phys_offsets(vmd, true, &offset[0], &offset[1]); in vmd_enable_domain()
795 ret = vmd_get_phys_offsets(vmd, false, &offset[0], &offset[1]); in vmd_enable_domain()
805 ret = vmd_get_bus_number_start(vmd); in vmd_enable_domain()
810 res = &vmd->dev->resource[VMD_CFGBAR]; in vmd_enable_domain()
811 vmd->resources[0] = (struct resource) { in vmd_enable_domain()
813 .start = vmd->busn_start, in vmd_enable_domain()
814 .end = vmd->busn_start + (resource_size(res) >> 20) - 1, in vmd_enable_domain()
835 res = &vmd->dev->resource[VMD_MEMBAR1]; in vmd_enable_domain()
840 vmd->resources[1] = (struct resource) { in vmd_enable_domain()
848 res = &vmd->dev->resource[VMD_MEMBAR2]; in vmd_enable_domain()
853 vmd->resources[2] = (struct resource) { in vmd_enable_domain()
861 sd->vmd_dev = vmd->dev; in vmd_enable_domain()
866 sd->node = pcibus_to_node(vmd->dev->bus); in vmd_enable_domain()
876 ret = vmd_alloc_irqs(vmd); in vmd_enable_domain()
880 vmd_set_msi_remapping(vmd, true); in vmd_enable_domain()
882 ret = vmd_create_irq_domain(vmd); in vmd_enable_domain()
890 irq_domain_update_bus_token(vmd->irq_domain, DOMAIN_BUS_VMD_MSI); in vmd_enable_domain()
892 vmd_set_msi_remapping(vmd, false); in vmd_enable_domain()
895 pci_add_resource(&resources, &vmd->resources[0]); in vmd_enable_domain()
896 pci_add_resource_offset(&resources, &vmd->resources[1], offset[0]); in vmd_enable_domain()
897 pci_add_resource_offset(&resources, &vmd->resources[2], offset[1]); in vmd_enable_domain()
899 vmd->bus = pci_create_root_bus(&vmd->dev->dev, vmd->busn_start, in vmd_enable_domain()
901 if (!vmd->bus) { in vmd_enable_domain()
903 vmd_remove_irq_domain(vmd); in vmd_enable_domain()
907 vmd_copy_host_bridge_flags(pci_find_host_bridge(vmd->dev->bus), in vmd_enable_domain()
908 to_pci_host_bridge(vmd->bus->bridge)); in vmd_enable_domain()
910 vmd_attach_resources(vmd); in vmd_enable_domain()
911 if (vmd->irq_domain) in vmd_enable_domain()
912 dev_set_msi_domain(&vmd->bus->dev, vmd->irq_domain); in vmd_enable_domain()
914 dev_set_msi_domain(&vmd->bus->dev, in vmd_enable_domain()
915 dev_get_msi_domain(&vmd->dev->dev)); in vmd_enable_domain()
917 WARN(sysfs_create_link(&vmd->dev->dev.kobj, &vmd->bus->dev.kobj, in vmd_enable_domain()
922 pci_scan_child_bus(vmd->bus); in vmd_enable_domain()
923 vmd_domain_reset(vmd); in vmd_enable_domain()
932 list_for_each_entry(child, &vmd->bus->children, node) { in vmd_enable_domain()
944 pci_assign_unassigned_bus_resources(vmd->bus); in vmd_enable_domain()
946 pci_walk_bus(vmd->bus, vmd_pm_enable_quirk, &features); in vmd_enable_domain()
953 list_for_each_entry(child, &vmd->bus->children, node) in vmd_enable_domain()
956 pci_bus_add_devices(vmd->bus); in vmd_enable_domain()
965 struct vmd_dev *vmd; in vmd_probe() local
971 vmd = devm_kzalloc(&dev->dev, sizeof(*vmd), GFP_KERNEL); in vmd_probe()
972 if (!vmd) in vmd_probe()
975 vmd->dev = dev; in vmd_probe()
976 vmd->instance = ida_alloc(&vmd_instance_ida, GFP_KERNEL); in vmd_probe()
977 if (vmd->instance < 0) in vmd_probe()
978 return vmd->instance; in vmd_probe()
980 vmd->name = devm_kasprintf(&dev->dev, GFP_KERNEL, "vmd%d", in vmd_probe()
981 vmd->instance); in vmd_probe()
982 if (!vmd->name) { in vmd_probe()
991 vmd->cfgbar = pcim_iomap(dev, VMD_CFGBAR, 0); in vmd_probe()
992 if (!vmd->cfgbar) { in vmd_probe()
1005 vmd->first_vec = 1; in vmd_probe()
1007 spin_lock_init(&vmd->cfg_lock); in vmd_probe()
1008 pci_set_drvdata(dev, vmd); in vmd_probe()
1009 err = vmd_enable_domain(vmd, features); in vmd_probe()
1013 dev_info(&vmd->dev->dev, "Bound to PCI domain %04x\n", in vmd_probe()
1014 vmd->sysdata.domain); in vmd_probe()
1018 ida_free(&vmd_instance_ida, vmd->instance); in vmd_probe()
1022 static void vmd_cleanup_srcu(struct vmd_dev *vmd) in vmd_cleanup_srcu() argument
1026 for (i = 0; i < vmd->msix_count; i++) in vmd_cleanup_srcu()
1027 cleanup_srcu_struct(&vmd->irqs[i].srcu); in vmd_cleanup_srcu()
1032 struct vmd_dev *vmd = pci_get_drvdata(dev); in vmd_remove() local
1034 pci_stop_root_bus(vmd->bus); in vmd_remove()
1035 sysfs_remove_link(&vmd->dev->dev.kobj, "domain"); in vmd_remove()
1036 pci_remove_root_bus(vmd->bus); in vmd_remove()
1037 vmd_cleanup_srcu(vmd); in vmd_remove()
1038 vmd_detach_resources(vmd); in vmd_remove()
1039 vmd_remove_irq_domain(vmd); in vmd_remove()
1040 ida_free(&vmd_instance_ida, vmd->instance); in vmd_remove()
1045 struct vmd_dev *vmd = pci_get_drvdata(dev); in vmd_shutdown() local
1047 vmd_remove_irq_domain(vmd); in vmd_shutdown()
1054 struct vmd_dev *vmd = pci_get_drvdata(pdev); in vmd_suspend() local
1057 for (i = 0; i < vmd->msix_count; i++) in vmd_suspend()
1058 devm_free_irq(dev, vmd->irqs[i].virq, &vmd->irqs[i]); in vmd_suspend()
1066 struct vmd_dev *vmd = pci_get_drvdata(pdev); in vmd_resume() local
1069 vmd_set_msi_remapping(vmd, !!vmd->irq_domain); in vmd_resume()
1071 for (i = 0; i < vmd->msix_count; i++) { in vmd_resume()
1072 err = devm_request_irq(dev, vmd->irqs[i].virq, in vmd_resume()
1074 vmd->name, &vmd->irqs[i]); in vmd_resume()