Re: [PATCH 6.13] PCI/pwrctrl: Skip NULL of_node when unregistering

From: Lukas Wunner
Date: Sun Dec 01 2024 - 11:13:17 EST


On Sun, Dec 01, 2024 at 01:51:08PM +0530, Manivannan Sadhasivam wrote:
> So we create pwrctl devices starting from PCI bridges. This is because,
> in order for the endpoints to be enumerated, the relevant pwrctl drivers
> need to be probed first (i.e., pci_bus_add_device() will be called for
> the endpoints only when they are detected on the bus, but that cannot
> happen until the relevant pwrctl driver is probed). That's why we have
> the loop in pci_pwrctrl_create_devices() to iterate over the children
> of PCI bridges defined in devicetree.

I think a better approach would be to create a pwrctrl device when
the corresponding PCI device is scanned.

In pci_scan_child_bus_extend(), you'll find this loop:

/* Go find them, Rover! */
for (devfn = 0; devfn < 256; devfn += 8)
pci_scan_slot(bus, devfn);

... where pci_scan_slot() reads the Vendor ID to determine whether
a device is present at the devfn address and then goes on to
create the pci_dev.

I think what you want to do is, just before the Vendor ID is read,
create the pwrctrl device and enable power. The OF node of the
pwrctrl device can be found by way of the devfn, right? So you
can just search whether an OF node exists for a given devfn.

Moreover, for multifunction devices I think you may want to use
refcounting so that the pwrctrl device does not cut power unless
the refcount reaches zero.

Thanks,

Lukas