Skip to content

Commit 0d21e71

Browse files
robherringbjorn-helgaas
authored andcommitted
PCI: Restrict device disabled status check to DT
Commit 6fffbc7 ("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: 6fffbc7 ("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=217317 Reported-by: Donald Hunter <donald.hunter@gmail.com> Reported-by: Vitaly Kuznetsov <vkuznets@redhat.com> Tested-by: Donald Hunter <donald.hunter@gmail.com> Tested-by: Vitaly Kuznetsov <vkuznets@redhat.com> Signed-off-by: Rob Herring <robh@kernel.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Cc: Binbin Zhou <zhoubinbin@loongson.cn> Cc: Liu Peibao <liupeibao@loongson.cn> Cc: Huacai Chen <chenhuacai@loongson.cn>
1 parent fe15c26 commit 0d21e71

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

drivers/pci/of.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,32 @@
1616
#include "pci.h"
1717

1818
#ifdef CONFIG_PCI
19-
void pci_set_of_node(struct pci_dev *dev)
19+
/**
20+
* pci_set_of_node - Find and set device's DT device_node
21+
* @dev: the PCI device structure to fill
22+
*
23+
* Returns 0 on success with of_node set or when no device is described in the
24+
* DT. Returns -ENODEV if the device is present, but disabled in the DT.
25+
*/
26+
int pci_set_of_node(struct pci_dev *dev)
2027
{
28+
struct device_node *node;
29+
2130
if (!dev->bus->dev.of_node)
22-
return;
23-
dev->dev.of_node = of_pci_find_child_device(dev->bus->dev.of_node,
24-
dev->devfn);
25-
if (dev->dev.of_node)
26-
dev->dev.fwnode = &dev->dev.of_node->fwnode;
31+
return 0;
32+
33+
node = of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn);
34+
if (!node)
35+
return 0;
36+
37+
if (!of_device_is_available(node)) {
38+
of_node_put(node);
39+
return -ENODEV;
40+
}
41+
42+
dev->dev.of_node = node;
43+
dev->dev.fwnode = &node->fwnode;
44+
return 0;
2745
}
2846

2947
void pci_release_of_node(struct pci_dev *dev)

drivers/pci/pci.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ int of_pci_get_max_link_speed(struct device_node *node);
624624
u32 of_pci_get_slot_power_limit(struct device_node *node,
625625
u8 *slot_power_limit_value,
626626
u8 *slot_power_limit_scale);
627-
void pci_set_of_node(struct pci_dev *dev);
627+
int pci_set_of_node(struct pci_dev *dev);
628628
void pci_release_of_node(struct pci_dev *dev);
629629
void pci_set_bus_of_node(struct pci_bus *bus);
630630
void pci_release_bus_of_node(struct pci_bus *bus);
@@ -662,7 +662,7 @@ of_pci_get_slot_power_limit(struct device_node *node,
662662
return 0;
663663
}
664664

665-
static inline void pci_set_of_node(struct pci_dev *dev) { }
665+
static inline int pci_set_of_node(struct pci_dev *dev) { return 0; }
666666
static inline void pci_release_of_node(struct pci_dev *dev) { }
667667
static inline void pci_set_bus_of_node(struct pci_bus *bus) { }
668668
static inline void pci_release_bus_of_node(struct pci_bus *bus) { }

drivers/pci/probe.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,7 @@ int pci_setup_device(struct pci_dev *dev)
18261826
u32 class;
18271827
u16 cmd;
18281828
u8 hdr_type;
1829-
int pos = 0;
1829+
int err, pos = 0;
18301830
struct pci_bus_region region;
18311831
struct resource *res;
18321832

@@ -1840,10 +1840,10 @@ int pci_setup_device(struct pci_dev *dev)
18401840
dev->error_state = pci_channel_io_normal;
18411841
set_pcie_port_type(dev);
18421842

1843-
pci_set_of_node(dev);
1843+
err = pci_set_of_node(dev);
1844+
if (err)
1845+
return err;
18441846
pci_set_acpi_fwnode(dev);
1845-
if (dev->dev.fwnode && !fwnode_device_is_available(dev->dev.fwnode))
1846-
return -ENODEV;
18471847

18481848
pci_dev_assign_slot(dev);
18491849

0 commit comments

Comments
 (0)