2 * Copyright 2015 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
23 #ifndef __AMD_PCIE_HELPERS_H__
24 #define __AMD_PCIE_HELPERS_H__
28 static inline bool is_pcie_gen3_supported(uint32_t pcie_link_speed_cap
)
30 if (pcie_link_speed_cap
& CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3
)
36 static inline bool is_pcie_gen2_supported(uint32_t pcie_link_speed_cap
)
38 if (pcie_link_speed_cap
& CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2
)
44 /* Get the new PCIE speed given the ASIC PCIE Cap and the NewState's requested PCIE speed*/
45 static inline uint16_t get_pcie_gen_support(uint32_t pcie_link_speed_cap
,
48 uint32_t asic_pcie_link_speed_cap
= (pcie_link_speed_cap
&
49 CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_MASK
);
50 uint32_t sys_pcie_link_speed_cap
= (pcie_link_speed_cap
&
51 CAIL_PCIE_LINK_SPEED_SUPPORT_MASK
);
53 switch (asic_pcie_link_speed_cap
) {
54 case CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1
:
57 case CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2
:
60 case CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3
:
64 if (is_pcie_gen3_supported(sys_pcie_link_speed_cap
) &&
65 (ns_pcie_gen
== PP_PCIEGen3
)) {
67 } else if (is_pcie_gen2_supported(sys_pcie_link_speed_cap
) &&
68 ((ns_pcie_gen
== PP_PCIEGen3
) || (ns_pcie_gen
== PP_PCIEGen2
))) {
76 static inline uint16_t get_pcie_lane_support(uint32_t pcie_lane_width_cap
,
77 uint16_t ns_pcie_lanes
)
80 uint16_t new_pcie_lanes
= ns_pcie_lanes
;
81 uint16_t pcie_lanes
[7] = {1, 2, 4, 8, 12, 16, 32};
83 switch (pcie_lane_width_cap
) {
85 pr_err("No valid PCIE lane width reported\n");
87 case CAIL_PCIE_LINK_WIDTH_SUPPORT_X1
:
90 case CAIL_PCIE_LINK_WIDTH_SUPPORT_X2
:
93 case CAIL_PCIE_LINK_WIDTH_SUPPORT_X4
:
96 case CAIL_PCIE_LINK_WIDTH_SUPPORT_X8
:
99 case CAIL_PCIE_LINK_WIDTH_SUPPORT_X12
:
102 case CAIL_PCIE_LINK_WIDTH_SUPPORT_X16
:
105 case CAIL_PCIE_LINK_WIDTH_SUPPORT_X32
:
109 for (i
= 0; i
< 7; i
++) {
110 if (ns_pcie_lanes
== pcie_lanes
[i
]) {
111 if (pcie_lane_width_cap
& (0x10000 << i
)) {
114 for (j
= i
- 1; j
>= 0; j
--) {
115 if (pcie_lane_width_cap
& (0x10000 << j
)) {
116 new_pcie_lanes
= pcie_lanes
[j
];
122 for (j
= i
+ 1; j
< 7; j
++) {
123 if (pcie_lane_width_cap
& (0x10000 << j
)) {
124 new_pcie_lanes
= pcie_lanes
[j
];
129 pr_err("Cannot find a valid PCIE lane width!\n");
138 return new_pcie_lanes
;