drivers/pci/msi/msi.c
Source file repositories/reference/linux-study-clean/drivers/pci/msi/msi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pci/msi/msi.c- Extension
.c- Size
- 26486 bytes
- Lines
- 994
- Domain
- Representative Device Path
- Bucket
- PCIe NVMe Storage Path
- Inferred role
- Representative Device Path: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Part of the selected hardware vertical slice: PCI discovery, driver binding, NVMe queues, block requests, DMA, interrupts, and completion.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hlinux/err.hlinux/export.hlinux/irq.hlinux/irqdomain.h../pci.hmsi.h
Detected Declarations
function pci_msi_supportedfunction pcim_msi_releasefunction pcim_setup_msi_releasefunction pcim_msi_releasefunction pci_msi_update_maskfunction pci_msi_mask_irqfunction pci_msi_unmask_irqfunction __pci_read_msi_msgfunction pci_write_msg_msifunction pci_write_msg_msixfunction __pci_write_msi_msgfunction pci_write_msi_msgfunction pci_intx_for_msifunction pci_msi_set_enablefunction msi_setup_msi_descfunction msi_verify_entriesfunction msi_for_each_descfunction __msi_capability_initfunction msi_capability_initfunction __pci_enable_msi_rangefunction pci_msi_vec_countfunction arch_restore_msi_irqsfunction __pci_restore_msi_statefunction pci_msi_shutdownfunction pci_msix_clear_and_set_ctrlfunction msix_setup_msi_descsfunction msix_setup_msi_descsfunction msix_update_entriesfunction msix_mask_allfunction __msix_setup_interruptsfunction msix_setup_interruptsfunction msix_capability_initfunction pci_msix_validate_entriesfunction __pci_enable_msix_rangefunction __pci_restore_msix_statefunction scoped_guardfunction pci_msix_shutdownfunction pci_free_msi_irqsfunction pci_msix_write_tph_tagfunction pci_no_msiexport pci_msi_mask_irqexport pci_msi_unmask_irqexport pci_write_msi_msgexport pci_msi_vec_countexport msi_desc_to_pci_dev
Annotated Snippet
if (entry->pci.msi_attrib.is_64) {
pci_read_config_dword(dev, pos + PCI_MSI_ADDRESS_HI,
&msg->address_hi);
pci_read_config_word(dev, pos + PCI_MSI_DATA_64, &data);
} else {
msg->address_hi = 0;
pci_read_config_word(dev, pos + PCI_MSI_DATA_32, &data);
}
msg->data = data;
}
}
static inline void pci_write_msg_msi(struct pci_dev *dev, struct msi_desc *desc,
struct msi_msg *msg)
{
int pos = dev->msi_cap;
u16 msgctl;
pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl);
msgctl &= ~PCI_MSI_FLAGS_QSIZE;
msgctl |= FIELD_PREP(PCI_MSI_FLAGS_QSIZE, desc->pci.msi_attrib.multiple);
pci_write_config_word(dev, pos + PCI_MSI_FLAGS, msgctl);
pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO, msg->address_lo);
if (desc->pci.msi_attrib.is_64) {
pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI, msg->address_hi);
pci_write_config_word(dev, pos + PCI_MSI_DATA_64, msg->data);
} else {
pci_write_config_word(dev, pos + PCI_MSI_DATA_32, msg->data);
}
/* Ensure that the writes are visible in the device */
pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl);
}
static inline void pci_write_msg_msix(struct msi_desc *desc, struct msi_msg *msg)
{
void __iomem *base = pci_msix_desc_addr(desc);
u32 ctrl = desc->pci.msix_ctrl;
bool unmasked = !(ctrl & PCI_MSIX_ENTRY_CTRL_MASKBIT);
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);
}
void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
{
struct pci_dev *dev = msi_desc_to_pci_dev(entry);
if (dev->current_state != PCI_D0 || pci_dev_is_disconnected(dev)) {
/* Don't touch the hardware now */
} else if (entry->pci.msi_attrib.is_msix) {
pci_write_msg_msix(entry, msg);
} else {
pci_write_msg_msi(dev, entry, msg);
}
entry->msg = *msg;
if (entry->write_msi_msg)
entry->write_msi_msg(entry, entry->write_msi_msg_data);
}
void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg)
{
struct msi_desc *entry = irq_get_msi_desc(irq);
__pci_write_msi_msg(entry, msg);
}
EXPORT_SYMBOL_GPL(pci_write_msi_msg);
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/err.h`, `linux/export.h`, `linux/irq.h`, `linux/irqdomain.h`, `../pci.h`, `msi.h`.
- Detected declarations: `function pci_msi_supported`, `function pcim_msi_release`, `function pcim_setup_msi_release`, `function pcim_msi_release`, `function pci_msi_update_mask`, `function pci_msi_mask_irq`, `function pci_msi_unmask_irq`, `function __pci_read_msi_msg`, `function pci_write_msg_msi`, `function pci_write_msg_msix`.
- Atlas domain: Representative Device Path / PCIe NVMe Storage Path.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.