2021-12-06 17:27:51 -05:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* PCI Message Signaled Interrupt (MSI).
|
|
|
|
*
|
|
|
|
* Legacy architecture specific setup and teardown mechanism.
|
|
|
|
*/
|
2021-12-06 17:27:52 -05:00
|
|
|
#include "msi.h"
|
2021-12-06 17:27:51 -05:00
|
|
|
|
|
|
|
/* Arch hooks */
|
|
|
|
int __weak arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __weak arch_teardown_msi_irq(unsigned int irq)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int __weak arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
|
|
|
|
{
|
|
|
|
struct msi_desc *desc;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If an architecture wants to support multiple MSI, it needs to
|
|
|
|
* override arch_setup_msi_irqs()
|
|
|
|
*/
|
|
|
|
if (type == PCI_CAP_ID_MSI && nvec > 1)
|
|
|
|
return 1;
|
|
|
|
|
2021-12-06 17:51:18 -05:00
|
|
|
msi_for_each_desc(desc, &dev->dev, MSI_DESC_NOTASSOCIATED) {
|
2021-12-06 17:27:51 -05:00
|
|
|
ret = arch_setup_msi_irq(dev, desc);
|
|
|
|
if (ret)
|
|
|
|
return ret < 0 ? ret : -ENOSPC;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __weak arch_teardown_msi_irqs(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
struct msi_desc *desc;
|
|
|
|
int i;
|
|
|
|
|
2021-12-06 17:51:18 -05:00
|
|
|
msi_for_each_desc(desc, &dev->dev, MSI_DESC_ASSOCIATED) {
|
|
|
|
for (i = 0; i < desc->nvec_used; i++)
|
|
|
|
arch_teardown_msi_irq(desc->irq + i);
|
2021-12-06 17:27:51 -05:00
|
|
|
}
|
|
|
|
}
|
2021-12-06 17:27:52 -05:00
|
|
|
|
2021-12-06 17:28:00 -05:00
|
|
|
static int pci_msi_setup_check_result(struct pci_dev *dev, int type, int ret)
|
|
|
|
{
|
2021-12-06 17:51:18 -05:00
|
|
|
struct msi_desc *desc;
|
2021-12-06 17:28:00 -05:00
|
|
|
int avail = 0;
|
|
|
|
|
|
|
|
if (type != PCI_CAP_ID_MSIX || ret >= 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Scan the MSI descriptors for successfully allocated ones. */
|
2021-12-06 17:51:18 -05:00
|
|
|
msi_for_each_desc(desc, &dev->dev, MSI_DESC_ASSOCIATED)
|
|
|
|
avail++;
|
|
|
|
|
2021-12-06 17:28:00 -05:00
|
|
|
return avail ? avail : ret;
|
|
|
|
}
|
|
|
|
|
2021-12-06 17:27:52 -05:00
|
|
|
int pci_msi_legacy_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
|
|
|
|
{
|
2021-12-06 17:28:00 -05:00
|
|
|
int ret = arch_setup_msi_irqs(dev, nvec, type);
|
|
|
|
|
2021-12-10 17:19:05 -05:00
|
|
|
ret = pci_msi_setup_check_result(dev, type, ret);
|
|
|
|
if (!ret)
|
|
|
|
ret = msi_device_populate_sysfs(&dev->dev);
|
|
|
|
return ret;
|
2021-12-06 17:27:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void pci_msi_legacy_teardown_msi_irqs(struct pci_dev *dev)
|
|
|
|
{
|
2021-12-10 17:19:05 -05:00
|
|
|
msi_device_destroy_sysfs(&dev->dev);
|
2021-12-06 17:27:52 -05:00
|
|
|
arch_teardown_msi_irqs(dev);
|
|
|
|
}
|