先看 MSI Capability Structures.
/*
* 很简单,使能 MSI
* 默认情况下,MSI 是禁用的.
* 这里要使能它.
*/
static inline void pci_msi_set_enable(struct pci_dev *dev, int enable)
{
u16 control;
/*
* 读取消息控制寄存器.
*/
pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control);
/*
* bit[0] 置 1. 见下图.
*/
control &= ~PCI_MSI_FLAGS_ENABLE;
if (enable)
control |= PCI_MSI_FLAGS_ENABLE;
/*
* 写入消息控制寄存器
*/
pci_write_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, control);
}
MSI-X 有很大的变化
bit[15] : 默认值为0,
static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,
int nvec, struct irq_affinity *affd)
{
u16 control;
/*
* 读取消息控制寄存器.
*
* 1) Table size . bit[10:0]
* 即 中断向量的个数.
* 可见一个Function能支持 2048个MSI-X 中断.
*/
pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);
}