Commit 0d21e71a authored by Rob Herring's avatar Rob Herring Committed by Bjorn Helgaas

PCI: Restrict device disabled status check to DT

Commit 6fffbc7a ("PCI: Honor firmware's device disabled status")
checked the firmware device status for both DT and ACPI devices. That
caused a regression in some ACPI systems. The exact reason isn't clear.
It's possibly a firmware bug. For now, at least, refactor the check to
be for DT based systems only.

Note that the original implementation leaked a refcount which is now
correctly handled.

[bhelgaas: Per ACPI r6.5, sec 6.3.7, for devices on an enumerable bus, _STA
must return with bit[0] ("device is present") set]

Link: https://lore.kernel.org/all/m2fs9lgndw.fsf@gmail.com/
Fixes: 6fffbc7a ("PCI: Honor firmware's device disabled status")
Link: https://lore.kernel.org/r/20230419193513.708818-1-robh@kernel.org
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217317Reported-by: default avatarDonald Hunter <donald.hunter@gmail.com>
Reported-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Tested-by: default avatarDonald Hunter <donald.hunter@gmail.com>
Tested-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Cc: Binbin Zhou <zhoubinbin@loongson.cn>
Cc: Liu Peibao <liupeibao@loongson.cn>
Cc: Huacai Chen <chenhuacai@loongson.cn>
parent fe15c26e
...@@ -16,14 +16,32 @@ ...@@ -16,14 +16,32 @@
#include "pci.h" #include "pci.h"
#ifdef CONFIG_PCI #ifdef CONFIG_PCI
void pci_set_of_node(struct pci_dev *dev) /**
* pci_set_of_node - Find and set device's DT device_node
* @dev: the PCI device structure to fill
*
* Returns 0 on success with of_node set or when no device is described in the
* DT. Returns -ENODEV if the device is present, but disabled in the DT.
*/
int pci_set_of_node(struct pci_dev *dev)
{ {
struct device_node *node;
if (!dev->bus->dev.of_node) if (!dev->bus->dev.of_node)
return; return 0;
dev->dev.of_node = of_pci_find_child_device(dev->bus->dev.of_node,
dev->devfn); node = of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn);
if (dev->dev.of_node) if (!node)
dev->dev.fwnode = &dev->dev.of_node->fwnode; return 0;
if (!of_device_is_available(node)) {
of_node_put(node);
return -ENODEV;
}
dev->dev.of_node = node;
dev->dev.fwnode = &node->fwnode;
return 0;
} }
void pci_release_of_node(struct pci_dev *dev) void pci_release_of_node(struct pci_dev *dev)
......
...@@ -624,7 +624,7 @@ int of_pci_get_max_link_speed(struct device_node *node); ...@@ -624,7 +624,7 @@ int of_pci_get_max_link_speed(struct device_node *node);
u32 of_pci_get_slot_power_limit(struct device_node *node, u32 of_pci_get_slot_power_limit(struct device_node *node,
u8 *slot_power_limit_value, u8 *slot_power_limit_value,
u8 *slot_power_limit_scale); u8 *slot_power_limit_scale);
void pci_set_of_node(struct pci_dev *dev); int pci_set_of_node(struct pci_dev *dev);
void pci_release_of_node(struct pci_dev *dev); void pci_release_of_node(struct pci_dev *dev);
void pci_set_bus_of_node(struct pci_bus *bus); void pci_set_bus_of_node(struct pci_bus *bus);
void pci_release_bus_of_node(struct pci_bus *bus); void pci_release_bus_of_node(struct pci_bus *bus);
...@@ -662,7 +662,7 @@ of_pci_get_slot_power_limit(struct device_node *node, ...@@ -662,7 +662,7 @@ of_pci_get_slot_power_limit(struct device_node *node,
return 0; return 0;
} }
static inline void pci_set_of_node(struct pci_dev *dev) { } static inline int pci_set_of_node(struct pci_dev *dev) { return 0; }
static inline void pci_release_of_node(struct pci_dev *dev) { } static inline void pci_release_of_node(struct pci_dev *dev) { }
static inline void pci_set_bus_of_node(struct pci_bus *bus) { } static inline void pci_set_bus_of_node(struct pci_bus *bus) { }
static inline void pci_release_bus_of_node(struct pci_bus *bus) { } static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
......
...@@ -1826,7 +1826,7 @@ int pci_setup_device(struct pci_dev *dev) ...@@ -1826,7 +1826,7 @@ int pci_setup_device(struct pci_dev *dev)
u32 class; u32 class;
u16 cmd; u16 cmd;
u8 hdr_type; u8 hdr_type;
int pos = 0; int err, pos = 0;
struct pci_bus_region region; struct pci_bus_region region;
struct resource *res; struct resource *res;
...@@ -1840,10 +1840,10 @@ int pci_setup_device(struct pci_dev *dev) ...@@ -1840,10 +1840,10 @@ int pci_setup_device(struct pci_dev *dev)
dev->error_state = pci_channel_io_normal; dev->error_state = pci_channel_io_normal;
set_pcie_port_type(dev); set_pcie_port_type(dev);
pci_set_of_node(dev); err = pci_set_of_node(dev);
if (err)
return err;
pci_set_acpi_fwnode(dev); pci_set_acpi_fwnode(dev);
if (dev->dev.fwnode && !fwnode_device_is_available(dev->dev.fwnode))
return -ENODEV;
pci_dev_assign_slot(dev); pci_dev_assign_slot(dev);
......
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