1 | 1. Refactor capability search into common macros. | 1 | 1. Refactor capability search into common macros. |
---|---|---|---|
2 | 2. Refactor capability search functions to eliminate code duplication. | 2 | 2. Refactor capability search functions to eliminate code duplication. |
3 | 2. DWC/CDNS use common PCI host bridge macros for finding the | 3 | 2. DWC/CDNS use common PCI host bridge macros for finding the |
4 | capabilities. | 4 | capabilities. |
5 | 3. Use cdns_pcie_find_*capability to avoid hardcode. | 5 | 3. Use cdns_pcie_find_*capability to avoid hardcode. |
6 | |||
7 | Changes since v7: | ||
8 | - Patch 2/5 and 3/5 compilation error resolved. | ||
9 | - Other patches are unchanged. | ||
6 | 10 | ||
7 | Changes since v6: | 11 | Changes since v6: |
8 | - Refactor capability search into common macros. | 12 | - Refactor capability search into common macros. |
9 | - Delete pci-host-helpers.c and MAINTAINERS. | 13 | - Delete pci-host-helpers.c and MAINTAINERS. |
10 | 14 | ||
... | ... | ||
38 | 42 | ||
39 | .../pci/controller/cadence/pcie-cadence-ep.c | 40 +++++---- | 43 | .../pci/controller/cadence/pcie-cadence-ep.c | 40 +++++---- |
40 | drivers/pci/controller/cadence/pcie-cadence.c | 28 +++++++ | 44 | drivers/pci/controller/cadence/pcie-cadence.c | 28 +++++++ |
41 | drivers/pci/controller/cadence/pcie-cadence.h | 18 +++-- | 45 | drivers/pci/controller/cadence/pcie-cadence.h | 18 +++-- |
42 | drivers/pci/controller/dwc/pcie-designware.c | 72 ++--------------- | 46 | drivers/pci/controller/dwc/pcie-designware.c | 72 ++--------------- |
43 | drivers/pci/pci.c | 79 +++++------------- | 47 | drivers/pci/pci.c | 80 ++++++------------ |
44 | drivers/pci/pci.h | 81 +++++++++++++++++++ | 48 | drivers/pci/pci.h | 81 +++++++++++++++++++ |
45 | include/uapi/linux/pci_regs.h | 2 + | 49 | include/uapi/linux/pci_regs.h | 2 + |
46 | 7 files changed, 176 insertions(+), 144 deletions(-) | 50 | 7 files changed, 177 insertions(+), 144 deletions(-) |
47 | 51 | ||
48 | 52 | ||
49 | base-commit: acb4f33713b9f6cadb6143f211714c343465411c | 53 | base-commit: acb4f33713b9f6cadb6143f211714c343465411c |
50 | -- | 54 | -- |
51 | 2.25.1 | 55 | 2.25.1 | diff view generated by jsdifflib |
1 | Introduce PCI_FIND_NEXT_CAP_TTL and PCI_FIND_NEXT_EXT_CAPABILITY macros | 1 | Introduce PCI_FIND_NEXT_CAP_TTL and PCI_FIND_NEXT_EXT_CAPABILITY macros |
---|---|---|---|
2 | to consolidate duplicate PCI capability search logic found throughout the | 2 | to consolidate duplicate PCI capability search logic found throughout the |
3 | driver tree. This refactoring: | 3 | driver tree. This refactoring: |
4 | 4 | ||
5 | 1. Eliminates code duplication in capability scanning routines | 5 | 1. Eliminates code duplication in capability scanning routines |
6 | 2. Provides a standardized, maintainable implementation | 6 | 2. Provides a standardized, maintainable implementation |
7 | 3. Reduces error-prone copy-paste implementations | 7 | 3. Reduces error-prone copy-paste implementations |
8 | 4. Maintains identical functionality to existing code | 8 | 4. Maintains identical functionality to existing code |
9 | 9 | ||
10 | The macros abstract the low-level capability register scanning while | 10 | The macros abstract the low-level capability register scanning while |
11 | preserving the existing PCI configuration space access patterns. They will | 11 | preserving the existing PCI configuration space access patterns. They will |
12 | enable future conversions of multiple capability search implementations | 12 | enable future conversions of multiple capability search implementations |
13 | across various drivers (e.g., PCI core, controller drivers) to use | 13 | across various drivers (e.g., PCI core, controller drivers) to use |
14 | this centralized logic. | 14 | this centralized logic. |
15 | 15 | ||
16 | Signed-off-by: Hans Zhang <18255117159@163.com> | 16 | Signed-off-by: Hans Zhang <18255117159@163.com> |
17 | --- | 17 | --- |
18 | drivers/pci/pci.h | 81 +++++++++++++++++++++++++++++++++++ | 18 | drivers/pci/pci.h | 81 +++++++++++++++++++++++++++++++++++ |
19 | include/uapi/linux/pci_regs.h | 2 + | 19 | include/uapi/linux/pci_regs.h | 2 + |
20 | 2 files changed, 83 insertions(+) | 20 | 2 files changed, 83 insertions(+) |
21 | 21 | ||
22 | diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h | 22 | diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h |
23 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/drivers/pci/pci.h | 24 | --- a/drivers/pci/pci.h |
25 | +++ b/drivers/pci/pci.h | 25 | +++ b/drivers/pci/pci.h |
26 | @@ -XXX,XX +XXX,XX @@ bool pcie_cap_has_lnkctl(const struct pci_dev *dev); | 26 | @@ -XXX,XX +XXX,XX @@ bool pcie_cap_has_lnkctl(const struct pci_dev *dev); |
27 | bool pcie_cap_has_lnkctl2(const struct pci_dev *dev); | 27 | bool pcie_cap_has_lnkctl2(const struct pci_dev *dev); |
28 | bool pcie_cap_has_rtctl(const struct pci_dev *dev); | 28 | bool pcie_cap_has_rtctl(const struct pci_dev *dev); |
29 | 29 | ||
30 | +/* Standard Capability finder */ | 30 | +/* Standard Capability finder */ |
31 | +/** | 31 | +/** |
32 | + * PCI_FIND_NEXT_CAP_TTL - Find a PCI standard capability | 32 | + * PCI_FIND_NEXT_CAP_TTL - Find a PCI standard capability |
33 | + * @read_cfg: Function pointer for reading PCI config space | 33 | + * @read_cfg: Function pointer for reading PCI config space |
34 | + * @start: Starting position to begin search | 34 | + * @start: Starting position to begin search |
35 | + * @cap: Capability ID to find | 35 | + * @cap: Capability ID to find |
36 | + * @args: Arguments to pass to read_cfg function | 36 | + * @args: Arguments to pass to read_cfg function |
37 | + * | 37 | + * |
38 | + * Iterates through the capability list in PCI config space to find | 38 | + * Iterates through the capability list in PCI config space to find |
39 | + * the specified capability. Implements TTL (time-to-live) protection | 39 | + * the specified capability. Implements TTL (time-to-live) protection |
40 | + * against infinite loops. | 40 | + * against infinite loops. |
41 | + * | 41 | + * |
42 | + * Returns: Position of the capability if found, 0 otherwise. | 42 | + * Returns: Position of the capability if found, 0 otherwise. |
43 | + */ | 43 | + */ |
44 | +#define PCI_FIND_NEXT_CAP_TTL(read_cfg, start, cap, args...) \ | 44 | +#define PCI_FIND_NEXT_CAP_TTL(read_cfg, start, cap, args...) \ |
45 | +({ \ | 45 | +({ \ |
46 | + u8 __pos = (start); \ | 46 | + u8 __pos = (start); \ |
47 | + int __ttl = PCI_FIND_CAP_TTL; \ | 47 | + int __ttl = PCI_FIND_CAP_TTL; \ |
48 | + u16 __ent; \ | 48 | + u16 __ent; \ |
49 | + u8 __found_pos = 0; \ | 49 | + u8 __found_pos = 0; \ |
50 | + u8 __id; \ | 50 | + u8 __id; \ |
51 | + \ | 51 | + \ |
52 | + read_cfg(args, __pos, 1, (u32 *)&__pos); \ | 52 | + read_cfg(args, __pos, 1, (u32 *)&__pos); \ |
53 | + \ | 53 | + \ |
54 | + while (__ttl--) { \ | 54 | + while (__ttl--) { \ |
55 | + if (__pos < PCI_STD_HEADER_SIZEOF) \ | 55 | + if (__pos < PCI_STD_HEADER_SIZEOF) \ |
56 | + break; \ | 56 | + break; \ |
57 | + __pos = ALIGN_DOWN(__pos, 4); \ | 57 | + __pos = ALIGN_DOWN(__pos, 4); \ |
58 | + read_cfg(args, __pos, 2, (u32 *)&__ent); \ | 58 | + read_cfg(args, __pos, 2, (u32 *)&__ent); \ |
59 | + __id = FIELD_GET(PCI_CAP_ID_MASK, __ent); \ | 59 | + __id = FIELD_GET(PCI_CAP_ID_MASK, __ent); \ |
60 | + if (__id == 0xff) \ | 60 | + if (__id == 0xff) \ |
61 | + break; \ | 61 | + break; \ |
62 | + if (__id == (cap)) { \ | 62 | + if (__id == (cap)) { \ |
63 | + __found_pos = __pos; \ | 63 | + __found_pos = __pos; \ |
64 | + break; \ | 64 | + break; \ |
65 | + } \ | 65 | + } \ |
66 | + __pos = FIELD_GET(PCI_CAP_LIST_NEXT_MASK, __ent); \ | 66 | + __pos = FIELD_GET(PCI_CAP_LIST_NEXT_MASK, __ent); \ |
67 | + } \ | 67 | + } \ |
68 | + __found_pos; \ | 68 | + __found_pos; \ |
69 | +}) | 69 | +}) |
70 | + | 70 | + |
71 | +/* Extended Capability finder */ | 71 | +/* Extended Capability finder */ |
72 | +/** | 72 | +/** |
73 | + * PCI_FIND_NEXT_EXT_CAPABILITY - Find a PCI extended capability | 73 | + * PCI_FIND_NEXT_EXT_CAPABILITY - Find a PCI extended capability |
74 | + * @read_cfg: Function pointer for reading PCI config space | 74 | + * @read_cfg: Function pointer for reading PCI config space |
75 | + * @start: Starting position to begin search (0 for initial search) | 75 | + * @start: Starting position to begin search (0 for initial search) |
76 | + * @cap: Extended capability ID to find | 76 | + * @cap: Extended capability ID to find |
77 | + * @args: Arguments to pass to read_cfg function | 77 | + * @args: Arguments to pass to read_cfg function |
78 | + * | 78 | + * |
79 | + * Searches the extended capability space in PCI config registers | 79 | + * Searches the extended capability space in PCI config registers |
80 | + * for the specified capability. Implements TTL protection against | 80 | + * for the specified capability. Implements TTL protection against |
81 | + * infinite loops using a calculated maximum search count. | 81 | + * infinite loops using a calculated maximum search count. |
82 | + * | 82 | + * |
83 | + * Returns: Position of the capability if found, 0 otherwise. | 83 | + * Returns: Position of the capability if found, 0 otherwise. |
84 | + */ | 84 | + */ |
85 | +#define PCI_FIND_NEXT_EXT_CAPABILITY(read_cfg, start, cap, args...) \ | 85 | +#define PCI_FIND_NEXT_EXT_CAPABILITY(read_cfg, start, cap, args...) \ |
86 | +({ \ | 86 | +({ \ |
87 | + u16 __pos = (start) ?: PCI_CFG_SPACE_SIZE; \ | 87 | + u16 __pos = (start) ?: PCI_CFG_SPACE_SIZE; \ |
88 | + u16 __found_pos = 0; \ | 88 | + u16 __found_pos = 0; \ |
89 | + int __ttl, __ret; \ | 89 | + int __ttl, __ret; \ |
90 | + u32 __header; \ | 90 | + u32 __header; \ |
91 | + \ | 91 | + \ |
92 | + __ttl = (PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE) / 8; \ | 92 | + __ttl = (PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE) / 8; \ |
93 | + while (__ttl-- > 0 && __pos >= PCI_CFG_SPACE_SIZE) { \ | 93 | + while (__ttl-- > 0 && __pos >= PCI_CFG_SPACE_SIZE) { \ |
94 | + __ret = read_cfg(args, __pos, 4, &__header); \ | 94 | + __ret = read_cfg(args, __pos, 4, &__header); \ |
95 | + if (__ret != PCIBIOS_SUCCESSFUL) \ | 95 | + if (__ret != PCIBIOS_SUCCESSFUL) \ |
96 | + break; \ | 96 | + break; \ |
97 | + \ | 97 | + \ |
98 | + if (__header == 0) \ | 98 | + if (__header == 0) \ |
99 | + break; \ | 99 | + break; \ |
100 | + \ | 100 | + \ |
101 | + if (PCI_EXT_CAP_ID(__header) == (cap) && __pos != start) { \ | 101 | + if (PCI_EXT_CAP_ID(__header) == (cap) && __pos != start) { \ |
102 | + __found_pos = __pos; \ | 102 | + __found_pos = __pos; \ |
103 | + break; \ | 103 | + break; \ |
104 | + } \ | 104 | + } \ |
105 | + \ | 105 | + \ |
106 | + __pos = PCI_EXT_CAP_NEXT(__header); \ | 106 | + __pos = PCI_EXT_CAP_NEXT(__header); \ |
107 | + } \ | 107 | + } \ |
108 | + __found_pos; \ | 108 | + __found_pos; \ |
109 | +}) | 109 | +}) |
110 | + | 110 | + |
111 | /* Functions internal to the PCI core code */ | 111 | /* Functions internal to the PCI core code */ |
112 | 112 | ||
113 | #ifdef CONFIG_DMI | 113 | #ifdef CONFIG_DMI |
114 | diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h | 114 | diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h |
115 | index XXXXXXX..XXXXXXX 100644 | 115 | index XXXXXXX..XXXXXXX 100644 |
116 | --- a/include/uapi/linux/pci_regs.h | 116 | --- a/include/uapi/linux/pci_regs.h |
117 | +++ b/include/uapi/linux/pci_regs.h | 117 | +++ b/include/uapi/linux/pci_regs.h |
118 | @@ -XXX,XX +XXX,XX @@ | 118 | @@ -XXX,XX +XXX,XX @@ |
119 | /* 0x48-0x7f reserved */ | 119 | /* 0x48-0x7f reserved */ |
120 | 120 | ||
121 | /* Capability lists */ | 121 | /* Capability lists */ |
122 | +#define PCI_CAP_ID_MASK 0x00ff | 122 | +#define PCI_CAP_ID_MASK 0x00ff |
123 | +#define PCI_CAP_LIST_NEXT_MASK 0xff00 | 123 | +#define PCI_CAP_LIST_NEXT_MASK 0xff00 |
124 | 124 | ||
125 | #define PCI_CAP_LIST_ID 0 /* Capability ID */ | 125 | #define PCI_CAP_LIST_ID 0 /* Capability ID */ |
126 | #define PCI_CAP_ID_PM 0x01 /* Power Management */ | 126 | #define PCI_CAP_ID_PM 0x01 /* Power Management */ |
127 | -- | 127 | -- |
128 | 2.25.1 | 128 | 2.25.1 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
18 | existing capability discovery patterns through thorough testing of PCI | 18 | existing capability discovery patterns through thorough testing of PCI |
19 | device enumeration and capability probing. | 19 | device enumeration and capability probing. |
20 | 20 | ||
21 | Signed-off-by: Hans Zhang <18255117159@163.com> | 21 | Signed-off-by: Hans Zhang <18255117159@163.com> |
22 | --- | 22 | --- |
23 | drivers/pci/pci.c | 79 +++++++++++++---------------------------------- | 23 | Changes since v7: |
24 | 1 file changed, 22 insertions(+), 57 deletions(-) | 24 | https://lore.kernel.org/linux-pci/20250402042020.48681-3-18255117159@163.com |
25 | |||
26 | - Resolve compilation errors. | ||
27 | --- | ||
28 | drivers/pci/pci.c | 80 ++++++++++++++--------------------------------- | ||
29 | 1 file changed, 23 insertions(+), 57 deletions(-) | ||
25 | 30 | ||
26 | diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c | 31 | diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c |
27 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/drivers/pci/pci.c | 33 | --- a/drivers/pci/pci.c |
29 | +++ b/drivers/pci/pci.c | 34 | +++ b/drivers/pci/pci.c |
... | ... | ||
130 | @@ -XXX,XX +XXX,XX @@ EXPORT_SYMBOL_GPL(pci_get_dsn); | 135 | @@ -XXX,XX +XXX,XX @@ EXPORT_SYMBOL_GPL(pci_get_dsn); |
131 | 136 | ||
132 | static u8 __pci_find_next_ht_cap(struct pci_dev *dev, u8 pos, int ht_cap) | 137 | static u8 __pci_find_next_ht_cap(struct pci_dev *dev, u8 pos, int ht_cap) |
133 | { | 138 | { |
134 | - int rc, ttl = PCI_FIND_CAP_TTL; | 139 | - int rc, ttl = PCI_FIND_CAP_TTL; |
140 | + int rc; | ||
135 | u8 cap, mask; | 141 | u8 cap, mask; |
136 | 142 | ||
137 | if (ht_cap == HT_CAPTYPE_SLAVE || ht_cap == HT_CAPTYPE_HOST) | 143 | if (ht_cap == HT_CAPTYPE_SLAVE || ht_cap == HT_CAPTYPE_HOST) |
138 | @@ -XXX,XX +XXX,XX @@ static u8 __pci_find_next_ht_cap(struct pci_dev *dev, u8 pos, int ht_cap) | 144 | @@ -XXX,XX +XXX,XX @@ static u8 __pci_find_next_ht_cap(struct pci_dev *dev, u8 pos, int ht_cap) |
139 | mask = HT_5BIT_CAP_MASK; | 145 | mask = HT_5BIT_CAP_MASK; |
... | ... | diff view generated by jsdifflib |
1 | Use the PCI core is now exposing generic macros for the host bridges to | 1 | Use the PCI core is now exposing generic macros for the host bridges to |
---|---|---|---|
2 | search for the PCIe capabilities, make use of them in the DWC driver. | 2 | search for the PCIe capabilities, make use of them in the DWC driver. |
3 | 3 | ||
4 | Signed-off-by: Hans Zhang <18255117159@163.com> | 4 | Signed-off-by: Hans Zhang <18255117159@163.com> |
5 | --- | 5 | --- |
6 | Changes since v6: | 6 | Changes since v7: |
7 | https://lore.kernel.org/linux-pci/20250323164852.430546-3-18255117159@163.com/ | 7 | https://lore.kernel.org/linux-pci/20250402042020.48681-4-18255117159@163.com/ |
8 | 8 | ||
9 | - The patch commit message were modified. | 9 | - Resolve compilation errors. |
10 | |||
11 | Changes since v5: | ||
12 | https://lore.kernel.org/linux-pci/20250321163803.391056-3-18255117159@163.com/ | ||
13 | |||
14 | - Kconfig add "select PCI_HOST_HELPERS" | ||
15 | --- | 10 | --- |
16 | drivers/pci/controller/dwc/pcie-designware.c | 72 ++------------------ | 11 | drivers/pci/controller/dwc/pcie-designware.c | 72 ++------------------ |
17 | 1 file changed, 7 insertions(+), 65 deletions(-) | 12 | 1 file changed, 7 insertions(+), 65 deletions(-) |
18 | 13 | ||
19 | diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c | 14 | diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c |
... | ... | ||
63 | - reg = dw_pcie_readw_dbi(pci, PCI_CAPABILITY_LIST); | 58 | - reg = dw_pcie_readw_dbi(pci, PCI_CAPABILITY_LIST); |
64 | - next_cap_ptr = (reg & 0x00ff); | 59 | - next_cap_ptr = (reg & 0x00ff); |
65 | - | 60 | - |
66 | - return __dw_pcie_find_next_cap(pci, next_cap_ptr, cap); | 61 | - return __dw_pcie_find_next_cap(pci, next_cap_ptr, cap); |
67 | + return PCI_FIND_NEXT_CAP_TTL(dw_pcie_read_cfg, PCI_CAPABILITY_LIST, cap, | 62 | + return PCI_FIND_NEXT_CAP_TTL(dw_pcie_read_cfg, PCI_CAPABILITY_LIST, cap, |
68 | + pcie); | 63 | + pci); |
69 | } | 64 | } |
70 | EXPORT_SYMBOL_GPL(dw_pcie_find_capability); | 65 | EXPORT_SYMBOL_GPL(dw_pcie_find_capability); |
71 | 66 | ||
72 | -static u16 dw_pcie_find_next_ext_capability(struct dw_pcie *pci, u16 start, | 67 | -static u16 dw_pcie_find_next_ext_capability(struct dw_pcie *pci, u16 start, |
73 | - u8 cap) | 68 | - u8 cap) |
... | ... | ||
105 | -} | 100 | -} |
106 | - | 101 | - |
107 | u16 dw_pcie_find_ext_capability(struct dw_pcie *pci, u8 cap) | 102 | u16 dw_pcie_find_ext_capability(struct dw_pcie *pci, u8 cap) |
108 | { | 103 | { |
109 | - return dw_pcie_find_next_ext_capability(pci, 0, cap); | 104 | - return dw_pcie_find_next_ext_capability(pci, 0, cap); |
110 | + return PCI_FIND_NEXT_EXT_CAPABILITY(dw_pcie_read_cfg, 0, cap, pcie); | 105 | + return PCI_FIND_NEXT_EXT_CAPABILITY(dw_pcie_read_cfg, 0, cap, pci); |
111 | } | 106 | } |
112 | EXPORT_SYMBOL_GPL(dw_pcie_find_ext_capability); | 107 | EXPORT_SYMBOL_GPL(dw_pcie_find_ext_capability); |
113 | 108 | ||
114 | -- | 109 | -- |
115 | 2.25.1 | 110 | 2.25.1 | diff view generated by jsdifflib |
1 | Use the PCI core is now exposing generic macros for the host bridges to | 1 | Use the PCI core is now exposing generic macros for the host bridges to |
---|---|---|---|
2 | search for the PCIe capabilities, make use of them in the CDNS driver. | 2 | search for the PCIe capabilities, make use of them in the CDNS driver. |
3 | 3 | ||
4 | Signed-off-by: Hans Zhang <18255117159@163.com> | 4 | Signed-off-by: Hans Zhang <18255117159@163.com> |
5 | --- | 5 | --- |
6 | Changes since v6: | 6 | Changes since v6: |
7 | https://lore.kernel.org/linux-pci/20250323164852.430546-4-18255117159@163.com/ | 7 | https://lore.kernel.org/linux-pci/20250323164852.430546-4-18255117159@163.com/ |
8 | 8 | ||
9 | - The patch commit message were modified. | 9 | - The patch commit message were modified. |
10 | 10 | ||
11 | Changes since v5: | 11 | Changes since v5: |
12 | https://lore.kernel.org/linux-pci/20250321163803.391056-4-18255117159@163.com | 12 | https://lore.kernel.org/linux-pci/20250321163803.391056-4-18255117159@163.com |
13 | 13 | ||
14 | - Kconfig add "select PCI_HOST_HELPERS" | 14 | - Kconfig add "select PCI_HOST_HELPERS" |
15 | --- | 15 | --- |
16 | drivers/pci/controller/cadence/pcie-cadence.c | 28 +++++++++++++++++++ | 16 | drivers/pci/controller/cadence/pcie-cadence.c | 28 +++++++++++++++++++ |
17 | drivers/pci/controller/cadence/pcie-cadence.h | 13 +++++++++ | 17 | drivers/pci/controller/cadence/pcie-cadence.h | 13 +++++++++ |
18 | 2 files changed, 41 insertions(+) | 18 | 2 files changed, 41 insertions(+) |
19 | 19 | ||
20 | diff --git a/drivers/pci/controller/cadence/pcie-cadence.c b/drivers/pci/controller/cadence/pcie-cadence.c | 20 | diff --git a/drivers/pci/controller/cadence/pcie-cadence.c b/drivers/pci/controller/cadence/pcie-cadence.c |
21 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/drivers/pci/controller/cadence/pcie-cadence.c | 22 | --- a/drivers/pci/controller/cadence/pcie-cadence.c |
23 | +++ b/drivers/pci/controller/cadence/pcie-cadence.c | 23 | +++ b/drivers/pci/controller/cadence/pcie-cadence.c |
24 | @@ -XXX,XX +XXX,XX @@ | 24 | @@ -XXX,XX +XXX,XX @@ |
25 | #include <linux/of.h> | 25 | #include <linux/of.h> |
26 | 26 | ||
27 | #include "pcie-cadence.h" | 27 | #include "pcie-cadence.h" |
28 | +#include "../../pci.h" | 28 | +#include "../../pci.h" |
29 | + | 29 | + |
30 | +static int cdns_pcie_read_cfg(void *priv, int where, int size, u32 *val) | 30 | +static int cdns_pcie_read_cfg(void *priv, int where, int size, u32 *val) |
31 | +{ | 31 | +{ |
32 | + struct cdns_pcie *pcie = priv; | 32 | + struct cdns_pcie *pcie = priv; |
33 | + | 33 | + |
34 | + if (size == 4) | 34 | + if (size == 4) |
35 | + *val = cdns_pcie_readl(pcie, where); | 35 | + *val = cdns_pcie_readl(pcie, where); |
36 | + else if (size == 2) | 36 | + else if (size == 2) |
37 | + *val = cdns_pcie_readw(pcie, where); | 37 | + *val = cdns_pcie_readw(pcie, where); |
38 | + else if (size == 1) | 38 | + else if (size == 1) |
39 | + *val = cdns_pcie_readb(pcie, where); | 39 | + *val = cdns_pcie_readb(pcie, where); |
40 | + | 40 | + |
41 | + return PCIBIOS_SUCCESSFUL; | 41 | + return PCIBIOS_SUCCESSFUL; |
42 | +} | 42 | +} |
43 | + | 43 | + |
44 | +u8 cdns_pcie_find_capability(struct cdns_pcie *pcie, u8 cap) | 44 | +u8 cdns_pcie_find_capability(struct cdns_pcie *pcie, u8 cap) |
45 | +{ | 45 | +{ |
46 | + return PCI_FIND_NEXT_CAP_TTL(cdns_pcie_read_cfg, PCI_CAPABILITY_LIST, | 46 | + return PCI_FIND_NEXT_CAP_TTL(cdns_pcie_read_cfg, PCI_CAPABILITY_LIST, |
47 | + cap, pcie); | 47 | + cap, pcie); |
48 | +} | 48 | +} |
49 | +EXPORT_SYMBOL_GPL(cdns_pcie_find_capability); | 49 | +EXPORT_SYMBOL_GPL(cdns_pcie_find_capability); |
50 | + | 50 | + |
51 | +u16 cdns_pcie_find_ext_capability(struct cdns_pcie *pcie, u8 cap) | 51 | +u16 cdns_pcie_find_ext_capability(struct cdns_pcie *pcie, u8 cap) |
52 | +{ | 52 | +{ |
53 | + return PCI_FIND_NEXT_EXT_CAPABILITY(cdns_pcie_read_cfg, 0, cap, pcie); | 53 | + return PCI_FIND_NEXT_EXT_CAPABILITY(cdns_pcie_read_cfg, 0, cap, pcie); |
54 | +} | 54 | +} |
55 | +EXPORT_SYMBOL_GPL(cdns_pcie_find_ext_capability); | 55 | +EXPORT_SYMBOL_GPL(cdns_pcie_find_ext_capability); |
56 | 56 | ||
57 | void cdns_pcie_detect_quiet_min_delay_set(struct cdns_pcie *pcie) | 57 | void cdns_pcie_detect_quiet_min_delay_set(struct cdns_pcie *pcie) |
58 | { | 58 | { |
59 | diff --git a/drivers/pci/controller/cadence/pcie-cadence.h b/drivers/pci/controller/cadence/pcie-cadence.h | 59 | diff --git a/drivers/pci/controller/cadence/pcie-cadence.h b/drivers/pci/controller/cadence/pcie-cadence.h |
60 | index XXXXXXX..XXXXXXX 100644 | 60 | index XXXXXXX..XXXXXXX 100644 |
61 | --- a/drivers/pci/controller/cadence/pcie-cadence.h | 61 | --- a/drivers/pci/controller/cadence/pcie-cadence.h |
62 | +++ b/drivers/pci/controller/cadence/pcie-cadence.h | 62 | +++ b/drivers/pci/controller/cadence/pcie-cadence.h |
63 | @@ -XXX,XX +XXX,XX @@ static inline u32 cdns_pcie_readl(struct cdns_pcie *pcie, u32 reg) | 63 | @@ -XXX,XX +XXX,XX @@ static inline u32 cdns_pcie_readl(struct cdns_pcie *pcie, u32 reg) |
64 | return readl(pcie->reg_base + reg); | 64 | return readl(pcie->reg_base + reg); |
65 | } | 65 | } |
66 | 66 | ||
67 | +static inline u32 cdns_pcie_readw(struct cdns_pcie *pcie, u32 reg) | 67 | +static inline u32 cdns_pcie_readw(struct cdns_pcie *pcie, u32 reg) |
68 | +{ | 68 | +{ |
69 | + return readw(pcie->reg_base + reg); | 69 | + return readw(pcie->reg_base + reg); |
70 | +} | 70 | +} |
71 | + | 71 | + |
72 | +static inline u32 cdns_pcie_readb(struct cdns_pcie *pcie, u32 reg) | 72 | +static inline u32 cdns_pcie_readb(struct cdns_pcie *pcie, u32 reg) |
73 | +{ | 73 | +{ |
74 | + return readb(pcie->reg_base + reg); | 74 | + return readb(pcie->reg_base + reg); |
75 | +} | 75 | +} |
76 | + | 76 | + |
77 | static inline u32 cdns_pcie_read_sz(void __iomem *addr, int size) | 77 | static inline u32 cdns_pcie_read_sz(void __iomem *addr, int size) |
78 | { | 78 | { |
79 | void __iomem *aligned_addr = PTR_ALIGN_DOWN(addr, 0x4); | 79 | void __iomem *aligned_addr = PTR_ALIGN_DOWN(addr, 0x4); |
80 | @@ -XXX,XX +XXX,XX @@ static inline int cdns_pcie_ep_setup(struct cdns_pcie_ep *ep) | 80 | @@ -XXX,XX +XXX,XX @@ static inline int cdns_pcie_ep_setup(struct cdns_pcie_ep *ep) |
81 | } | 81 | } |
82 | #endif | 82 | #endif |
83 | 83 | ||
84 | +u8 cdns_pcie_find_capability(struct cdns_pcie *pcie, u8 cap); | 84 | +u8 cdns_pcie_find_capability(struct cdns_pcie *pcie, u8 cap); |
85 | +u16 cdns_pcie_find_ext_capability(struct cdns_pcie *pcie, u8 cap); | 85 | +u16 cdns_pcie_find_ext_capability(struct cdns_pcie *pcie, u8 cap); |
86 | + | 86 | + |
87 | void cdns_pcie_detect_quiet_min_delay_set(struct cdns_pcie *pcie); | 87 | void cdns_pcie_detect_quiet_min_delay_set(struct cdns_pcie *pcie); |
88 | 88 | ||
89 | void cdns_pcie_set_outbound_region(struct cdns_pcie *pcie, u8 busnr, u8 fn, | 89 | void cdns_pcie_set_outbound_region(struct cdns_pcie *pcie, u8 busnr, u8 fn, |
90 | -- | 90 | -- |
91 | 2.25.1 | 91 | 2.25.1 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
4 | 4 | ||
5 | This avoids hardcoding the offsets in the driver. | 5 | This avoids hardcoding the offsets in the driver. |
6 | 6 | ||
7 | Signed-off-by: Hans Zhang <18255117159@163.com> | 7 | Signed-off-by: Hans Zhang <18255117159@163.com> |
8 | --- | 8 | --- |
9 | Changes since v5~v6: | 9 | Changes since v5~v7: |
10 | 10 | ||
11 | - None | 11 | - None |
12 | 12 | ||
13 | Changes since v4: | 13 | Changes since v4: |
14 | https://lore.kernel.org/linux-pci/20250321101710.371480-5-18255117159@163.com/ | 14 | https://lore.kernel.org/linux-pci/20250321101710.371480-5-18255117159@163.com/ |
... | ... | diff view generated by jsdifflib |