Re: [v4 1/4] PCI: Introduce generic capability search functions

From: Hans Zhang
Date: Fri Mar 21 2025 - 10:01:38 EST




On 2025/3/21 21:00, Manivannan Sadhasivam wrote:
On Fri, Mar 21, 2025 at 06:17:07PM +0800, Hans Zhang wrote:
Existing controller drivers (e.g., DWC, custom out-of-tree drivers)
duplicate logic for scanning PCI capability lists. This creates
maintenance burdens and risks inconsistencies.

To resolve this:

1. Add pci_generic_find_capability() and pci_generic_find_ext_capability()
in drivers/pci/pci.c, accepting controller-specific read functions
and device data as parameters.


I'd reword pci_generic* as pci_host_bridge* to reflect the fact that these APIs
are meant for host bridges.


Hi Mani,

Thanks your for reply. Will change.

2. Refactor dwc_pcie_find_capability() and similar functions to utilize
these new generic interfaces.


This is not part of this patch. So should be dropped.

Will change.

3. Update out-of-tree drivers to leverage the common implementation,
eliminating code duplication.


This also.

Will change.

This approach:
- Centralizes critical PCI capability scanning logic
- Allows flexible adaptation to varied hardware access methods
- Reduces future maintenance overhead
- Aligns with kernel code reuse best practices

Tested with DWC PCIe controller and CDNS PCIe drivers.


This tested info is also not required since the DWC and CDNS changes are not
part of this patch.

Will change.

Best regards,
Hans