/** * pci_msi_supported - check whether MSI may be enabled on a device * @dev: pointer to the pci_dev data structure of MSI device function * @nvec: how many MSIs have been requested? * * Look at global flags, the device itself, and its parent buses * to determine if MSI/-X are supported for the device. If MSI/-X is * supported return 1, else return 0.
**/ staticint pci_msi_supported(struct pci_dev *dev, int nvec)
{ struct pci_bus *bus;
/* MSI must be globally enabled and supported by the device */ if (!pci_msi_enable) return 0;
if (!dev || dev->no_msi) return 0;
/* * You can't ask to have 0 or less MSIs configured. * a) it's stupid .. * b) the list manipulation code assumes nvec >= 1.
*/ if (nvec < 1) return 0;
/* * Any bridge which does NOT route MSI transactions from its * secondary bus to its primary bus must set NO_MSI flag on * the secondary pci_bus. * * The NO_MSI flag can either be set directly by: * - arch-specific PCI host bus controller drivers (deprecated) * - quirks for specific PCI bridges * * or indirectly by platform-specific PCI host bridge drivers by * advertising the 'msi_domain' property, which results in * the NO_MSI flag when no MSI domain is found for this bridge * at probe time.
*/ for (bus = dev->bus; bus; bus = bus->parent) if (bus->bus_flags & PCI_BUS_FLAGS_NO_MSI) return 0;
/* * Needs to be separate from pcim_release to prevent an ordering problem * vs. msi_device_data_release() in the MSI core code.
*/ staticint pcim_setup_msi_release(struct pci_dev *dev)
{ int ret;
if (!pci_is_managed(dev) || dev->is_msi_managed) return 0;
ret = devm_add_action(&dev->dev, pcim_msi_release, dev); if (ret) return ret;
dev->is_msi_managed = true; return 0;
}
/* * Ordering vs. devres: msi device data has to be installed first so that * pcim_msi_release() is invoked before it on device release.
*/ staticint pci_setup_msi_context(struct pci_dev *dev)
{ int ret = msi_setup_device_data(&dev->dev);
if (ret) return ret;
return pcim_setup_msi_release(dev);
}
/* * Helper functions for mask/unmask and MSI message handling
*/
if (desc->pci.msi_attrib.is_virtual) return; /* * The specification mandates that the entry is masked * when the message is modified: * * "If software changes the Address or Data value of an * entry while the entry is unmasked, the result is * undefined."
*/ if (unmasked)
pci_msix_write_vector_ctrl(desc, ctrl | PCI_MSIX_ENTRY_CTRL_MASKBIT);
writel(msg->address_lo, base + PCI_MSIX_ENTRY_LOWER_ADDR);
writel(msg->address_hi, base + PCI_MSIX_ENTRY_UPPER_ADDR);
writel(msg->data, base + PCI_MSIX_ENTRY_DATA);
if (unmasked)
pci_msix_write_vector_ctrl(desc, ctrl);
/* Ensure that the writes are visible in the device */
readl(base + PCI_MSIX_ENTRY_DATA);
}
staticint __msi_capability_init(struct pci_dev *dev, int nvec, struct irq_affinity_desc *masks)
{ int ret = msi_setup_msi_desc(dev, nvec, masks); struct msi_desc *entry, desc;
if (ret) return ret;
/* All MSIs are unmasked by default; mask them all */
entry = msi_first_desc(&dev->dev, MSI_DESC_ALL);
pci_msi_mask(entry, msi_multi_mask(entry)); /* * Copy the MSI descriptor for the error path because * pci_msi_setup_msi_irqs() will free it for the hierarchical * interrupt domain case.
*/
memcpy(&desc, entry, sizeof(desc));
/* Configure MSI capability structure */
ret = pci_msi_setup_msi_irqs(dev, nvec, PCI_CAP_ID_MSI); if (ret) goto err;
/** * msi_capability_init - configure device's MSI capability structure * @dev: pointer to the pci_dev data structure of MSI device function * @nvec: number of interrupts to allocate * @affd: description of automatic IRQ affinity assignments (may be %NULL) * * Setup the MSI capability structure of the device with the requested * number of interrupts. A return value of zero indicates the successful * setup of an entry with the new MSI IRQ. A negative return value indicates * an error, and a positive return value indicates the number of interrupts * which could have been allocated.
*/ staticint msi_capability_init(struct pci_dev *dev, int nvec, struct irq_affinity *affd)
{ /* Reject multi-MSI early on irq domain enabled architectures */ if (nvec > 1 && !pci_msi_domain_supports(dev, MSI_FLAG_MULTI_PCI_MSI, ALLOW_LEGACY)) return 1;
/* * Disable MSI during setup in the hardware, but mark it enabled * so that setup code can evaluate it.
*/
pci_msi_set_enable(dev, 0);
if (rc < 0) return rc; if (rc < minvec) return -ENOSPC;
nvec = rc;
}
}
/** * pci_msi_vec_count - Return the number of MSI vectors a device can send * @dev: device to report about * * This function returns the number of MSI vectors a device requested via * Multiple Message Capable register. It returns a negative errno if the * device is not capable sending MSI interrupts. Otherwise, the call succeeds * and returns a power of two, up to a maximum of 2^5 (32), according to the * MSI specification.
**/ int pci_msi_vec_count(struct pci_dev *dev)
{ int ret;
u16 msgctl;
/* * Architecture override returns true when the PCI MSI message should be * written by the generic restore function.
*/ bool __weak arch_restore_msi_irqs(struct pci_dev *dev)
{ returntrue;
}
/* Return the device with MSI unmasked as initial states */
desc = msi_first_desc(&dev->dev, MSI_DESC_ALL); if (!WARN_ON_ONCE(!desc))
pci_msi_unmask(desc, msi_multi_mask(desc));
/* Restore dev->irq to its default pin-assertion IRQ */
dev->irq = desc->pci.msi_attrib.default_irq;
pcibios_alloc_irq(dev);
}
/** * msix_prepare_msi_desc - Prepare a half initialized MSI descriptor for operation * @dev: The PCI device for which the descriptor is prepared * @desc: The MSI descriptor for preparation * * This is separate from msix_setup_msi_descs() below to handle dynamic * allocations for MSI-X after initial enablement. * * Ideally the whole MSI-X setup would work that way, but there is no way to * support this for the legacy arch_setup_msi_irqs() mechanism and for the * fake irq domains like the x86 XEN one. Sigh... * * The descriptor is zeroed and only @desc::msi_index and @desc::affinity * are set. When called from msix_setup_msi_descs() then the is_virtual * attribute is initialized as well. * * Fill in the rest.
*/ void msix_prepare_msi_desc(struct pci_dev *dev, struct msi_desc *desc)
{
desc->nvec_used = 1;
desc->pci.msi_attrib.is_msix = 1;
desc->pci.msi_attrib.is_64 = 1;
desc->pci.msi_attrib.default_irq = dev->irq;
desc->pci.mask_base = dev->msix_base;
/** * msix_capability_init - configure device's MSI-X capability * @dev: pointer to the pci_dev data structure of MSI-X device function * @entries: pointer to an array of struct msix_entry entries * @nvec: number of @entries * @affd: Optional pointer to enable automatic affinity assignment * * Setup the MSI-X capability structure of device function with a * single MSI-X IRQ. A return of zero indicates the successful setup of * requested MSI-X entries with allocated IRQs or non-zero for otherwise.
**/ staticint msix_capability_init(struct pci_dev *dev, struct msix_entry *entries, int nvec, struct irq_affinity *affd)
{ int ret, tsize;
u16 control;
/* * Some devices require MSI-X to be enabled before the MSI-X * registers can be accessed. Mask all the vectors to prevent * interrupts coming in before they're fully set up.
*/
pci_msix_clear_and_set_ctrl(dev, 0, PCI_MSIX_FLAGS_MASKALL |
PCI_MSIX_FLAGS_ENABLE);
/* Mark it enabled so setup functions can query it */
dev->msix_enabled = 1;
pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control); /* Request & Map MSI-X table region */
tsize = msix_table_size(control);
dev->msix_base = msix_map_region(dev, tsize); if (!dev->msix_base) {
ret = -ENOMEM; goto out_disable;
}
ret = msix_setup_interrupts(dev, entries, nvec, affd); if (ret) goto out_disable;
/* Disable INTX */
pci_intx_for_msi(dev, 0);
if (!pci_msi_domain_supports(dev, MSI_FLAG_NO_MASK, DENY_LEGACY)) { /* * Ensure that all table entries are masked to prevent * stale entries from firing in a crash kernel. * * Done late to deal with a broken Marvell NVME device * which takes the MSI-X mask bits into account even * when MSI-X is disabled, which prevents MSI delivery.
*/
msix_mask_all(dev->msix_base, tsize);
}
pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_MASKALL, 0);
for (i = 0; i < nvec; i++) { /* Check for duplicate entries */ for (j = i + 1; j < nvec; j++) { if (entries[i].entry == entries[j].entry) returnfalse;
} /* Check for unsupported gaps */ if (nogap && entries[i].entry != i) returnfalse;
} returntrue;
}
int __pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries, int minvec, int maxvec, struct irq_affinity *affd, int flags)
{ int hwsize, rc, nvec = maxvec;
if (dev->msix_base) {
iounmap(dev->msix_base);
dev->msix_base = NULL;
}
}
#ifdef CONFIG_PCIE_TPH /** * pci_msix_write_tph_tag - Update the TPH tag for a given MSI-X vector * @pdev: The PCIe device to update * @index: The MSI-X index to update * @tag: The tag to write * * Returns: 0 on success, error code on failure
*/ int pci_msix_write_tph_tag(struct pci_dev *pdev, unsignedint index, u16 tag)
{ struct msi_desc *msi_desc; struct irq_desc *irq_desc; unsignedint virq;
if (!pdev->msix_enabled) return -ENXIO;
virq = msi_get_virq(&pdev->dev, index); if (!virq) return -ENXIO;
guard(msi_descs_lock)(&pdev->dev);
/* * This is a horrible hack, but short of implementing a PCI * specific interrupt chip callback and a huge pile of * infrastructure, this is the minor nuisance. It provides the * protection against concurrent operations on this entry and keeps * the control word cache in sync.
*/
irq_desc = irq_to_desc(virq); if (!irq_desc) return -ENXIO;
guard(raw_spinlock_irq)(&irq_desc->lock);
msi_desc = irq_data_get_msi_desc(&irq_desc->irq_data); if (!msi_desc || msi_desc->pci.msi_attrib.is_virtual) return -ENXIO;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.