Re: [v6 1/5] PCI: Introduce generic capability search functions

From: Manivannan Sadhasivam
Date: Thu Mar 27 2025 - 12:57:19 EST


On Mon, Mar 24, 2025 at 12:48:48AM +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:
>
> Add pci_host_bridge_find_*capability() in pci-host-helpers.c, accepting
> controller-specific read functions and device data as parameters.
>
> 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
>
> Signed-off-by: Hans Zhang <18255117159@xxxxxxx>
> ---
> Changes since v5:
> https://lore.kernel.org/linux-pci/20250321163803.391056-2-18255117159@xxxxxxx
>
> - If you put the helpers in drivers/pci/pci.c, they unnecessarily enlarge
> the kernel's .text section even if it's known already at compile time
> that they're never going to be used (e.g. on x86).
>
> - Move the API for find capabilitys to a new file called
> pci-host-helpers.c.
>
> Changes since v4:
> https://lore.kernel.org/linux-pci/20250321101710.371480-2-18255117159@xxxxxxx
>
> - Resolved [v4 1/4] compilation warning.
> - The patch commit message were modified.
> ---
> drivers/pci/controller/Kconfig | 17 ++++
> drivers/pci/controller/Makefile | 1 +
> drivers/pci/controller/pci-host-helpers.c | 98 +++++++++++++++++++++++
> drivers/pci/pci.h | 7 ++
> 4 files changed, 123 insertions(+)
> create mode 100644 drivers/pci/controller/pci-host-helpers.c
>
> diff --git a/drivers/pci/controller/Kconfig b/drivers/pci/controller/Kconfig
> index 9800b7681054..0020a892a55b 100644
> --- a/drivers/pci/controller/Kconfig
> +++ b/drivers/pci/controller/Kconfig
> @@ -132,6 +132,23 @@ config PCI_HOST_GENERIC
> Say Y here if you want to support a simple generic PCI host
> controller, such as the one emulated by kvmtool.
>
> +config PCI_HOST_HELPERS
> + bool
> + prompt "PCI Host Controller Helper Functions" if EXPERT

User is not required to select this Kconfig option so that his driver can build.
Please make this symbol invisible to user and make it selected by the required
controller drivers only.

- Mani

--
மணிவண்ணன் சதாசிவம்