1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <device/device.h>
4 #include <device/pci_def.h>
5 #include <intelblocks/pcie_rp.h>
6 #include <soc/pci_devs.h>
9 #define CPU_CPIE_VW_IDX_BASE 24
11 static const struct pcie_rp_group pch_lp_rp_groups
[] = {
12 { .slot
= PCH_DEV_SLOT_PCIE
, .count
= 8, .lcap_port_base
= 1 },
13 { .slot
= PCH_DEV_SLOT_PCIE_1
, .count
= 4, .lcap_port_base
= 1 },
17 static const struct pcie_rp_group pch_h_rp_groups
[] = {
18 { .slot
= PCH_DEV_SLOT_PCIE
, .count
= 8, .lcap_port_base
= 1 },
19 { .slot
= PCH_DEV_SLOT_PCIE_1
, .count
= 8, .lcap_port_base
= 1 },
20 { .slot
= PCH_DEV_SLOT_PCIE_2
, .count
= 8, .lcap_port_base
= 1 },
24 static const struct pcie_rp_group cpu_rp_groups
[] = {
25 { .slot
= SA_DEV_SLOT_PEG
, .start
= 0, .count
= 3, .lcap_port_base
= 1 },
26 { .slot
= SA_DEV_SLOT_CPU_PCIE
, .start
= 0, .count
= 1, .lcap_port_base
= 1 },
30 static bool is_part_of_group(const struct device
*dev
,
31 const struct pcie_rp_group
*groups
)
33 if (dev
->path
.type
!= DEVICE_PATH_PCI
)
36 const unsigned int slot_to_find
= PCI_SLOT(dev
->path
.pci
.devfn
);
37 const unsigned int fn_to_find
= PCI_FUNC(dev
->path
.pci
.devfn
);
38 const struct pcie_rp_group
*group
;
42 for (group
= groups
; group
->count
; ++group
) {
43 for (i
= 0, fn
= rp_start_fn(group
); i
< group
->count
; i
++, fn
++) {
44 if (slot_to_find
== group
->slot
&& fn_to_find
== fn
)
52 const struct pcie_rp_group
*soc_get_pch_rp_groups(void)
54 if (CONFIG(SOC_INTEL_TIGERLAKE_PCH_H
))
55 return pch_h_rp_groups
;
57 return pch_lp_rp_groups
;
60 enum pcie_rp_type
soc_get_pcie_rp_type(const struct device
*dev
)
62 const struct pcie_rp_group
*pch_rp_groups
= soc_get_pch_rp_groups();
64 if (is_part_of_group(dev
, pch_rp_groups
))
67 if (is_part_of_group(dev
, cpu_rp_groups
))
70 return PCIE_RP_UNKNOWN
;
73 int soc_get_cpu_rp_vw_idx(const struct device
*dev
)
75 if (dev
->path
.type
!= DEVICE_PATH_PCI
)
78 switch (dev
->path
.pci
.devfn
) {
80 return CPU_CPIE_VW_IDX_BASE
+ 2;
82 return CPU_CPIE_VW_IDX_BASE
+ 1;
84 return CPU_CPIE_VW_IDX_BASE
;
85 case SA_DEVFN_CPU_PCIE
:
86 return CPU_CPIE_VW_IDX_BASE
+ 3;