Lines Matching +full:ports +full:- +full:offset2

1 // SPDX-License-Identifier: GPL-2.0
14 #include <linux/pci-acpi.h>
15 #include <linux/pci-ecam.h>
53 * vendor-specific capability space
58 * Device may use MSI-X vector 0 for software triggering and will not
64 * Device can bypass remapping MSI-X transactions into its MSI-X table,
71 * Enable ASPM on the PCIE root ports and set the default LTR of the
94 * struct vmd_irq - private data to map driver IRQ to the VMD shared vector
100 * Every MSI/MSI-X IRQ requested for a device in a VMD domain will be mapped to
111 * struct vmd_irq_list - list of driver requested IRQs mapping to a VMD vector
146 return container_of(bus->sysdata, struct vmd_dev, sysdata); in vmd_from_bus()
152 return irqs - vmd->irqs; in index_from_irqs()
158 * destination ID for the VMD MSI-X table. The VMD muxes interrupts in its
159 * domain into one of its own, and the VMD driver de-muxes these for the
165 struct vmd_irq *vmdirq = data->chip_data; in vmd_compose_msi_msg()
166 struct vmd_irq_list *irq = vmdirq->irq; in vmd_compose_msi_msg()
170 msg->address_hi = X86_MSI_BASE_ADDRESS_HIGH; in vmd_compose_msi_msg()
171 msg->arch_addr_lo.base_address = X86_MSI_BASE_ADDRESS_LOW; in vmd_compose_msi_msg()
172 msg->arch_addr_lo.destid_0_7 = index_from_irqs(vmd, irq); in vmd_compose_msi_msg()
180 struct vmd_irq *vmdirq = data->chip_data; in vmd_irq_enable()
184 WARN_ON(vmdirq->enabled); in vmd_irq_enable()
185 list_add_tail_rcu(&vmdirq->node, &vmdirq->irq->irq_list); in vmd_irq_enable()
186 vmdirq->enabled = true; in vmd_irq_enable()
189 data->chip->irq_unmask(data); in vmd_irq_enable()
194 struct vmd_irq *vmdirq = data->chip_data; in vmd_irq_disable()
197 data->chip->irq_mask(data); in vmd_irq_disable()
200 if (vmdirq->enabled) { in vmd_irq_disable()
201 list_del_rcu(&vmdirq->node); in vmd_irq_disable()
202 vmdirq->enabled = false; in vmd_irq_disable()
208 .name = "VMD-MSI",
229 if (vmd->msix_count == 1 + vmd->first_vec) in vmd_next_irq()
230 return &vmd->irqs[vmd->first_vec]; in vmd_next_irq()
233 * White list for fast-interrupt handlers. All others will share the in vmd_next_irq()
236 switch (msi_desc_to_pci_dev(desc)->class) { 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()
258 struct msi_desc *desc = arg->desc; in vmd_msi_init()
259 struct vmd_dev *vmd = vmd_from_bus(msi_desc_to_pci_dev(desc)->bus); in vmd_msi_init()
263 return -ENOMEM; in vmd_msi_init()
265 INIT_LIST_HEAD(&vmdirq->node); in vmd_msi_init()
266 vmdirq->irq = vmd_next_irq(vmd, desc); in vmd_msi_init()
267 vmdirq->virq = virq; in vmd_msi_init()
269 irq_domain_set_info(domain, virq, vmdirq->irq->virq, info->chip, vmdirq, in vmd_msi_init()
280 synchronize_srcu(&vmdirq->irq->srcu); in vmd_msi_free()
284 vmdirq->irq->count--; in vmd_msi_free()
294 struct vmd_dev *vmd = vmd_from_bus(pdev->bus); in vmd_msi_prepare()
296 if (nvec > vmd->msix_count) in vmd_msi_prepare()
297 return vmd->msix_count; in vmd_msi_prepare()
305 arg->desc = desc; in vmd_set_desc()
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()
337 fn = irq_domain_alloc_named_id_fwnode("VMD-MSI", vmd->sysdata.domain); in vmd_create_irq_domain()
339 return -ENODEV; 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()
344 return -ENODEV; in vmd_create_irq_domain()
356 if (!vmd->msix_count) 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()
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()
392 return -EFAULT; in vmd_pci_read()
394 spin_lock_irqsave(&vmd->cfg_lock, flags); in vmd_pci_read()
406 ret = -EINVAL; in vmd_pci_read()
409 spin_unlock_irqrestore(&vmd->cfg_lock, flags); in vmd_pci_read()
414 * VMD h/w converts non-posted config writes to posted memory writes. The
415 * read-back in this function forces the completion so it returns only after
427 return -EFAULT; in vmd_pci_write()
429 spin_lock_irqsave(&vmd->cfg_lock, flags); in vmd_pci_write()
444 ret = -EINVAL; in vmd_pci_write()
447 spin_unlock_irqrestore(&vmd->cfg_lock, flags); in vmd_pci_write()
462 if (pci_dev->bus->ops != &vmd_ops) in vmd_acpi_find_companion()
465 bridge = pci_find_host_bridge(pci_dev->bus); in vmd_acpi_find_companion()
466 busnr = pci_dev->bus->number - bridge->bus->number; in vmd_acpi_find_companion()
474 addr = (busnr << 24) | ((u32)pci_dev->devfn << 16) | 0x8000FFFFU; in vmd_acpi_find_companion()
476 dev_dbg(&pci_dev->dev, "Looking for ACPI companion (address 0x%x)\n", in vmd_acpi_find_companion()
479 return acpi_find_child_device(ACPI_COMPANION(bridge->dev.parent), addr, in vmd_acpi_find_companion()
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()
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()
562 vmd->dev->resource[VMD_MEMBAR1].child = NULL; in vmd_detach_resources()
563 vmd->dev->resource[VMD_MEMBAR2].child = NULL; in vmd_detach_resources()
584 resource_size_t *offset2) in vmd_get_phys_offsets() argument
586 struct pci_dev *dev = vmd->dev; in vmd_get_phys_offsets()
595 return -ENODEV; in vmd_get_phys_offsets()
602 return -ENOMEM; in vmd_get_phys_offsets()
609 /* Hypervisor-Emulated Vendor-Specific Capability */ in vmd_get_phys_offsets()
628 *offset1 = dev->resource[VMD_MEMBAR1].start - in vmd_get_phys_offsets()
630 *offset2 = dev->resource[VMD_MEMBAR2].start - in vmd_get_phys_offsets()
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()
658 return -ENODEV; in vmd_get_bus_number_start()
671 idx = srcu_read_lock(&irqs->srcu); in vmd_irq()
672 list_for_each_entry_rcu(vmdirq, &irqs->irq_list, node) in vmd_irq()
673 generic_handle_irq(vmdirq->virq); in vmd_irq()
674 srcu_read_unlock(&irqs->srcu, idx); in vmd_irq()
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()
686 return -ENODEV; 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()
696 return -ENOMEM; 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()
716 * Since VMD is an aperture to regular PCIe root ports, only allow it to
722 vmd_bridge->native_pcie_hotplug = root_bridge->native_pcie_hotplug; in vmd_copy_host_bridge_flags()
723 vmd_bridge->native_shpc_hotplug = root_bridge->native_shpc_hotplug; in vmd_copy_host_bridge_flags()
724 vmd_bridge->native_aer = root_bridge->native_aer; in vmd_copy_host_bridge_flags()
725 vmd_bridge->native_pme = root_bridge->native_pme; in vmd_copy_host_bridge_flags()
726 vmd_bridge->native_ltr = root_bridge->native_ltr; in vmd_copy_host_bridge_flags()
727 vmd_bridge->native_dpc = root_bridge->native_dpc; in vmd_copy_host_bridge_flags()
750 * Skip if the max snoop LTR is non-zero, indicating BIOS has set it in vmd_pm_enable_quirk()
761 * max non-snoop latency. in vmd_pm_enable_quirk()
772 struct pci_sysdata *sd = &vmd->sysdata; in vmd_enable_domain()
785 * guests to correctly assign host physical addresses to the root ports in vmd_enable_domain()
802 * limits the bus range to between 0-127, 128-255, or 224-255 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()
820 * put 32-bit resources in the window. in vmd_enable_domain()
822 * There's no hardware reason why a 64-bit window *couldn't* in vmd_enable_domain()
823 * contain a 32-bit resource, but pbus_size_mem() computes the in vmd_enable_domain()
824 * bridge window size assuming a 64-bit window will contain no in vmd_enable_domain()
825 * 32-bit resources. __pci_assign_resource() enforces that in vmd_enable_domain()
828 * The only way we could use a 64-bit non-prefetchable MEMBAR is in vmd_enable_domain()
829 * if its address is <4GB so that we can convert it to a 32-bit in vmd_enable_domain()
835 res = &vmd->dev->resource[VMD_MEMBAR1]; in vmd_enable_domain()
836 upper_bits = upper_32_bits(res->end); in vmd_enable_domain()
837 flags = res->flags & ~IORESOURCE_SIZEALIGN; in vmd_enable_domain()
840 vmd->resources[1] = (struct resource) { in vmd_enable_domain()
842 .start = res->start, in vmd_enable_domain()
843 .end = res->end, in vmd_enable_domain()
848 res = &vmd->dev->resource[VMD_MEMBAR2]; in vmd_enable_domain()
849 upper_bits = upper_32_bits(res->end); in vmd_enable_domain()
850 flags = res->flags & ~IORESOURCE_SIZEALIGN; in vmd_enable_domain()
853 vmd->resources[2] = (struct resource) { in vmd_enable_domain()
855 .start = res->start + membar2_offset, in vmd_enable_domain()
856 .end = res->end, in vmd_enable_domain()
861 sd->vmd_dev = vmd->dev; in vmd_enable_domain()
862 sd->domain = vmd_find_free_domain(); in vmd_enable_domain()
863 if (sd->domain < 0) in vmd_enable_domain()
864 return sd->domain; in vmd_enable_domain()
866 sd->node = pcibus_to_node(vmd->dev->bus); in vmd_enable_domain()
871 * acceptable because the guest is usually CPU-limited and MSI in vmd_enable_domain()
890 irq_domain_update_bus_token(vmd->irq_domain, DOMAIN_BUS_VMD_MSI); 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()
904 return -ENODEV; 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()
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()
925 /* When Intel VMD is enabled, the OS does not discover the Root Ports in vmd_enable_domain()
932 list_for_each_entry(child, &vmd->bus->children, node) { in vmd_enable_domain()
933 if (!list_empty(&child->devices)) { in vmd_enable_domain()
934 dev = list_first_entry(&child->devices, 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()
951 * run on each of the real root ports. 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()
964 unsigned long features = (unsigned long) id->driver_data; in vmd_probe()
968 if (resource_size(&dev->resource[VMD_CFGBAR]) < (1 << 20)) in vmd_probe()
969 return -ENOMEM; in vmd_probe()
971 vmd = devm_kzalloc(&dev->dev, sizeof(*vmd), GFP_KERNEL); in vmd_probe()
973 return -ENOMEM; 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()
983 err = -ENOMEM; in vmd_probe()
991 vmd->cfgbar = pcim_iomap(dev, VMD_CFGBAR, 0); in vmd_probe()
992 if (!vmd->cfgbar) { in vmd_probe()
993 err = -ENOMEM; in vmd_probe()
998 if (dma_set_mask_and_coherent(&dev->dev, DMA_BIT_MASK(64)) && in vmd_probe()
999 dma_set_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32))) { in vmd_probe()
1000 err = -ENODEV; in vmd_probe()
1005 vmd->first_vec = 1; in vmd_probe()
1007 spin_lock_init(&vmd->cfg_lock); 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()
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()
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()
1040 ida_free(&vmd_instance_ida, vmd->instance); in vmd_remove()
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()
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()