Skip to content

Commit b12d0be

Browse files
Ahmed S. DarwishKAGA-KOKO
authored andcommitted
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: Thomas Gleixner <[email protected]> Signed-off-by: Ahmed S. Darwish <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: Bjorn Helgaas <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent c93fd52 commit b12d0be

File tree

4 files changed

+47
-19
lines changed

4 files changed

+47
-19
lines changed

drivers/pci/msi/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
#
33
# Makefile for the PCI/MSI
44
obj-$(CONFIG_PCI) += pcidev_msi.o
5-
obj-$(CONFIG_PCI_MSI) += msi.o
6-
obj-$(CONFIG_PCI_MSI) += irqdomain.o
5+
obj-$(CONFIG_PCI_MSI) += api.o msi.o irqdomain.o
76
obj-$(CONFIG_PCI_MSI_ARCH_FALLBACKS) += legacy.o

drivers/pci/msi/api.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* PCI MSI/MSI-X — Exported APIs for device drivers
4+
*
5+
* Copyright (C) 2003-2004 Intel
6+
* Copyright (C) Tom Long Nguyen ([email protected])
7+
* Copyright (C) 2016 Christoph Hellwig.
8+
* Copyright (C) 2022 Linutronix GmbH
9+
*/
10+
11+
#include <linux/export.h>
12+
13+
#include "msi.h"
14+
15+
/**
16+
* pci_disable_msi() - Disable MSI interrupt mode on device
17+
* @dev: the PCI device to operate on
18+
*
19+
* Legacy device driver API to disable MSI interrupt mode on device,
20+
* free earlier allocated interrupt vectors, and restore INTx emulation.
21+
* The PCI device Linux IRQ (@dev->irq) is restored to its default
22+
* pin-assertion IRQ. This is the cleanup pair of pci_enable_msi().
23+
*
24+
* NOTE: The newer pci_alloc_irq_vectors() / pci_free_irq_vectors() API
25+
* pair should, in general, be used instead.
26+
*/
27+
void pci_disable_msi(struct pci_dev *dev)
28+
{
29+
if (!pci_msi_enabled() || !dev || !dev->msi_enabled)
30+
return;
31+
32+
msi_lock_descs(&dev->dev);
33+
pci_msi_shutdown(dev);
34+
pci_free_msi_irqs(dev);
35+
msi_unlock_descs(&dev->dev);
36+
}
37+
EXPORT_SYMBOL(pci_disable_msi);

drivers/pci/msi/msi.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg)
163163
}
164164
EXPORT_SYMBOL_GPL(pci_write_msi_msg);
165165

166-
static void free_msi_irqs(struct pci_dev *dev)
166+
void pci_free_msi_irqs(struct pci_dev *dev)
167167
{
168168
pci_msi_teardown_msi_irqs(dev);
169169

@@ -413,7 +413,7 @@ static int msi_capability_init(struct pci_dev *dev, int nvec,
413413

414414
err:
415415
pci_msi_unmask(entry, msi_multi_mask(entry));
416-
free_msi_irqs(dev);
416+
pci_free_msi_irqs(dev);
417417
fail:
418418
dev->msi_enabled = 0;
419419
unlock:
@@ -531,7 +531,7 @@ static int msix_setup_interrupts(struct pci_dev *dev, void __iomem *base,
531531
goto out_unlock;
532532

533533
out_free:
534-
free_msi_irqs(dev);
534+
pci_free_msi_irqs(dev);
535535
out_unlock:
536536
msi_unlock_descs(&dev->dev);
537537
kfree(masks);
@@ -680,7 +680,7 @@ int pci_msi_vec_count(struct pci_dev *dev)
680680
}
681681
EXPORT_SYMBOL(pci_msi_vec_count);
682682

683-
static void pci_msi_shutdown(struct pci_dev *dev)
683+
void pci_msi_shutdown(struct pci_dev *dev)
684684
{
685685
struct msi_desc *desc;
686686

@@ -701,18 +701,6 @@ static void pci_msi_shutdown(struct pci_dev *dev)
701701
pcibios_alloc_irq(dev);
702702
}
703703

704-
void pci_disable_msi(struct pci_dev *dev)
705-
{
706-
if (!pci_msi_enable || !dev || !dev->msi_enabled)
707-
return;
708-
709-
msi_lock_descs(&dev->dev);
710-
pci_msi_shutdown(dev);
711-
free_msi_irqs(dev);
712-
msi_unlock_descs(&dev->dev);
713-
}
714-
EXPORT_SYMBOL(pci_disable_msi);
715-
716704
/**
717705
* pci_msix_vec_count - return the number of device's MSI-X table entries
718706
* @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)
797785

798786
msi_lock_descs(&dev->dev);
799787
pci_msix_shutdown(dev);
800-
free_msi_irqs(dev);
788+
pci_free_msi_irqs(dev);
801789
msi_unlock_descs(&dev->dev);
802790
}
803791
EXPORT_SYMBOL(pci_disable_msix);

drivers/pci/msi/msi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ static inline __attribute_const__ u32 msi_multi_mask(struct msi_desc *desc)
8484
return (1 << (1 << desc->pci.msi_attrib.multi_cap)) - 1;
8585
}
8686

87+
/* MSI internal functions invoked from the public APIs */
88+
void pci_msi_shutdown(struct pci_dev *dev);
89+
void pci_free_msi_irqs(struct pci_dev *dev);
90+
8791
/* Legacy (!IRQDOMAIN) fallbacks */
8892
#ifdef CONFIG_PCI_MSI_ARCH_FALLBACKS
8993
int pci_msi_legacy_setup_msi_irqs(struct pci_dev *dev, int nvec, int type);

0 commit comments

Comments
 (0)