blob: 1193047777901785764374d0fc1431bbc09a387e [file] [log] [blame]
Eric Laif8248f32020-12-31 11:43:29 +08001/* SPDX-License-Identifier: GPL-2.0-only */
2
Tim Wawrzynczakb0d3a012021-12-02 16:19:29 -07003#include <device/device.h>
Eric Laif8248f32020-12-31 11:43:29 +08004#include <intelblocks/pcie_rp.h>
Tim Wawrzynczakb0d3a012021-12-02 16:19:29 -07005#include <soc/cpu.h>
Eric Laif8248f32020-12-31 11:43:29 +08006#include <soc/pci_devs.h>
7#include <soc/pcie.h>
8
Tim Wawrzynczak40c9c8a2021-12-08 10:43:08 -07009#define CPU_CPIE_VW_IDX_BASE 24
10
Eric Laif8248f32020-12-31 11:43:29 +080011static const struct pcie_rp_group pch_lp_rp_groups[] = {
MAULIK V VAGHELAd9c5b142022-02-14 22:04:03 +053012 { .slot = PCH_DEV_SLOT_PCIE, .count = 8, .lcap_port_base = 1 },
13 { .slot = PCH_DEV_SLOT_PCIE_1, .count = 4, .lcap_port_base = 1 },
Eric Laif8248f32020-12-31 11:43:29 +080014 { 0 }
15};
16
Tim Wawrzynczakb0d3a012021-12-02 16:19:29 -070017static const struct pcie_rp_group pch_m_rp_groups[] = {
MAULIK V VAGHELAd9c5b142022-02-14 22:04:03 +053018 { .slot = PCH_DEV_SLOT_PCIE, .count = 8, .lcap_port_base = 1 },
19 { .slot = PCH_DEV_SLOT_PCIE_1, .count = 2, .lcap_port_base = 1 },
Tim Wawrzynczakb0d3a012021-12-02 16:19:29 -070020 { 0 }
21};
22
Eric Laif8248f32020-12-31 11:43:29 +080023const struct pcie_rp_group *get_pch_pcie_rp_table(void)
24{
Tim Wawrzynczakb0d3a012021-12-02 16:19:29 -070025 if (CONFIG(SOC_INTEL_ALDERLAKE_PCH_M))
26 return pch_m_rp_groups;
27
28 return pch_lp_rp_groups; /* Valid for PCH-P and PCH-N */
Eric Laif8248f32020-12-31 11:43:29 +080029}
30
31/*
32 * ADL-P FSP define CPU RP as below:
33 * RP1: PEG60 : 0:6:0 : x4 CPU Slot
34 * RP2: PEG10 : 0:1:0 : x8 CPU Slot
35 * RP3: PEG62 : 0:6:2 : x4 CPU Slot
36 */
37static const struct pcie_rp_group cpu_rp_groups[] = {
MAULIK V VAGHELAd9c5b142022-02-14 22:04:03 +053038 { .slot = SA_DEV_SLOT_CPU_6, .start = 0, .count = 1, .lcap_port_base = 1 },
39 { .slot = SA_DEV_SLOT_CPU_1, .start = 0, .count = 1, .lcap_port_base = 1 },
40 { .slot = SA_DEV_SLOT_CPU_6, .start = 2, .count = 1, .lcap_port_base = 1 },
Eric Laif8248f32020-12-31 11:43:29 +080041 { 0 }
42};
43
Tim Wawrzynczakb0d3a012021-12-02 16:19:29 -070044static const struct pcie_rp_group cpu_m_rp_groups[] = {
MAULIK V VAGHELAd9c5b142022-02-14 22:04:03 +053045 { .slot = SA_DEV_SLOT_CPU_6, .start = 0, .count = 1, .lcap_port_base = 1 },
Tim Wawrzynczakb0d3a012021-12-02 16:19:29 -070046 { 0 }
47};
48
49static const struct pcie_rp_group cpu_n_rp_groups[] = {
50 { 0 }
51};
52
Eric Laif8248f32020-12-31 11:43:29 +080053const struct pcie_rp_group *get_cpu_pcie_rp_table(void)
54{
Tim Wawrzynczakb0d3a012021-12-02 16:19:29 -070055 if (CONFIG(SOC_INTEL_ALDERLAKE_PCH_M))
56 return cpu_m_rp_groups;
57
58 if (CONFIG(SOC_INTEL_ALDERLAKE_PCH_N))
59 return cpu_n_rp_groups;
60
Eric Laif8248f32020-12-31 11:43:29 +080061 return cpu_rp_groups;
62}
Tim Wawrzynczakb0d3a012021-12-02 16:19:29 -070063
MAULIK V VAGHELAd9c5b142022-02-14 22:04:03 +053064/*
65 * TBT's LCAP registers are returning port index which starts from 2 (Usually for other PCIe
66 * root ports index starts from 1). Thus keeping lcap_port_base 2 for TBT, so that coreboot's
67 * PCIe remapping logic can return correct index (0-based)
68 */
69
MAULIK V VAGHELA3e4f28f2022-01-21 14:17:53 +053070static const struct pcie_rp_group tbt_rp_groups[] = {
MAULIK V VAGHELAd9c5b142022-02-14 22:04:03 +053071 { .slot = SA_DEV_SLOT_TBT, .count = CONFIG_MAX_TBT_ROOT_PORTS, .lcap_port_base = 2 },
MAULIK V VAGHELA3e4f28f2022-01-21 14:17:53 +053072 { 0 }
73};
74
75const struct pcie_rp_group *get_tbt_pcie_rp_table(void)
76{
77 return tbt_rp_groups;
78}
79
Tim Wawrzynczakb0d3a012021-12-02 16:19:29 -070080static bool is_part_of_group(const struct device *dev,
81 const struct pcie_rp_group *groups)
82{
83 if (dev->path.type != DEVICE_PATH_PCI)
84 return false;
85
86 const unsigned int slot_to_find = PCI_SLOT(dev->path.pci.devfn);
87 const unsigned int fn_to_find = PCI_FUNC(dev->path.pci.devfn);
88 const struct pcie_rp_group *group;
89 unsigned int i;
90 unsigned int fn;
91
92 for (group = groups; group->count; ++group) {
93 for (i = 0, fn = rp_start_fn(group); i < group->count; i++, fn++) {
94 if (slot_to_find == group->slot && fn_to_find == fn)
95 return true;
96 }
97 }
98
99 return false;
100}
101
102enum pcie_rp_type soc_get_pcie_rp_type(const struct device *dev)
103{
104 if (is_part_of_group(dev, pch_lp_rp_groups))
105 return PCIE_RP_PCH;
106
107 if (CONFIG_MAX_CPU_ROOT_PORTS && is_part_of_group(dev, cpu_rp_groups))
108 return PCIE_RP_CPU;
109
110 return PCIE_RP_UNKNOWN;
111}
Tim Wawrzynczak40c9c8a2021-12-08 10:43:08 -0700112
113int soc_get_cpu_rp_vw_idx(const struct device *dev)
114{
115 if (dev->path.type != DEVICE_PATH_PCI)
116 return -1;
117
118 switch (dev->path.pci.devfn) {
119 case SA_DEVFN_CPU_PCIE1_0:
120 return CPU_CPIE_VW_IDX_BASE;
121 case SA_DEVFN_CPU_PCIE6_0:
122 return CPU_CPIE_VW_IDX_BASE + 3;
123 case SA_DEVFN_CPU_PCIE6_2:
124 return CPU_CPIE_VW_IDX_BASE + 2;
125 default:
126 return -1;
127 }
128}