Debian Codegraph @

src/soc/intel/common/block/include/intelblocks/pcie_rp.h

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #ifndef SOC_INTEL_COMMON_BLOCK_PCIE_RP_H
4 #define SOC_INTEL_COMMON_BLOCK_PCIE_RP_H
5
6 #include <stdint.h>
7
8 /*
9 * In schematic PCIe root port numbers are 1-based, but FSP use 0-based indexes for
10 * the configuration arrays and so this macro subtracts 1 to convert RP# to array index.
11 */
12 #define PCIE_RP(x) ((x) - 1)
13 #define PCH_RP(x) PCIE_RP(x)
14 #define CPU_RP(x) PCIE_RP(x)
15
16 enum pcie_rp_flags {
17 PCIE_RP_HOTPLUG = (1 << 0),
18 /* PCIE RP Latency Tolerance Report */
19 PCIE_RP_LTR = (1 << 1),
20 /* PCIE RP Advanced Error Report */
21 PCIE_RP_AER = (1 << 2),
22 /* Clock source is not used by the root port. */
23 PCIE_RP_CLK_SRC_UNUSED = (1 << 3),
24 /*
25 * Clock request signal requires probing before enabling CLKREQ# based power
26 * management.
27 */
28 PCIE_RP_CLK_REQ_DETECT = (1 << 4),
29 /* Clock request signal is not used by the root port. */
30 PCIE_RP_CLK_REQ_UNUSED = (1 << 5),
31 /* indicates that this root port is built-in. */
32 PCIE_RP_BUILT_IN = (1 << 6),
33 };
34
35 enum pcie_clk_src_flags {
36 PCIE_CLK_FREE_RUNNING = (1 << 0),
37 PCIE_CLK_LAN = (1 << 1),
38 };
39
40 /* coreboot enums are off-by-1 to allow for no config in devicetree */
41 #define UPD_INDEX(upd) (upd - 1)
42
43 /* This enum is for passing into an FSP UPD, typically PcieRpL1Substates */
44 enum L1_substates_control {
45 L1_SS_FSP_DEFAULT,
46 L1_SS_DISABLED,
47 L1_SS_L1_1,
48 L1_SS_L1_2,
49 };
50
51 /* This enum is for passing into an FSP UPD, typically ASPM */
52 enum ASPM_control {
53 ASPM_DEFAULT,
54 ASPM_DISABLE,
55 ASPM_L0S,
56 ASPM_L1,
57 ASPM_L0S_L1,
58 ASPM_AUTO,
59 };
60
61 /* This enum is for passing into an FSP UPD, typically PCIe Speed */
62 enum PCIE_SPEED_control {
63 SPEED_DEFAULT,
64 SPEED_AUTO,
65 SPEED_GEN1,
66 SPEED_GEN2,
67 SPEED_GEN3,
68 SPEED_GEN4,
69 };
70
71 /* PCIe Root Ports */
72 struct pcie_rp_config {
73 /* CLKOUT_PCIE_P/N# used by this root port as per schematics. */
74 uint8_t clk_src;
75 /* SRCCLKREQ# used by this root port as per schematics. */
76 uint8_t clk_req;
77 enum pcie_rp_flags flags;
78 /* PCIe RP L1 substate */
79 enum L1_substates_control PcieRpL1Substates;
80 /* PCIe RP ASPM */
81 enum ASPM_control pcie_rp_aspm;
82 /* timeout for device detect */
83 uint32_t pcie_rp_detect_timeout_ms;
84 /* PCIe RP PCIe Speed */
85 enum PCIE_SPEED_control pcie_rp_pcie_speed;
86 };
87
88 /*
89 * The PCIe Root Ports usually come in groups of up to 8 PCI-device
90 * functions.
91 *
92 * `slot` is the PCI device/slot number of such a group.
93 * `start` is the initial PCI function number within the group. This is useful
94 * in case the root port numbers are not contiguous within the slot.
95 * `count` is the number of functions within the group starting with the `start`
96 * function number.
97 * `lcap_port_base` is the starting index of physical port as described in LCAP
98 * register in PCIe config space. coreboot always uses 0 based indexing while
99 * referring to the PCIe port but LCAP registers uses 1-based indexing in
100 * most of the cases. Remapping logic needs to correctly map LCAP port number
101 * (1-based or n-based) to coreboot indexing (0-based).
102 */
103 struct pcie_rp_group {
104 unsigned int slot;
105 unsigned int start;
106 unsigned int count;
107 unsigned int lcap_port_base;
108 };
109
110 static inline unsigned int rp_start_fn(const struct pcie_rp_group *group)
111 {
112 return group->start;
113 }
114
115 static inline unsigned int rp_end_fn(const struct pcie_rp_group *group)
116 {
117 return group->start + group->count - 1;
118 }
119
120 /*
121 * Update PCI paths of the root ports in the devicetree.
122 *
123 * Depending on the board layout and physical presence of downstream
124 * devices, individual root-port functions can be hidden and reordered.
125 * If we have device nodes for root ports in the static `devicetree.cb`,
126 * we need to update their PCI paths, so the nodes still control the
127 * correct root port. Device nodes for disabled root ports will be
128 * unlinked from the bus, to not interfere with PCI enumeration.
129 *
130 * Call this once, after root ports have been reordered, but before PCI
131 * enumeration.
132 *
133 * `groups` points to a list of groups terminated by an entry with `count == 0`.
134 * It is assumed that the first group includes the RPs 1 to the first group's
135 * `count` and that adjacent groups follow without gaps in the numbering.
136 */
137 void pcie_rp_update_devicetree(const struct pcie_rp_group *groups);
138
139 /*
140 * Return mask of PCIe root ports that are enabled by mainboard. Mask is set in
141 * the same order as the root ports in pcie_rp_group groups table.
142 *
143 * Thus, the status of first root port in the groups table is indicated by bit 0
144 * in the returned mask, second root port by bit 1 and so on.
145
146 * 1 in the bit position indicates root port is enabled, whereas 0 indicates root
147 * port is disabled. This function assumes that the maximum count of root ports
148 * in the groups table is <= 32.
149 */
150 uint32_t pcie_rp_enable_mask(const struct pcie_rp_group *groups);
151
152 /* Get PCH root port groups */
153 const struct pcie_rp_group *soc_get_pch_rp_groups(void);
154
155 enum pcie_rp_type {
156 PCIE_RP_UNKNOWN,
157 PCIE_RP_CPU,
158 PCIE_RP_PCH,
159 };
160
161 /* For PCIe RTD3 support, each SoC that uses it must implement this function. */
162 struct device; /* Not necessary to include all of device/device.h */
163 enum pcie_rp_type soc_get_pcie_rp_type(const struct device *dev);
164
165 /* Return the virtual wire index that represents CPU-side PCIe root ports */
166 int soc_get_cpu_rp_vw_idx(const struct device *dev);
167
168 #endif /* SOC_INTEL_COMMON_BLOCK_PCIE_RP_H */