Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d873b4d4 authored by Yijing Wang's avatar Yijing Wang Committed by Bjorn Helgaas
Browse files

PCI/MSI: Add msi_setup_entry() to clean up MSI initialization



Move MSI entry stuff to a new function, msi_setup_entry(), to simplify
msi_capability_init() as MSI-X does.

Signed-off-by: default avatarYijing Wang <wangyijing@huawei.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
parent 31ea5d4d
Loading
Loading
Loading
Loading
+33 −18
Original line number Original line Diff line number Diff line
@@ -581,6 +581,38 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
	return ret;
	return ret;
}
}


static struct msi_desc *msi_setup_entry(struct pci_dev *dev)
{
	u16 control;
	struct msi_desc *entry;

	/* MSI Entry Initialization */
	entry = alloc_msi_entry(dev);
	if (!entry)
		return NULL;

	pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control);

	entry->msi_attrib.is_msix	= 0;
	entry->msi_attrib.is_64		= !!(control & PCI_MSI_FLAGS_64BIT);
	entry->msi_attrib.entry_nr	= 0;
	entry->msi_attrib.maskbit	= !!(control & PCI_MSI_FLAGS_MASKBIT);
	entry->msi_attrib.default_irq	= dev->irq;	/* Save IOAPIC IRQ */
	entry->msi_attrib.pos		= dev->msi_cap;
	entry->msi_attrib.multi_cap	= (control & PCI_MSI_FLAGS_QMASK) >> 1;

	if (control & PCI_MSI_FLAGS_64BIT)
		entry->mask_pos = dev->msi_cap + PCI_MSI_MASK_64;
	else
		entry->mask_pos = dev->msi_cap + PCI_MSI_MASK_32;

	/* Save the initial mask status */
	if (entry->msi_attrib.maskbit)
		pci_read_config_dword(dev, entry->mask_pos, &entry->masked);

	return entry;
}

/**
/**
 * msi_capability_init - configure device's MSI capability structure
 * msi_capability_init - configure device's MSI capability structure
 * @dev: pointer to the pci_dev data structure of MSI device function
 * @dev: pointer to the pci_dev data structure of MSI device function
@@ -596,32 +628,15 @@ static int msi_capability_init(struct pci_dev *dev, int nvec)
{
{
	struct msi_desc *entry;
	struct msi_desc *entry;
	int ret;
	int ret;
	u16 control;
	unsigned mask;
	unsigned mask;


	msi_set_enable(dev, 0);	/* Disable MSI during set up */
	msi_set_enable(dev, 0);	/* Disable MSI during set up */


	pci_read_config_word(dev, dev->msi_cap + PCI_MSI_FLAGS, &control);
	entry = msi_setup_entry(dev);
	/* MSI Entry Initialization */
	entry = alloc_msi_entry(dev);
	if (!entry)
	if (!entry)
		return -ENOMEM;
		return -ENOMEM;


	entry->msi_attrib.is_msix	= 0;
	entry->msi_attrib.is_64		= !!(control & PCI_MSI_FLAGS_64BIT);
	entry->msi_attrib.entry_nr	= 0;
	entry->msi_attrib.maskbit	= !!(control & PCI_MSI_FLAGS_MASKBIT);
	entry->msi_attrib.default_irq	= dev->irq;	/* Save IOAPIC IRQ */
	entry->msi_attrib.pos		= dev->msi_cap;
	entry->msi_attrib.multi_cap	= (control & PCI_MSI_FLAGS_QMASK) >> 1;

	if (control & PCI_MSI_FLAGS_64BIT)
		entry->mask_pos = dev->msi_cap + PCI_MSI_MASK_64;
	else
		entry->mask_pos = dev->msi_cap + PCI_MSI_MASK_32;
	/* All MSIs are unmasked by default, Mask them all */
	/* All MSIs are unmasked by default, Mask them all */
	if (entry->msi_attrib.maskbit)
		pci_read_config_dword(dev, entry->mask_pos, &entry->masked);
	mask = msi_mask(entry->msi_attrib.multi_cap);
	mask = msi_mask(entry->msi_attrib.multi_cap);
	msi_mask_irq(entry, mask, mask);
	msi_mask_irq(entry, mask, mask);