Debian Codegraph @

src/soc/intel/common/block/aspm/aspm.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <fsp/api.h>
4 #include <intelblocks/aspm.h>
5 #include <intelblocks/pcie_rp.h>
6 #include <option.h>
7 #include <soc/soc_chip.h>
8 #include <soc/pcie.h>
9
10 /*
11 * The PCIe RP ASPM and PCIe L1 Substate UPDs follow the PCI Express Base
12 * Specification 1.1. The UPDs and their default values are consistent
13 * from Skylake through Meteor Lake. However, the default for CPU ports
14 * differs from PCH ports. Use auto and maximum unless overwritten
15 * to make the behaviour consistent.
16 *
17 * +-------------------+--------------------------+-----------+-----------+
18 * | Setting | Option | PCH Ports | CPU Ports |
19 * |-------------------|--------------------------|-----------|-----------|
20 * | PcieRpEnableCpm | Disabled | [Default] | [Default] |
21 * | | Enabled | | |
22 * |-------------------|--------------------------|-----------|-----------|
23 * | PcieRpAspm | PchPcieAspmDisabled | | |
24 * | | PchPcieAspmL0s | | |
25 * | | PchPcieAspmL1 | | |
26 * | | PchPcieAspmL0sL1 | | [Default] |
27 * | | PchPcieAspmAutoConfig | [Default] | |
28 * | | PchPcieAspmMax | | |
29 * |-------------------|--------------------------|-----------|-----------|
30 * | PcieRpL1Substates | Disabled | | |
31 * | | PchPcieL1SubstatesL1_1 | | |
32 * | | PchPcieL1SubstatesL1_1_2 | | [Default] |
33 * | | PchPcieL1SubstatesMax | [Default] | |
34 * |-------------------|--------------------------|-----------|-----------|
35 * | PchPcieRpPcieSpeed| PchPcieRpPcieSpeedAuto | [Default] | |
36 * | | PchPcieRpPcieSpeedGen1 | | |
37 * | | PchPcieRpPcieSpeedGen2 | | |
38 * | | PchPcieRpPcieSpeedGen3 | | |
39 * | | PchPcieRpPcieSpeedGen4 | | |
40 * +-------------------+--------------------------+-----------+-----------+
41 */
42
43 static unsigned int aspm_control_to_upd(enum ASPM_control aspm_control, bool is_cpu_rp)
44 {
45 /* Disable without Kconfig selected */
46 if (!CONFIG(PCIEXP_ASPM))
47 return UPD_INDEX(ASPM_DISABLE);
48
49 /* Use default unless overwritten */
50 if (!aspm_control)
51 return is_cpu_rp ? UPD_INDEX(ASPM_L0S_L1) : UPD_INDEX(ASPM_AUTO);
52
53 return UPD_INDEX(aspm_control);
54 }
55
56 static unsigned int l1ss_control_to_upd(enum L1_substates_control l1_substates_control)
57 {
58 /* Disable without Kconfig selected */
59 if (!CONFIG(PCIEXP_ASPM))
60 return UPD_INDEX(L1_SS_DISABLED);
61
62 /* Don't enable UPD if Kconfig not set */
63 if (!CONFIG(PCIEXP_L1_SUB_STATE))
64 return UPD_INDEX(L1_SS_DISABLED);
65
66 /* L1 Substate should be disabled in compliance mode */
67 if (CONFIG(SOC_INTEL_COMPLIANCE_TEST_MODE))
68 return UPD_INDEX(L1_SS_DISABLED);
69
70 /* Use maximum unless overwritten */
71 if (!l1_substates_control)
72 return UPD_INDEX(L1_SS_L1_2);
73
74 return UPD_INDEX(l1_substates_control);
75 }
76
77 static unsigned int pcie_speed_control_to_upd(enum PCIE_SPEED_control pcie_speed_control)
78 {
79 /* Use auto unless overwritten */
80 if (!pcie_speed_control)
81 return UPD_INDEX(SPEED_AUTO);
82
83 return UPD_INDEX(pcie_speed_control);
84 }
85
86 void configure_pch_rp_power_management(FSP_S_CONFIG *s_cfg,
87 const struct pcie_rp_config *rp_cfg,
88 unsigned int index)
89 {
90 s_cfg->PcieRpEnableCpm[index] =
91 get_uint_option("pciexp_clk_pm", CONFIG(PCIEXP_CLK_PM));
92 s_cfg->PcieRpAspm[index] =
93 aspm_control_to_upd(get_uint_option("pciexp_aspm", rp_cfg->pcie_rp_aspm), false);
94 s_cfg->PcieRpL1Substates[index] =
95 l1ss_control_to_upd(get_uint_option("pciexp_l1ss", rp_cfg->PcieRpL1Substates));
96 s_cfg->PcieRpPcieSpeed[index] =
97 pcie_speed_control_to_upd(get_uint_option("pciexp_speed", rp_cfg->pcie_rp_pcie_speed));
98 }
99
100 #if CONFIG(HAS_INTEL_CPU_ROOT_PORTS)
101 /*
102 * Starting with Alder Lake, UPDs for Clock Power Management were
103 * introduced for the CPU root ports.
104 *
105 * CpuPcieClockGating:
106 * Disabled
107 * Enabled [Default]
108 *
109 * CpuPciePowerGating
110 * Disabled
111 * Enabled [Default]
112 *
113 */
114 void configure_cpu_rp_power_management(FSP_S_CONFIG *s_cfg,
115 const struct pcie_rp_config *rp_cfg,
116 unsigned int index)
117 {
118 bool pciexp_clk_pm = get_uint_option("pciexp_clk_pm", CONFIG(PCIEXP_CLK_PM));
119 s_cfg->CpuPcieRpEnableCpm[index] = pciexp_clk_pm;
120 s_cfg->CpuPcieClockGating[index] = pciexp_clk_pm;
121 s_cfg->CpuPciePowerGating[index] = pciexp_clk_pm;
122 s_cfg->CpuPcieRpAspm[index] =
123 aspm_control_to_upd(get_uint_option("pciexp_aspm_cpu", rp_cfg->pcie_rp_aspm), true);
124 s_cfg->CpuPcieRpL1Substates[index] =
125 l1ss_control_to_upd(get_uint_option("pciexp_l1ss", rp_cfg->PcieRpL1Substates));
126 }
127
128 #endif // CONFIG(HAS_INTEL_CPU_ROOT_PORTS)