Skip to content

Commit f546e80

Browse files
Philipp Stannerbjorn-helgaas
authored andcommitted
PCI: Export pci_intx_unmanaged() and pcim_intx()
pci_intx() is a hybrid function which sometimes performs devres operations, depending on whether pcim_enable_device() has been used to enable the pci_dev. This sometimes-managed nature of the function is problematic. Notably, it causes the function to allocate under some circumstances which makes it unusable from interrupt context. Export pcim_intx() (which is always managed) and rename __pcim_intx() (which is never managed) to pci_intx_unmanaged() and export it as well. Then all callers of pci_intx() can be ported to the version they need, depending whether they use pci_enable_device() or pcim_enable_device(). Link: https://lore.kernel.org/r/20241209130632.132074-3-pstanner@redhat.com Signed-off-by: Philipp Stanner <pstanner@redhat.com> [bhelgaas: commit log] Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
1 parent 9dfc685 commit f546e80

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

drivers/pci/devres.c

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -411,31 +411,12 @@ static inline bool mask_contains_bar(int mask, int bar)
411411
return mask & BIT(bar);
412412
}
413413

414-
/*
415-
* This is a copy of pci_intx() used to bypass the problem of recursive
416-
* function calls due to the hybrid nature of pci_intx().
417-
*/
418-
static void __pcim_intx(struct pci_dev *pdev, int enable)
419-
{
420-
u16 pci_command, new;
421-
422-
pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
423-
424-
if (enable)
425-
new = pci_command & ~PCI_COMMAND_INTX_DISABLE;
426-
else
427-
new = pci_command | PCI_COMMAND_INTX_DISABLE;
428-
429-
if (new != pci_command)
430-
pci_write_config_word(pdev, PCI_COMMAND, new);
431-
}
432-
433414
static void pcim_intx_restore(struct device *dev, void *data)
434415
{
435416
struct pci_dev *pdev = to_pci_dev(dev);
436417
struct pcim_intx_devres *res = data;
437418

438-
__pcim_intx(pdev, res->orig_intx);
419+
pci_intx_unmanaged(pdev, res->orig_intx);
439420
}
440421

441422
static struct pcim_intx_devres *get_or_create_intx_devres(struct device *dev)
@@ -472,10 +453,11 @@ int pcim_intx(struct pci_dev *pdev, int enable)
472453
return -ENOMEM;
473454

474455
res->orig_intx = !enable;
475-
__pcim_intx(pdev, enable);
456+
pci_intx_unmanaged(pdev, enable);
476457

477458
return 0;
478459
}
460+
EXPORT_SYMBOL_GPL(pcim_intx);
479461

480462
static void pcim_disable_device(void *pdev_raw)
481463
{

drivers/pci/pci.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4479,6 +4479,35 @@ void pci_disable_parity(struct pci_dev *dev)
44794479
}
44804480
}
44814481

4482+
/**
4483+
* pci_intx_unmanaged - enables/disables PCI INTx for device dev,
4484+
* unmanaged version
4485+
* @pdev: the PCI device to operate on
4486+
* @enable: boolean: whether to enable or disable PCI INTx
4487+
*
4488+
* Enables/disables PCI INTx for device @pdev
4489+
*
4490+
* This function behavios identically to pci_intx(), but is never managed with
4491+
* devres.
4492+
*/
4493+
void pci_intx_unmanaged(struct pci_dev *pdev, int enable)
4494+
{
4495+
u16 pci_command, new;
4496+
4497+
pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
4498+
4499+
if (enable)
4500+
new = pci_command & ~PCI_COMMAND_INTX_DISABLE;
4501+
else
4502+
new = pci_command | PCI_COMMAND_INTX_DISABLE;
4503+
4504+
if (new == pci_command)
4505+
return;
4506+
4507+
pci_write_config_word(pdev, PCI_COMMAND, new);
4508+
}
4509+
EXPORT_SYMBOL_GPL(pci_intx_unmanaged);
4510+
44824511
/**
44834512
* pci_intx - enables/disables PCI INTx for device dev
44844513
* @pdev: the PCI device to operate on

include/linux/pci.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,7 @@ int __must_check pcim_set_mwi(struct pci_dev *dev);
13501350
int pci_try_set_mwi(struct pci_dev *dev);
13511351
void pci_clear_mwi(struct pci_dev *dev);
13521352
void pci_disable_parity(struct pci_dev *dev);
1353+
void pci_intx_unmanaged(struct pci_dev *pdev, int enable);
13531354
void pci_intx(struct pci_dev *dev, int enable);
13541355
bool pci_check_and_mask_intx(struct pci_dev *dev);
13551356
bool pci_check_and_unmask_intx(struct pci_dev *dev);
@@ -2297,6 +2298,7 @@ static inline void pci_fixup_device(enum pci_fixup_pass pass,
22972298
struct pci_dev *dev) { }
22982299
#endif
22992300

2301+
int pcim_intx(struct pci_dev *pdev, int enabled);
23002302
int pcim_request_all_regions(struct pci_dev *pdev, const char *name);
23012303
void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen);
23022304
void __iomem *pcim_iomap_region(struct pci_dev *pdev, int bar,

0 commit comments

Comments
 (0)