]> www.infradead.org Git - users/hch/misc.git/commitdiff
PCI: dwc: ep: Implement capability search using PCI core APIs
authorHans Zhang <18255117159@163.com>
Tue, 19 Aug 2025 14:58:28 +0000 (22:58 +0800)
committerBjorn Helgaas <bhelgaas@google.com>
Wed, 20 Aug 2025 20:56:19 +0000 (15:56 -0500)
The PCI core now provides generic PCI_FIND_NEXT_CAP() macros to search for
PCI capabilities, using config accessors we supply.

Use them in the DWC EP driver to implement dw_pcie_ep_find_capability()
instead of duplicating the algorithm.

Signed-off-by: Hans Zhang <18255117159@163.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Link: https://patch.msgid.link/20250819145828.438541-1-18255117159@163.com
drivers/pci/controller/dwc/pcie-designware-ep.c
drivers/pci/controller/dwc/pcie-designware.h

index 0ae54a94809ba90ddd10a80c80afc98304ca6ddb..7f2112c2fb21543d11e848a4a62d529cc3f4e8d0 100644 (file)
@@ -69,37 +69,10 @@ void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar)
 }
 EXPORT_SYMBOL_GPL(dw_pcie_ep_reset_bar);
 
-static u8 __dw_pcie_ep_find_next_cap(struct dw_pcie_ep *ep, u8 func_no,
-                                    u8 cap_ptr, u8 cap)
-{
-       u8 cap_id, next_cap_ptr;
-       u16 reg;
-
-       if (!cap_ptr)
-               return 0;
-
-       reg = dw_pcie_ep_readw_dbi(ep, func_no, cap_ptr);
-       cap_id = (reg & 0x00ff);
-
-       if (cap_id > PCI_CAP_ID_MAX)
-               return 0;
-
-       if (cap_id == cap)
-               return cap_ptr;
-
-       next_cap_ptr = (reg & 0xff00) >> 8;
-       return __dw_pcie_ep_find_next_cap(ep, func_no, next_cap_ptr, cap);
-}
-
 static u8 dw_pcie_ep_find_capability(struct dw_pcie_ep *ep, u8 func_no, u8 cap)
 {
-       u8 next_cap_ptr;
-       u16 reg;
-
-       reg = dw_pcie_ep_readw_dbi(ep, func_no, PCI_CAPABILITY_LIST);
-       next_cap_ptr = (reg & 0x00ff);
-
-       return __dw_pcie_ep_find_next_cap(ep, func_no, next_cap_ptr, cap);
+       return PCI_FIND_NEXT_CAP(dw_pcie_ep_read_cfg, PCI_CAPABILITY_LIST,
+                                cap, ep, func_no);
 }
 
 /**
index b5e7e18138a656853cc62fa785a7034055d4d1fb..a44f2113925deffaad1088308e98aa570dcc0c31 100644 (file)
@@ -695,6 +695,27 @@ static inline u8 dw_pcie_ep_readb_dbi(struct dw_pcie_ep *ep, u8 func_no,
        return dw_pcie_ep_read_dbi(ep, func_no, reg, 0x1);
 }
 
+static inline int dw_pcie_ep_read_cfg_byte(struct dw_pcie_ep *ep, u8 func_no,
+                                          int where, u8 *val)
+{
+       *val = dw_pcie_ep_readb_dbi(ep, func_no, where);
+       return PCIBIOS_SUCCESSFUL;
+}
+
+static inline int dw_pcie_ep_read_cfg_word(struct dw_pcie_ep *ep, u8 func_no,
+                                          int where, u16 *val)
+{
+       *val = dw_pcie_ep_readw_dbi(ep, func_no, where);
+       return PCIBIOS_SUCCESSFUL;
+}
+
+static inline int dw_pcie_ep_read_cfg_dword(struct dw_pcie_ep *ep, u8 func_no,
+                                           int where, u32 *val)
+{
+       *val = dw_pcie_ep_readl_dbi(ep, func_no, where);
+       return PCIBIOS_SUCCESSFUL;
+}
+
 static inline unsigned int dw_pcie_ep_get_dbi2_offset(struct dw_pcie_ep *ep,
                                                      u8 func_no)
 {