coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
pcie_rp.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/device.h>
4 #include <intelblocks/pcie_rp.h>
5 #include <soc/cpu.h>
6 #include <soc/pci_devs.h>
7 #include <soc/pcie.h>
8 
9 #define CPU_CPIE_VW_IDX_BASE 24
10 
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 },
14  { 0 }
15 };
16 
17 static const struct pcie_rp_group pch_m_rp_groups[] = {
18  { .slot = PCH_DEV_SLOT_PCIE, .count = 8, .lcap_port_base = 1 },
19  { .slot = PCH_DEV_SLOT_PCIE_1, .count = 2, .lcap_port_base = 1 },
20  { 0 }
21 };
22 
24 {
25  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 */
29 }
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  */
37 static const struct pcie_rp_group cpu_rp_groups[] = {
38  { .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 },
41  { 0 }
42 };
43 
44 static const struct pcie_rp_group cpu_m_rp_groups[] = {
45  { .slot = SA_DEV_SLOT_CPU_6, .start = 0, .count = 1, .lcap_port_base = 1 },
46  { 0 }
47 };
48 
49 static const struct pcie_rp_group cpu_n_rp_groups[] = {
50  { 0 }
51 };
52 
54 {
55  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 
61  return cpu_rp_groups;
62 }
63 
64 /*
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 
70 static const struct pcie_rp_group tbt_rp_groups[] = {
71  { .slot = SA_DEV_SLOT_TBT, .count = CONFIG_MAX_TBT_ROOT_PORTS, .lcap_port_base = 2 },
72  { 0 }
73 };
74 
76 {
77  return tbt_rp_groups;
78 }
79 
80 static 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 
102 enum pcie_rp_type soc_get_pcie_rp_type(const struct device *dev)
103 {
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 }
112 
113 int 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) {
120  return CPU_CPIE_VW_IDX_BASE;
122  return CPU_CPIE_VW_IDX_BASE + 3;
124  return CPU_CPIE_VW_IDX_BASE + 2;
125  default:
126  return -1;
127  }
128 }
static const struct pcie_rp_group cpu_m_rp_groups[]
Definition: pcie_rp.c:44
static const struct pcie_rp_group cpu_rp_groups[]
Definition: pcie_rp.c:37
static const struct pcie_rp_group cpu_n_rp_groups[]
Definition: pcie_rp.c:49
static const struct pcie_rp_group pch_lp_rp_groups[]
Definition: pcie_rp.c:11
#define CPU_CPIE_VW_IDX_BASE
Definition: pcie_rp.c:9
const struct pcie_rp_group * get_cpu_pcie_rp_table(void)
Definition: pcie_rp.c:53
const struct pcie_rp_group * get_tbt_pcie_rp_table(void)
Definition: pcie_rp.c:75
enum pcie_rp_type soc_get_pcie_rp_type(const struct device *dev)
Definition: pcie_rp.c:102
const struct pcie_rp_group * get_pch_pcie_rp_table(void)
Definition: pcie_rp.c:23
static const struct pcie_rp_group tbt_rp_groups[]
Definition: pcie_rp.c:70
static const struct pcie_rp_group pch_m_rp_groups[]
Definition: pcie_rp.c:17
int soc_get_cpu_rp_vw_idx(const struct device *dev)
Definition: pcie_rp.c:113
static bool is_part_of_group(const struct device *dev, const struct pcie_rp_group *groups)
Definition: pcie_rp.c:80
@ CONFIG
Definition: dsi_common.h:201
@ DEVICE_PATH_PCI
Definition: path.h:9
#define PCI_FUNC(devfn)
Definition: pci_def.h:550
#define PCI_SLOT(devfn)
Definition: pci_def.h:549
pcie_rp_type
Definition: pcie_rp.h:135
@ PCIE_RP_PCH
Definition: pcie_rp.h:138
@ PCIE_RP_UNKNOWN
Definition: pcie_rp.h:136
@ PCIE_RP_CPU
Definition: pcie_rp.h:137
static unsigned int rp_start_fn(const struct pcie_rp_group *group)
Definition: pcie_rp.h:90
#define SA_DEV_SLOT_CPU_1
Definition: pci_devs.h:28
#define PCH_DEV_SLOT_PCIE_1
Definition: pci_devs.h:193
#define SA_DEV_SLOT_TBT
Definition: pci_devs.h:47
#define SA_DEV_SLOT_CPU_6
Definition: pci_devs.h:43
#define PCH_DEV_SLOT_PCIE
Definition: pci_devs.h:175
#define SA_DEVFN_CPU_PCIE6_2
Definition: pci_devs.h:45
#define SA_DEVFN_CPU_PCIE6_0
Definition: pci_devs.h:44
#define SA_DEVFN_CPU_PCIE1_0
Definition: pci_devs.h:29
struct pci_path pci
Definition: path.h:116
enum device_path_type type
Definition: path.h:114
Definition: device.h:107
struct device_path path
Definition: device.h:115
unsigned int devfn
Definition: path.h:54
unsigned int count
Definition: pcie_rp.h:86
unsigned int slot
Definition: pcie_rp.h:84