Skip to content

Commit 969c54c

Browse files
Philipp Stannergregkh
authored andcommitted
PCI: Export pci_intx_unmanaged() and pcim_intx()
[ Upstream commit f546e80 ] 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> Stable-dep-of: d555ed4 ("PCI: Restore original INTX_DISABLE bit by pcim_intx()") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 1711fd7 commit 969c54c

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
@@ -4480,6 +4480,35 @@ void pci_disable_parity(struct pci_dev *dev)
44804480
}
44814481
}
44824482

4483+
/**
4484+
* pci_intx_unmanaged - enables/disables PCI INTx for device dev,
4485+
* unmanaged version
4486+
* @pdev: the PCI device to operate on
4487+
* @enable: boolean: whether to enable or disable PCI INTx
4488+
*
4489+
* Enables/disables PCI INTx for device @pdev
4490+
*
4491+
* This function behavios identically to pci_intx(), but is never managed with
4492+
* devres.
4493+
*/
4494+
void pci_intx_unmanaged(struct pci_dev *pdev, int enable)
4495+
{
4496+
u16 pci_command, new;
4497+
4498+
pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
4499+
4500+
if (enable)
4501+
new = pci_command & ~PCI_COMMAND_INTX_DISABLE;
4502+
else
4503+
new = pci_command | PCI_COMMAND_INTX_DISABLE;
4504+
4505+
if (new == pci_command)
4506+
return;
4507+
4508+
pci_write_config_word(pdev, PCI_COMMAND, new);
4509+
}
4510+
EXPORT_SYMBOL_GPL(pci_intx_unmanaged);
4511+
44834512
/**
44844513
* pci_intx - enables/disables PCI INTx for device dev
44854514
* @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
@@ -1353,6 +1353,7 @@ int __must_check pcim_set_mwi(struct pci_dev *dev);
13531353
int pci_try_set_mwi(struct pci_dev *dev);
13541354
void pci_clear_mwi(struct pci_dev *dev);
13551355
void pci_disable_parity(struct pci_dev *dev);
1356+
void pci_intx_unmanaged(struct pci_dev *pdev, int enable);
13561357
void pci_intx(struct pci_dev *dev, int enable);
13571358
bool pci_check_and_mask_intx(struct pci_dev *dev);
13581359
bool pci_check_and_unmask_intx(struct pci_dev *dev);
@@ -2293,6 +2294,7 @@ static inline void pci_fixup_device(enum pci_fixup_pass pass,
22932294
struct pci_dev *dev) { }
22942295
#endif
22952296

2297+
int pcim_intx(struct pci_dev *pdev, int enabled);
22962298
int pcim_request_all_regions(struct pci_dev *pdev, const char *name);
22972299
void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen);
22982300
void __iomem *pcim_iomap_region(struct pci_dev *pdev, int bar,

0 commit comments

Comments
 (0)