linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v14 0/7] Refactor capability search into common macros
@ 2025-07-16 16:11 Hans Zhang
  2025-07-16 16:11 ` [PATCH v14 1/7] PCI: Introduce generic bus config read helper function Hans Zhang
                   ` (7 more replies)
  0 siblings, 8 replies; 36+ messages in thread
From: Hans Zhang @ 2025-07-16 16:11 UTC (permalink / raw)
  To: lpieralisi, kwilczynski, bhelgaas, helgaas, jingoohan1, mani
  Cc: robh, ilpo.jarvinen, linux-pci, linux-kernel, Hans Zhang

Dear Maintainers,

This patch series addresses long-standing code duplication in PCI
capability discovery logic across the PCI core and controller drivers.
The existing implementation ties capability search to fully initialized
PCI device structures, limiting its usability during early controller
initialization phases where device/bus structures may not yet be
available.

The primary goal is to decouple capability discovery from PCI device
dependencies by introducing a unified framework using config space
accessor-based macros. This enables:

1. Early Capability Discovery: Host controllers (e.g., Cadence, DWC)
can now perform capability searches during pre-initialization stages
using their native config accessors.

2. Code Consolidation: Common logic for standard and extended capability
searches is refactored into shared macros (`PCI_FIND_NEXT_CAP` and
`PCI_FIND_NEXT_EXT_CAP`), eliminating redundant implementations.

3. Safety and Maintainability: TTL checks are centralized within the
macros to prevent infinite loops, while hardcoded offsets in drivers
are replaced with dynamic discovery, reducing fragility.

Key improvements include:  
- Driver Conversions: DesignWare and Cadence drivers are migrated to
  use the new macros, removing device-specific assumptions and ensuring
  consistent error handling.

- Enhanced Readability: Magic numbers are replaced with symbolic
  constants, and config space accessors are standardized for clarity.

- Backward Compatibility: Existing PCI core behavior remains unchanged.

---
Changes since v13:
- Split patch 3/6 into two patches for searching standard and extended capability. (Bjorn)
- Optimize the code based on the review comments from Bjorn.
- Patch 5/7 and 6/7 use simplified macro definitions: PCI_FIND_NEXT_CAP(), PCI_FIND_NEXT_EXT_CAP().
- The other patches have not been modified.

Changes since v12:
- Modify some commit messages, code format issues, and optimize the function return values.

Changes since v11:
- Resolved some compilation warning.
- Add some include.
- Add the *** BLURB HERE *** description(Corrected by Mani and Krzysztof).

Changes since v10:
- The patch [v10 2/6] remove #include <uapi/linux/pci_regs.h> and add macro definition comments.
- The patch [v10 3/6] remove #include <uapi/linux/pci_regs.h> and commit message were modified.
- The other patches have not been modified.

Changes since v9:
- Resolved [v9 4/6] compilation error.
  The latest 6.15 rc1 merge __dw_pcie_find_vsec_capability, which uses 
  dw_pcie_find_next_ext_capability.
- The other patches have not been modified.

Changes since v8:
- Split patch.
- The patch commit message were modified.
- Other patches(4/6, 5/6, 6/6) are unchanged.

Changes since v7:
- Patch 2/5 and 3/5 compilation error resolved.
- Other patches are unchanged.

Changes since v6:
- Refactor capability search into common macros.
- Delete pci-host-helpers.c and MAINTAINERS.

Changes since v5:
- 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.
- Add new patch for MAINTAINERS.

Changes since v4:
- Resolved [v4 1/4] compilation warning.
- The patch subject and commit message were modified.

Changes since v3:
- Resolved [v3 1/4] compilation error.
- Other patches are not modified.

Changes since v2:
- Add and split into a series of patches.
---

Hans Zhang (7):
  PCI: Introduce generic bus config read helper function
  PCI: Clean up __pci_find_next_cap_ttl() readability
  PCI: Refactor standard capability search into common macro
  PCI: Refactor extended capability search into common macro
  PCI: dwc: Use common PCI host bridge APIs for finding the capabilities
  PCI: cadence: Use common PCI host bridge APIs for finding the
    capabilities
  PCI: cadence: Use cdns_pcie_find_*capability to avoid hardcode

 drivers/pci/access.c                          | 15 ++++
 .../pci/controller/cadence/pcie-cadence-ep.c  | 38 ++++----
 drivers/pci/controller/cadence/pcie-cadence.c | 30 +++++++
 drivers/pci/controller/cadence/pcie-cadence.h | 18 ++--
 drivers/pci/controller/dwc/pcie-designware.c  | 83 ++++--------------
 drivers/pci/pci.c                             | 76 +++-------------
 drivers/pci/pci.h                             | 87 +++++++++++++++++++
 include/uapi/linux/pci_regs.h                 |  3 +
 8 files changed, 196 insertions(+), 154 deletions(-)


base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
-- 
2.25.1


^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2025-08-13  7:51 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-16 16:11 [PATCH v14 0/7] Refactor capability search into common macros Hans Zhang
2025-07-16 16:11 ` [PATCH v14 1/7] PCI: Introduce generic bus config read helper function Hans Zhang
2025-07-16 16:11 ` [PATCH v14 2/7] PCI: Clean up __pci_find_next_cap_ttl() readability Hans Zhang
2025-07-16 16:11 ` [PATCH v14 3/7] PCI: Refactor standard capability search into common macro Hans Zhang
2025-07-16 16:12 ` [PATCH v14 4/7] PCI: Refactor extended " Hans Zhang
2025-07-16 16:12 ` [PATCH v14 5/7] PCI: dwc: Use common PCI host bridge APIs for finding the capabilities Hans Zhang
2025-07-16 16:12 ` [PATCH v14 6/7] PCI: cadence: " Hans Zhang
2025-07-16 16:12 ` [PATCH v14 7/7] PCI: cadence: Use cdns_pcie_find_*capability to avoid hardcode Hans Zhang
2025-07-16 23:11 ` [PATCH v14 0/7] Refactor capability search into common macros Bjorn Helgaas
2025-07-31  7:32   ` [REGRESSION] next/master: suspect endianness issue in common PCI capability search macro Gerd Bayer
2025-07-31 17:38     ` [PATCH] PCI: Fix endianness issues in pci_bus_read_config() Gerd Bayer
2025-07-31 18:39       ` Bjorn Helgaas
2025-07-31 19:01         ` Arnd Bergmann
2025-08-01  8:18           ` Manivannan Sadhasivam
2025-08-01  9:25             ` Hans Zhang
2025-08-01  9:47               ` Manivannan Sadhasivam
2025-08-01 10:06                 ` Hans Zhang
2025-08-01 10:54                   ` Manivannan Sadhasivam
2025-08-01 11:30                     ` Gerd Bayer
2025-08-01 16:54                       ` Hans Zhang
2025-08-01 18:08                         ` Keith Busch
2025-08-02 15:23                           ` Hans Zhang
2025-08-02 15:40                             ` Arnd Bergmann
2025-08-04  3:06                       ` Hans Zhang
2025-08-04  8:03                         ` Arnd Bergmann
2025-08-04  8:25                           ` Hans Zhang
2025-08-04 10:09                         ` Gerd Bayer
2025-08-12 14:44                           ` Hans Zhang
2025-08-13  7:47                             ` Niklas Schnelle
2025-08-13  7:50                               ` Hans Zhang
2025-08-04 14:33                         ` Bjorn Helgaas
2025-08-04 15:04                           ` Hans Zhang
2025-08-01 16:47                     ` Hans Zhang
2025-07-31 18:53       ` Lukas Wunner
2025-08-01  7:52       ` Geert Uytterhoeven
2025-08-01 13:00   ` [PATCH v14 0/7] Refactor capability search into common macros Bjorn Helgaas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).