@@ -4966,6 +4966,8 @@ bool pci_device_is_present(struct pci_dev *pdev)
{
u32 v;
+ if (pdev->is_removed)
+ return false;
return pci_bus_read_dev_vendor_id(pdev->bus, pdev->devfn, &v, 0);
}
EXPORT_SYMBOL_GPL(pci_device_is_present);
@@ -936,28 +936,46 @@ struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops);
static inline int pci_read_config_byte(const struct pci_dev *dev, int where, u8 *val)
{
+ if (unlikely(dev->is_removed)) {
+ *val = ~0;
+ return -ENODEV;
+ }
return pci_bus_read_config_byte(dev->bus, dev->devfn, where, val);
}
static inline int pci_read_config_word(const struct pci_dev *dev, int where, u16 *val)
{
+ if (unlikely(dev->is_removed)) {
+ *val = ~0;
+ return -ENODEV;
+ }
return pci_bus_read_config_word(dev->bus, dev->devfn, where, val);
}
static inline int pci_read_config_dword(const struct pci_dev *dev, int where,
u32 *val)
{
+ if (unlikely(dev->is_removed)) {
+ *val = ~0;
+ return -ENODEV;
+ }
return pci_bus_read_config_dword(dev->bus, dev->devfn, where, val);
}
static inline int pci_write_config_byte(const struct pci_dev *dev, int where, u8 val)
{
+ if (unlikely(dev->is_removed))
+ return -ENODEV;
return pci_bus_write_config_byte(dev->bus, dev->devfn, where, val);
}
static inline int pci_write_config_word(const struct pci_dev *dev, int where, u16 val)
{
+ if (unlikely(dev->is_removed))
+ return -ENODEV;
return pci_bus_write_config_word(dev->bus, dev->devfn, where, val);
}
static inline int pci_write_config_dword(const struct pci_dev *dev, int where,
u32 val)
{
+ if (unlikely(dev->is_removed))
+ return -ENODEV;
return pci_bus_write_config_dword(dev->bus, dev->devfn, where, val);
}
If we've detected that the PCI device is removed, there is no need to access the device's config space. This patch has all the device config reads and writes return error when in such a state. If the device is not present on a config read, the value returned will be set to all 1's. This is the same as what hardware is expected to return when accessing a removed device, but software can do this faster without relying on hardware. When checking if a device is present, we short-cut the removal by returning the known state instead of querying the bus. Signed-off-by: Keith Busch <keith.busch@intel.com> Cc: Lukas Wunner <lukas@wunner.de> --- drivers/pci/pci.c | 2 ++ include/linux/pci.h | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+)