From: Hans Zhang <18255117159@163.com>
To: bhelgaas@google.com, lpieralisi@kernel.org,
kwilczynski@kernel.org, mani@kernel.org, s-vadapalli@ti.com,
a-garg7@ti.com
Cc: robh@kernel.org, linux-pci@vger.kernel.org,
linux-kernel@vger.kernel.org, Hans Zhang <18255117159@163.com>
Subject: [PATCH v2 2/3] PCI: cadence: Add cdns_pcie_get_pcie_cap() helper and cache capability offset
Date: Sat, 9 May 2026 21:07:15 +0800 [thread overview]
Message-ID: <20260509130716.2104103-3-18255117159@163.com> (raw)
In-Reply-To: <20260509130716.2104103-1-18255117159@163.com>
Add a helper cdns_pcie_get_pcie_cap() that finds and caches the
PCIe Capability offset in struct cdns_pcie::pcie_cap. This avoids
repeated searches and follows the pattern used in other PCIe drivers.
The helper uses cdns_pcie_find_capability() to locate PCI_CAP_ID_EXP
and stores the result for later use.
This is a preparatory step for removing the hardcoded capability
offset from host driver code.
Signed-off-by: Hans Zhang <18255117159@163.com>
---
drivers/pci/controller/cadence/pcie-cadence.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/drivers/pci/controller/cadence/pcie-cadence.h b/drivers/pci/controller/cadence/pcie-cadence.h
index c057f4b393e6..bbd275193bc1 100644
--- a/drivers/pci/controller/cadence/pcie-cadence.h
+++ b/drivers/pci/controller/cadence/pcie-cadence.h
@@ -219,6 +219,7 @@ struct cdns_plat_pcie_of_data {
* wrapper
* @cdns_pcie_reg_offsets: Register bank offsets for different SoC
* @debug_dir: debugfs node
+ * @pcie_cap: PCIe capability offset
*/
struct cdns_pcie {
void __iomem *reg_base;
@@ -233,6 +234,7 @@ struct cdns_pcie {
const struct cdns_pcie_ops *ops;
const struct cdns_plat_pcie_of_data *cdns_pcie_reg_offsets;
struct dentry *debug_dir;
+ u8 pcie_cap;
};
/**
@@ -651,6 +653,22 @@ static inline int cdns_pcie_hpa_ep_setup(struct cdns_pcie_ep *ep)
u8 cdns_pcie_find_capability(struct cdns_pcie *pcie, u8 cap);
u16 cdns_pcie_find_ext_capability(struct cdns_pcie *pcie, u8 cap);
+
+/**
+ * cdns_pcie_get_pcie_cap() - Return cached PCIe Capability offset
+ * @pcie: Cadence PCIe instance
+ *
+ * Finds and caches the offset of PCI_CAP_ID_EXP on first call.
+ * Returns 0 if the capability is not present.
+ */
+static inline u8 cdns_pcie_get_pcie_cap(struct cdns_pcie *pcie)
+{
+ if (!pcie->pcie_cap)
+ pcie->pcie_cap = cdns_pcie_find_capability(pcie, PCI_CAP_ID_EXP);
+
+ return pcie->pcie_cap;
+}
+
bool cdns_pcie_linkup(struct cdns_pcie *pcie);
void cdns_pcie_detect_quiet_min_delay_set(struct cdns_pcie *pcie);
--
2.34.1
next prev parent reply other threads:[~2026-05-09 13:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-09 13:07 [PATCH v2 0/3] PCI: cadence: Fix and generalize PCIe capability offset for Root Port Hans Zhang
2026-05-09 13:07 ` [PATCH v2 1/3] PCI: cadence: Fix Root Port configuration space access for LGA IP Hans Zhang
2026-05-09 13:07 ` Hans Zhang [this message]
2026-05-11 4:58 ` [PATCH v2 2/3] PCI: cadence: Add cdns_pcie_get_pcie_cap() helper and cache capability offset Aksh Garg
2026-05-09 13:07 ` [PATCH v2 3/3] PCI: cadence: Use dynamic PCIe capability offset in host driver Hans Zhang
2026-05-11 4:47 ` Aksh Garg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260509130716.2104103-3-18255117159@163.com \
--to=18255117159@163.com \
--cc=a-garg7@ti.com \
--cc=bhelgaas@google.com \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
--cc=robh@kernel.org \
--cc=s-vadapalli@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).