Commit b12d0bec authored by Ahmed S. Darwish's avatar Ahmed S. Darwish Committed by Thomas Gleixner

PCI/MSI: Move pci_disable_msi() to api.c

msi.c is a maze of randomly sorted functions which makes the code
unreadable. As a first step split the driver visible API and the internal
implementation which also allows proper API documentation via one file.

Create drivers/pci/msi/api.c to group all exported device-driver PCI/MSI
APIs in one C file.

Begin by moving pci_disable_msi() there and add kernel-doc for the function
as appropriate.
Suggested-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarAhmed S. Darwish <darwi@linutronix.de>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Acked-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Link: https://lore.kernel.org/r/20221111122014.696798036@linutronix.de
parent c93fd526
...@@ -2,6 +2,5 @@ ...@@ -2,6 +2,5 @@
# #
# Makefile for the PCI/MSI # Makefile for the PCI/MSI
obj-$(CONFIG_PCI) += pcidev_msi.o obj-$(CONFIG_PCI) += pcidev_msi.o
obj-$(CONFIG_PCI_MSI) += msi.o obj-$(CONFIG_PCI_MSI) += api.o msi.o irqdomain.o
obj-$(CONFIG_PCI_MSI) += irqdomain.o
obj-$(CONFIG_PCI_MSI_ARCH_FALLBACKS) += legacy.o obj-$(CONFIG_PCI_MSI_ARCH_FALLBACKS) += legacy.o
// SPDX-License-Identifier: GPL-2.0
/*
* PCI MSI/MSI-X — Exported APIs for device drivers
*
* Copyright (C) 2003-2004 Intel
* Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com)
* Copyright (C) 2016 Christoph Hellwig.
* Copyright (C) 2022 Linutronix GmbH
*/
#include <linux/export.h>
#include "msi.h"
/**
* pci_disable_msi() - Disable MSI interrupt mode on device
* @dev: the PCI device to operate on
*
* Legacy device driver API to disable MSI interrupt mode on device,
* free earlier allocated interrupt vectors, and restore INTx emulation.
* The PCI device Linux IRQ (@dev->irq) is restored to its default
* pin-assertion IRQ. This is the cleanup pair of pci_enable_msi().
*
* NOTE: The newer pci_alloc_irq_vectors() / pci_free_irq_vectors() API
* pair should, in general, be used instead.
*/
void pci_disable_msi(struct pci_dev *dev)
{
if (!pci_msi_enabled() || !dev || !dev->msi_enabled)
return;
msi_lock_descs(&dev->dev);
pci_msi_shutdown(dev);
pci_free_msi_irqs(dev);
msi_unlock_descs(&dev->dev);
}
EXPORT_SYMBOL(pci_disable_msi);
...@@ -163,7 +163,7 @@ void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg) ...@@ -163,7 +163,7 @@ void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg)
} }
EXPORT_SYMBOL_GPL(pci_write_msi_msg); EXPORT_SYMBOL_GPL(pci_write_msi_msg);
static void free_msi_irqs(struct pci_dev *dev) void pci_free_msi_irqs(struct pci_dev *dev)
{ {
pci_msi_teardown_msi_irqs(dev); pci_msi_teardown_msi_irqs(dev);
...@@ -413,7 +413,7 @@ static int msi_capability_init(struct pci_dev *dev, int nvec, ...@@ -413,7 +413,7 @@ static int msi_capability_init(struct pci_dev *dev, int nvec,
err: err:
pci_msi_unmask(entry, msi_multi_mask(entry)); pci_msi_unmask(entry, msi_multi_mask(entry));
free_msi_irqs(dev); pci_free_msi_irqs(dev);
fail: fail:
dev->msi_enabled = 0; dev->msi_enabled = 0;
unlock: unlock:
...@@ -531,7 +531,7 @@ static int msix_setup_interrupts(struct pci_dev *dev, void __iomem *base, ...@@ -531,7 +531,7 @@ static int msix_setup_interrupts(struct pci_dev *dev, void __iomem *base,
goto out_unlock; goto out_unlock;
out_free: out_free:
free_msi_irqs(dev); pci_free_msi_irqs(dev);
out_unlock: out_unlock:
msi_unlock_descs(&dev->dev); msi_unlock_descs(&dev->dev);
kfree(masks); kfree(masks);
...@@ -680,7 +680,7 @@ int pci_msi_vec_count(struct pci_dev *dev) ...@@ -680,7 +680,7 @@ int pci_msi_vec_count(struct pci_dev *dev)
} }
EXPORT_SYMBOL(pci_msi_vec_count); EXPORT_SYMBOL(pci_msi_vec_count);
static void pci_msi_shutdown(struct pci_dev *dev) void pci_msi_shutdown(struct pci_dev *dev)
{ {
struct msi_desc *desc; struct msi_desc *desc;
...@@ -701,18 +701,6 @@ static void pci_msi_shutdown(struct pci_dev *dev) ...@@ -701,18 +701,6 @@ static void pci_msi_shutdown(struct pci_dev *dev)
pcibios_alloc_irq(dev); pcibios_alloc_irq(dev);
} }
void pci_disable_msi(struct pci_dev *dev)
{
if (!pci_msi_enable || !dev || !dev->msi_enabled)
return;
msi_lock_descs(&dev->dev);
pci_msi_shutdown(dev);
free_msi_irqs(dev);
msi_unlock_descs(&dev->dev);
}
EXPORT_SYMBOL(pci_disable_msi);
/** /**
* pci_msix_vec_count - return the number of device's MSI-X table entries * pci_msix_vec_count - return the number of device's MSI-X table entries
* @dev: pointer to the pci_dev data structure of MSI-X device function * @dev: pointer to the pci_dev data structure of MSI-X device function
...@@ -797,7 +785,7 @@ void pci_disable_msix(struct pci_dev *dev) ...@@ -797,7 +785,7 @@ void pci_disable_msix(struct pci_dev *dev)
msi_lock_descs(&dev->dev); msi_lock_descs(&dev->dev);
pci_msix_shutdown(dev); pci_msix_shutdown(dev);
free_msi_irqs(dev); pci_free_msi_irqs(dev);
msi_unlock_descs(&dev->dev); msi_unlock_descs(&dev->dev);
} }
EXPORT_SYMBOL(pci_disable_msix); EXPORT_SYMBOL(pci_disable_msix);
......
...@@ -84,6 +84,10 @@ static inline __attribute_const__ u32 msi_multi_mask(struct msi_desc *desc) ...@@ -84,6 +84,10 @@ static inline __attribute_const__ u32 msi_multi_mask(struct msi_desc *desc)
return (1 << (1 << desc->pci.msi_attrib.multi_cap)) - 1; return (1 << (1 << desc->pci.msi_attrib.multi_cap)) - 1;
} }
/* MSI internal functions invoked from the public APIs */
void pci_msi_shutdown(struct pci_dev *dev);
void pci_free_msi_irqs(struct pci_dev *dev);
/* Legacy (!IRQDOMAIN) fallbacks */ /* Legacy (!IRQDOMAIN) fallbacks */
#ifdef CONFIG_PCI_MSI_ARCH_FALLBACKS #ifdef CONFIG_PCI_MSI_ARCH_FALLBACKS
int pci_msi_legacy_setup_msi_irqs(struct pci_dev *dev, int nvec, int type); int pci_msi_legacy_setup_msi_irqs(struct pci_dev *dev, int nvec, int type);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment