Skip to content

Commit 3a33020

Browse files
Hans Zhangbjorn-helgaas
authored andcommitted
PCI: dwc: ep: Implement capability search using PCI core APIs
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
1 parent 8ffc9f2 commit 3a33020

2 files changed

Lines changed: 23 additions & 29 deletions

File tree

drivers/pci/controller/dwc/pcie-designware-ep.c

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -69,37 +69,10 @@ void dw_pcie_ep_reset_bar(struct dw_pcie *pci, enum pci_barno bar)
6969
}
7070
EXPORT_SYMBOL_GPL(dw_pcie_ep_reset_bar);
7171

72-
static u8 __dw_pcie_ep_find_next_cap(struct dw_pcie_ep *ep, u8 func_no,
73-
u8 cap_ptr, u8 cap)
74-
{
75-
u8 cap_id, next_cap_ptr;
76-
u16 reg;
77-
78-
if (!cap_ptr)
79-
return 0;
80-
81-
reg = dw_pcie_ep_readw_dbi(ep, func_no, cap_ptr);
82-
cap_id = (reg & 0x00ff);
83-
84-
if (cap_id > PCI_CAP_ID_MAX)
85-
return 0;
86-
87-
if (cap_id == cap)
88-
return cap_ptr;
89-
90-
next_cap_ptr = (reg & 0xff00) >> 8;
91-
return __dw_pcie_ep_find_next_cap(ep, func_no, next_cap_ptr, cap);
92-
}
93-
9472
static u8 dw_pcie_ep_find_capability(struct dw_pcie_ep *ep, u8 func_no, u8 cap)
9573
{
96-
u8 next_cap_ptr;
97-
u16 reg;
98-
99-
reg = dw_pcie_ep_readw_dbi(ep, func_no, PCI_CAPABILITY_LIST);
100-
next_cap_ptr = (reg & 0x00ff);
101-
102-
return __dw_pcie_ep_find_next_cap(ep, func_no, next_cap_ptr, cap);
74+
return PCI_FIND_NEXT_CAP(dw_pcie_ep_read_cfg, PCI_CAPABILITY_LIST,
75+
cap, ep, func_no);
10376
}
10477

10578
/**

drivers/pci/controller/dwc/pcie-designware.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,27 @@ static inline u8 dw_pcie_ep_readb_dbi(struct dw_pcie_ep *ep, u8 func_no,
695695
return dw_pcie_ep_read_dbi(ep, func_no, reg, 0x1);
696696
}
697697

698+
static inline int dw_pcie_ep_read_cfg_byte(struct dw_pcie_ep *ep, u8 func_no,
699+
int where, u8 *val)
700+
{
701+
*val = dw_pcie_ep_readb_dbi(ep, func_no, where);
702+
return PCIBIOS_SUCCESSFUL;
703+
}
704+
705+
static inline int dw_pcie_ep_read_cfg_word(struct dw_pcie_ep *ep, u8 func_no,
706+
int where, u16 *val)
707+
{
708+
*val = dw_pcie_ep_readw_dbi(ep, func_no, where);
709+
return PCIBIOS_SUCCESSFUL;
710+
}
711+
712+
static inline int dw_pcie_ep_read_cfg_dword(struct dw_pcie_ep *ep, u8 func_no,
713+
int where, u32 *val)
714+
{
715+
*val = dw_pcie_ep_readl_dbi(ep, func_no, where);
716+
return PCIBIOS_SUCCESSFUL;
717+
}
718+
698719
static inline unsigned int dw_pcie_ep_get_dbi2_offset(struct dw_pcie_ep *ep,
699720
u8 func_no)
700721
{

0 commit comments

Comments
 (0)